/** * A one way asynchronous send */ @Override public void oneway(Object command) throws IOException { checkStarted(); wireFormat.marshal(command, dataOut); dataOut.flush(); }
protected ByteSequence getByteSequence(Message message) throws IOException { org.apache.activemq.util.ByteSequence packet = wireFormat.marshal(message); return new ByteSequence(packet.data, packet.offset, packet.length); }
private void trace(DataStructure command) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(maxTraceDatagramSize); DataOutputStream out = new DataOutputStream(baos); wireFormat.marshal(brokerId, out); wireFormat.marshal(command, out); out.close(); ByteSequence sequence = baos.toByteSequence(); DatagramPacket datagram = new DatagramPacket(sequence.getData(), sequence.getOffset(), sequence.getLength(), address); socket.send(datagram); } catch (Throwable e) { LOG.debug("Failed to trace: {}", command, e); } }
public void oneway(Object command) throws IOException { next.oneway((Command) remoteWireFormat.unmarshal(localWireFormat.marshal(command))); }
/** * @param command * @param sync * @return * @throws IOException */ public RecordLocation writeCommand(DataStructure command, boolean sync) throws IOException { if (started.get()) { try { return journal.write(toPacket(wireFormat.marshal(command)), sync); } catch (IOException ioe) { LOG.error("Cannot write to the journal", ioe); brokerService.handleIOException(ioe); throw ioe; } } throw new IOException("closed"); }
public void onCommand(Object command) { try { getTransportListener().onCommand((Command)localWireFormat.unmarshal(remoteWireFormat.marshal(command))); } catch (IOException e) { getTransportListener().onException(e); } }
@Override public void deleteAllMessages() throws IOException { try { JournalTrace trace = new JournalTrace(); trace.setMessage("DELETED"); RecordLocation location = journal.write(toPacket(wireFormat.marshal(trace)), false); journal.setMark(location, true); LOG.info("Journal deleted: "); } catch (IOException e) { throw e; } catch (Throwable e) { throw IOExceptionSupport.create(e); } longTermPersistence.deleteAllMessages(); }
@Override public void addMessage(ConnectionContext context, Message message) throws IOException { KahaAddMessageCommand command = new KahaAddMessageCommand(); command.setDestination(dest); command.setMessageId(message.getMessageId().toProducerKey()); processAdd(command, message.getTransactionId(), wireFormat.marshal(message)); }
@Override public void addSubscription(SubscriptionInfo subscriptionInfo, boolean retroactive) throws IOException { String subscriptionKey = subscriptionKey(subscriptionInfo.getClientId(), subscriptionInfo .getSubscriptionName()); KahaSubscriptionCommand command = new KahaSubscriptionCommand(); command.setDestination(dest); command.setSubscriptionKey(subscriptionKey.toString()); command.setRetroactive(retroactive); org.apache.activemq.util.ByteSequence packet = wireFormat.marshal(subscriptionInfo); command.setSubscriptionInfo(new Buffer(packet.getData(), packet.getOffset(), packet.getLength())); store(command, isEnableJournalDiskSyncs() && true, null, null); this.subscriptionCount.incrementAndGet(); }
@Override public void updateMessage(Message message) throws IOException { TransactionContext c = persistenceAdapter.getTransactionContext(); try { adapter.doUpdateMessage(c, destination, message.getMessageId(), ByteSequenceData.toByteArray(wireFormat.marshal(message))); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to update message: " + message.getMessageId() + " in container: " + e, e); } finally { c.close(); } }
@Override public void updateMessage(Message message) throws IOException { if (LOG.isTraceEnabled()) { LOG.trace("updating: " + message.getMessageId() + " with deliveryCount: " + message.getRedeliveryCounter()); } KahaUpdateMessageCommand updateMessageCommand = new KahaUpdateMessageCommand(); KahaAddMessageCommand command = new KahaAddMessageCommand(); command.setDestination(dest); command.setMessageId(message.getMessageId().toProducerKey()); command.setPriority(message.getPriority()); command.setPrioritySupported(prioritizedMessages); org.apache.activemq.util.ByteSequence packet = wireFormat.marshal(message); command.setMessage(new Buffer(packet.getData(), packet.getOffset(), packet.getLength())); updateMessageCommand.setMessage(command); store(updateMessageCommand, isEnableJournalDiskSyncs(), null, null); }
@Override public void addSubscription(SubscriptionInfo subscriptionInfo, boolean retroactive) throws IOException { String subscriptionKey = subscriptionKey(subscriptionInfo.getClientId(), subscriptionInfo.getSubscriptionName()); KahaSubscriptionCommand command = new KahaSubscriptionCommand(); command.setDestination(dest); command.setSubscriptionKey(subscriptionKey); command.setRetroactive(retroactive); org.apache.activemq.util.ByteSequence packet = wireFormat.marshal(subscriptionInfo); command.setSubscriptionInfo(new Buffer(packet.getData(), packet.getOffset(), packet.getLength())); process(command); }
private void doSchedule(Message messageSend, Object cronValue, Object periodValue, Object delayValue) throws Exception { long delay = 0; long period = 0; int repeat = 0; String cronEntry = ""; // clear transaction context Message msg = messageSend.copy(); msg.setTransactionId(null); org.apache.activemq.util.ByteSequence packet = wireFormat.marshal(msg); if (cronValue != null) { cronEntry = cronValue.toString(); } if (periodValue != null) { period = (Long) TypeConversionSupport.convert(periodValue, Long.class); } if (delayValue != null) { delay = (Long) TypeConversionSupport.convert(delayValue, Long.class); } Object repeatValue = msg.getProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT); if (repeatValue != null) { repeat = (Integer) TypeConversionSupport.convert(repeatValue, Integer.class); } //job id should be unique for every job (Same format as MessageId) MessageId jobId = new MessageId(messageSend.getMessageId().getProducerId(), longGenerator.getNextSequenceId()); getInternalScheduler().schedule(jobId.toString(), new ByteSequence(packet.data, packet.offset, packet.length), cronEntry, delay, period, repeat); }
ByteSequence packet = wireFormat.marshal(message); data = ByteSequenceData.toByteArray(packet); } catch (IOException e) {
@Override public void removeMessage(ConnectionContext context, MessageAck ack) throws IOException { KahaRemoveMessageCommand command = new KahaRemoveMessageCommand(); command.setDestination(dest); command.setMessageId(ack.getLastMessageId().toProducerKey()); command.setTransactionInfo(TransactionIdConversion.convert(transactionIdTransformer.transform(ack.getTransactionId()))); org.apache.activemq.util.ByteSequence packet = wireFormat.marshal(ack); command.setAck(new Buffer(packet.getData(), packet.getOffset(), packet.getLength())); store(command, isEnableJournalDiskSyncs() && ack.isResponseRequired(), null, null); }
protected void doAcknowledge(ConnectionContext context, String subscriptionKey, MessageId messageId, MessageAck ack) throws IOException { KahaRemoveMessageCommand command = new KahaRemoveMessageCommand(); command.setDestination(dest); command.setSubscriptionKey(subscriptionKey); command.setMessageId(messageId.toProducerKey()); command.setTransactionInfo(ack != null ? TransactionIdConversion.convert(transactionIdTransformer.transform(ack.getTransactionId())) : null); if (ack != null && ack.isUnmatchedAck()) { command.setAck(UNMATCHED); } else { org.apache.activemq.util.ByteSequence packet = wireFormat.marshal(ack); command.setAck(new Buffer(packet.getData(), packet.getOffset(), packet.getLength())); } store(command, false, null, null); }
@Override public void addMessage(final ConnectionContext context, final Message message) throws IOException { final KahaAddMessageCommand command = new KahaAddMessageCommand(); command.setDestination(dest); command.setMessageId(message.getMessageId().toProducerKey()); command.setTransactionInfo(TransactionIdConversion.convert(transactionIdTransformer.transform(message.getTransactionId()))); command.setPriority(message.getPriority()); command.setPrioritySupported(isPrioritizedMessages()); org.apache.activemq.util.ByteSequence packet = wireFormat.marshal(message); command.setMessage(new Buffer(packet.getData(), packet.getOffset(), packet.getLength())); store(command, isEnableJournalDiskSyncs() && message.isResponseRequired(), new IndexAware() { // sync add? (for async, future present from getFutureOrSequenceLong) Object possibleFuture = message.getMessageId().getFutureOrSequenceLong(); @Override public void sequenceAssignedWithIndexLocked(final long sequence) { message.getMessageId().setFutureOrSequenceLong(sequence); if (indexListener != null) { if (possibleFuture == null) { trackPendingAdd(dest, sequence); indexListener.onAdd(new IndexListener.MessageContext(context, message, new Runnable() { @Override public void run() { trackPendingAddComplete(dest, sequence); } })); } } } }, null); }
/** * A one way asynchronous send */ @Override public void oneway(Object command) throws IOException { checkStarted(); wireFormat.marshal(command, dataOut); dataOut.flush(); }
private static void putMsgDataStructure(final DataStructure ds, final WireFormat marshaller, final CoreMessage coreMessage) throws IOException { final ByteSequence dsBytes = marshaller.marshal(ds); dsBytes.compact(); coreMessage.putBytesProperty(AMQ_MSG_DATASTRUCTURE, dsBytes.data); }
@Override public void addMessage(ConnectionContext context, Message message) throws IOException { KahaAddMessageCommand command = new KahaAddMessageCommand(); command.setDestination(dest); command.setMessageId(message.getMessageId().toProducerKey()); processAdd(command, message.getTransactionId(), wireFormat.marshal(message)); }