@Override public void scheduledJob(String id, ByteSequence job) { org.apache.activemq.util.ByteSequence packet = new org.apache.activemq.util.ByteSequence(job.getData(), job.getOffset(), job.getLength()); try { Message messageSend = (Message) wireFormat.unmarshal(packet); messageSend.setOriginalTransactionId(null); Object repeatValue = messageSend.getProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT); Object cronValue = messageSend.getProperty(ScheduledMessage.AMQ_SCHEDULED_CRON); String cronStr = cronValue != null ? cronValue.toString() : null; int repeat = 0; messageSend.setMessageId(new MessageId(producerId, messageIdGenerator.getNextSequenceId()));
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); } }
@Override protected void configureMetadata() { if (brokerService != null) { metadata.openwireVersion = brokerService.getStoreOpenWireVersion(); wireFormat.setVersion(metadata.openwireVersion); if (LOG.isDebugEnabled()) { LOG.debug("Store OpenWire version configured as: {}", metadata.openwireVersion); } } }
@Override public long getLastMessageBrokerSequenceId() throws IOException { TransactionContext c = getTransactionContext(); try { long seq = getAdapter().doGetLastMessageStoreSequenceId(c); sequenceGenerator.setLastSequenceId(seq); long brokerSeq = 0; if (seq != 0) { byte[] msg = getAdapter().doGetMessageById(c, seq); if (msg != null) { Message last = (Message)wireFormat.unmarshal(new ByteSequence(msg)); brokerSeq = last.getMessageId().getBrokerSequenceId(); } else { LOG.warn("Broker sequence id wasn't recovered properly, possible duplicates!"); } } return brokerSeq; } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to get last broker message id: " + e, e); } finally { c.close(); } }
@Override public boolean recoverMessage(long sequenceId, byte[] data) throws Exception { Message msg = (Message)wireFormat.unmarshal(new ByteSequence(data)); msg.getMessageId().setBrokerSequenceId(sequenceId); return listener.recoverMessage(msg); }
protected void sendScheduledJob(ConnectionContext context, Job job, ActiveMQDestination replyTo) throws Exception { org.apache.activemq.util.ByteSequence packet = new org.apache.activemq.util.ByteSequence(job.getPayload()); try { Message msg = (Message) this.wireFormat.unmarshal(packet); msg.setOriginalTransactionId(null); msg.setPersistent(false); msg.setType(AdvisorySupport.ADIVSORY_MESSAGE_TYPE); msg.setMessageId(new MessageId(this.producerId, this.messageIdGenerator.getNextSequenceId()));
@Override public boolean recoverMessage(long sequenceId, byte[] data) throws Exception { Message msg = (Message)wireFormat.unmarshal(new ByteSequence(data)); msg.getMessageId().setBrokerSequenceId(sequenceId); msg.getMessageId().setFutureOrSequenceLong(sequenceId); msg.getMessageId().setEntryLocator(sequenceId); listener.recoverMessage(msg); trackLastRecovered(sequenceId, msg.getPriority()); return true; }
@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); }
public void recoverAdd(long id, byte[] messageBytes) throws IOException { final Message message = (Message) ((JDBCPersistenceAdapter)persistenceAdapter).getWireFormat().unmarshal(new ByteSequence(messageBytes)); message.getMessageId().setFutureOrSequenceLong(id); message.getMessageId().setEntryLocator(id); Tx tx = getPreparedTx(message.getTransactionId()); tx.add(new CommitAddOutcome(null, message)); }
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); }
@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); }
public void addMessage(ConnectionContext context, Message message) throws IOException { KahaAddMessageCommand command = new KahaAddMessageCommand(); command.setDestination(dest); command.setMessageId(message.getMessageId().toString()); command.setTransactionInfo(createTransactionInfo(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(), null, null); }
protected Message getMessage(ByteSequence bs) throws IOException { org.apache.activemq.util.ByteSequence packet = new org.apache.activemq.util.ByteSequence(bs.getData(), bs .getOffset(), bs.getLength()); return (Message) this.wireFormat.unmarshal(packet); }
@Override public Message getMessage(MessageId messageId) throws IOException { // Get a connection and pull the message out of the DB TransactionContext c = persistenceAdapter.getTransactionContext(); try { byte data[] = adapter.doGetMessage(c, messageId); if (data == null) { return null; } Message answer = (Message)wireFormat.unmarshal(new ByteSequence(data)); return answer; } catch (IOException e) { throw IOExceptionSupport.create("Failed to broker message: " + messageId + " in container: " + e, e); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to broker message: " + messageId + " in container: " + e, e); } finally { c.close(); } }
@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 addMessage(final ConnectionContext context, final Message message) throws IOException { MessageId messageId = message.getMessageId(); if (audit != null && audit.isDuplicate(message)) { if (LOG.isDebugEnabled()) { ByteSequence packet = wireFormat.marshal(message); data = ByteSequenceData.toByteArray(packet); } catch (IOException e) { throw IOExceptionSupport.create("Failed to broker message: " + messageId + " in container: " + e, e); sequenceId = persistenceAdapter.getNextSequenceId(); final long sequence = sequenceId; message.getMessageId().setEntryLocator(sequence); adapter.doAddMessage(c, sequenceId, messageId, destination, data, message.getExpiration(), this.isPrioritizedMessages() ? message.getPriority() : 0, xaXid); } catch (SQLException e) { JDBCPersistenceAdapter.log("JDBC Failure: ", e); throw IOExceptionSupport.create("Failed to broker message: " + messageId + " in container: " + e, e); } finally { c.close();
@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(); }
throw new IOException("Could not load journal record, null message content at location: " + location); Message msg = (Message) wireFormat.unmarshal(new DataInputStream(addMessage.getMessage().newInput())); return msg; } catch (Throwable t) { IOException ioe = IOExceptionSupport.create("Unexpected error on journal read at: " + location , t); LOG.error("Failed to load message at: {}", location , ioe); brokerService.handleIOException(ioe); throw ioe;
@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)); }