/** * Creates an initialized <CODE>BlobMessage</CODE> object. A * <CODE>BlobMessage</CODE> object is used to send a message containing * the <CODE>File</CODE> content. Before the message is sent the file * conent will be uploaded to the broker or some other remote repository * depending on the {@link #getBlobTransferPolicy()}. * * @param file the file to be uploaded to some remote repo (or the broker) * depending on the strategy * @return a BlobMessage * @throws JMSException if the JMS provider fails to create this message due * to some internal error. */ public BlobMessage createBlobMessage(File file) throws JMSException { ActiveMQBlobMessage message = new ActiveMQBlobMessage(); configureMessage(message); message.setBlobUploader(new BlobUploader(getBlobTransferPolicy(), file)); message.setBlobDownloader(new BlobDownloader((getBlobTransferPolicy()))); message.setDeletedByBroker(true); message.setName(file.getName()); return message; }
private void copy(ActiveMQBlobMessage copy) { super.copy(copy); copy.setRemoteBlobUrl(getRemoteBlobUrl()); copy.setMimeType(getMimeType()); copy.setDeletedByBroker(isDeletedByBroker()); copy.setBlobUploader(getBlobUploader()); copy.setName(getName()); }
/** * Return the {@link File} for the {@link ActiveMQBlobMessage}. * * @param message * @return file * @throws JMSException * @throws IOException */ protected File getFile(ActiveMQBlobMessage message) throws JMSException, IOException { if (message.getURL() != null) { try { return new File(message.getURL().toURI()); } catch (URISyntaxException e) { IOException ioe = new IOException("Unable to open file for message " + message); ioe.initCause(e); } } //replace all : with _ to make windows more happy String fileName = message.getJMSMessageID().replaceAll(":", "_"); return new File(rootFile, fileName); } }
public Message copy() { ActiveMQBlobMessage copy = new ActiveMQBlobMessage(); copy(copy); return copy; }
/** * Write the booleans that this object uses to a BooleanStream */ public void looseMarshal(OpenWireFormat wireFormat, Object o, DataOutput dataOut) throws IOException { ActiveMQBlobMessage info = (ActiveMQBlobMessage)o; super.looseMarshal(wireFormat, o, dataOut); looseMarshalString(info.getRemoteBlobUrl(), dataOut); looseMarshalString(info.getMimeType(), dataOut); dataOut.writeBoolean(info.isDeletedByBroker()); } }
/** * Un-marshal an object instance from the data input stream * * @param o the object to un-marshal * @param dataIn the data input stream to build the object from * @throws IOException */ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn) throws IOException { super.looseUnmarshal(wireFormat, o, dataIn); ActiveMQBlobMessage info = (ActiveMQBlobMessage)o; info.setRemoteBlobUrl(looseUnmarshalString(dataIn)); info.setMimeType(looseUnmarshalString(dataIn)); info.setDeletedByBroker(dataIn.readBoolean()); }
} else if (message instanceof BlobMessage) { BlobMessage blobMessage = (BlobMessage)message; ActiveMQBlobMessage msg = new ActiveMQBlobMessage(); msg.setConnection(connection); if (connection != null){ msg.setBlobDownloader(new BlobDownloader(connection.getBlobTransferPolicy())); msg.setURL(blobMessage.getURL()); } catch (MalformedURLException e) {
/** * Creates an initialized <CODE>BlobMessage</CODE> object. A * <CODE>BlobMessage</CODE> object is used to send a message containing a * <CODE>URL</CODE> which points to some network addressible BLOB. * * @param url the network addressable URL used to pass directly to the * consumer * @param deletedByBroker indicates whether or not the resource is deleted * by the broker when the message is acknowledged * @return a BlobMessage * @throws JMSException if the JMS provider fails to create this message due * to some internal error. */ public BlobMessage createBlobMessage(URL url, boolean deletedByBroker) throws JMSException { ActiveMQBlobMessage message = new ActiveMQBlobMessage(); configureMessage(message); message.setURL(url); message.setDeletedByBroker(deletedByBroker); message.setBlobDownloader(new BlobDownloader(getBlobTransferPolicy())); return message; }
public InputStream getInputStream(ActiveMQBlobMessage message) throws IOException, JMSException { URL value = message.getURL(); if (value == null) { return null; } return value.openStream(); }
/** * Write a object instance to data output stream * * @param o the instance to be marshaled * @param dataOut the output stream * @throws IOException thrown if an error occurs */ public void tightMarshal2(OpenWireFormat wireFormat, Object o, DataOutput dataOut, BooleanStream bs) throws IOException { super.tightMarshal2(wireFormat, o, dataOut, bs); ActiveMQBlobMessage info = (ActiveMQBlobMessage)o; tightMarshalString2(info.getRemoteBlobUrl(), dataOut, bs); tightMarshalString2(info.getMimeType(), dataOut, bs); bs.readBoolean(); }
/** * @return a new object instance */ public DataStructure createObject() { return new ActiveMQBlobMessage(); }
@Override protected Message copy(Session session, Message m) throws JMSException { if (m instanceof ActiveMQBlobMessage) { ActiveMQBlobMessage b = (ActiveMQBlobMessage) m; ActiveMQBlobMessage copy = (ActiveMQBlobMessage) getAMQSession(session).createBlobMessage(b.getURL()); try { copy.setProperties(b.getProperties()); } catch (IOException e) { throw JMSExceptionSupport.create("Unable to copy message " + m, e); } return copy; } else { return super.copy(session, m); } }
ActiveMQMessage m = (ActiveMQMessage)md.getMessage().copy(); if (m.getDataStructureType()==CommandTypes.ACTIVEMQ_BLOB_MESSAGE) { ((ActiveMQBlobMessage)m).setBlobDownloader(new BlobDownloader(session.getBlobTransferPolicy()));
/** * Write the booleans that this object uses to a BooleanStream */ public void looseMarshal(OpenWireFormat wireFormat, Object o, DataOutput dataOut) throws IOException { ActiveMQBlobMessage info = (ActiveMQBlobMessage)o; super.looseMarshal(wireFormat, o, dataOut); looseMarshalString(info.getRemoteBlobUrl(), dataOut); looseMarshalString(info.getMimeType(), dataOut); dataOut.writeBoolean(info.isDeletedByBroker()); } }
/** * Un-marshal an object instance from the data input stream * * @param o the object to un-marshal * @param dataIn the data input stream to build the object from * @throws IOException */ public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn) throws IOException { super.looseUnmarshal(wireFormat, o, dataIn); ActiveMQBlobMessage info = (ActiveMQBlobMessage)o; info.setRemoteBlobUrl(looseUnmarshalString(dataIn)); info.setMimeType(looseUnmarshalString(dataIn)); info.setDeletedByBroker(dataIn.readBoolean()); }
} else if (message instanceof BlobMessage) { BlobMessage blobMessage = (BlobMessage)message; ActiveMQBlobMessage msg = new ActiveMQBlobMessage(); msg.setConnection(connection); if (connection != null){ msg.setBlobDownloader(new BlobDownloader(connection.getBlobTransferPolicy())); msg.setURL(blobMessage.getURL()); } catch (MalformedURLException e) {
/** * Creates an initialized <CODE>BlobMessage</CODE> object. A * <CODE>BlobMessage</CODE> object is used to send a message containing a * <CODE>URL</CODE> which points to some network addressible BLOB. * * @param url the network addressable URL used to pass directly to the * consumer * @param deletedByBroker indicates whether or not the resource is deleted * by the broker when the message is acknowledged * @return a BlobMessage * @throws JMSException if the JMS provider fails to create this message due * to some internal error. */ public BlobMessage createBlobMessage(URL url, boolean deletedByBroker) throws JMSException { ActiveMQBlobMessage message = new ActiveMQBlobMessage(); configureMessage(message); message.setURL(url); message.setDeletedByBroker(deletedByBroker); message.setBlobDownloader(new BlobDownloader(getBlobTransferPolicy())); return message; }
@Override public Map<String, Object> getFields(Object o) throws OpenDataException { ActiveMQBlobMessage m = (ActiveMQBlobMessage)o; Map<String, Object> rc = super.getFields(o); try { rc.put(CompositeDataConstants.MESSAGE_URL, "" + m.getURL().toString()); } catch (JMSException e) { rc.put(CompositeDataConstants.MESSAGE_URL, ""); } return rc; } }
/** * Write a object instance to data output stream * * @param o the instance to be marshaled * @param dataOut the output stream * @throws IOException thrown if an error occurs */ public void tightMarshal2(OpenWireFormat wireFormat, Object o, DataOutput dataOut, BooleanStream bs) throws IOException { super.tightMarshal2(wireFormat, o, dataOut, bs); ActiveMQBlobMessage info = (ActiveMQBlobMessage)o; tightMarshalString2(info.getRemoteBlobUrl(), dataOut, bs); tightMarshalString2(info.getMimeType(), dataOut, bs); bs.readBoolean(); }
/** * @return a new object instance */ public DataStructure createObject() { return new ActiveMQBlobMessage(); }