protected void configure(ActiveMQMessage msg) throws JMSException { long sequenceNumber = messageSequence.incrementAndGet(); msg.setMessageId(new MessageId(producerId, sequenceNumber)); msg.onSend(); msg.setProducerId(producerId); }
public void rollbackPendingCursorAdditions(MessageId messageId) { synchronized (indexOrderedCursorUpdates) { for (int i = indexOrderedCursorUpdates.size() - 1; i >= 0; i--) { MessageContext mc = indexOrderedCursorUpdates.get(i); if (mc.message.getMessageId().equals(messageId)) { indexOrderedCursorUpdates.remove(mc); if (mc.onCompletion != null) { mc.onCompletion.run(); } break; } } } }
@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 protected void setBatch(MessageId messageId) throws Exception { if (LOG.isTraceEnabled()) { LOG.trace("{} setBatch {} seq: {}, loc: {}", this, messageId, messageId.getFutureOrSequenceLong(), messageId.getEntryLocator()); } store.setBatch(messageId); batchResetNeeded = false; }
/** * Write the booleans that this object uses to a BooleanStream */ public int tightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs) throws IOException { MessageId info = (MessageId)o; int rc = super.tightMarshal1(wireFormat, o, bs); rc += tightMarshalString1(info.getTextView(), bs); rc += tightMarshalCachedObject1(wireFormat, (DataStructure)info.getProducerId(), bs); rc+=tightMarshalLong1(wireFormat, info.getProducerSequenceId(), bs); rc+=tightMarshalLong1(wireFormat, info.getBrokerSequenceId(), bs); return rc + 0; }
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())); msg.setProperty("scheduledJobId", job.getJobId()); final boolean originalFlowControl = context.isProducerFlowControl(); final ProducerBrokerExchange producerExchange = new ProducerBrokerExchange(); producerExchange.setConnectionContext(context); producerExchange.setProducerState(new ProducerState(new ProducerInfo())); try { context.setProducerFlowControl(false); this.next.send(producerExchange, msg); } finally { context.setProducerFlowControl(originalFlowControl);
@Override public void messageConsumed(ConnectionContext context, MessageReference messageReference) { super.messageConsumed(context, messageReference); try { if (!messageReference.isAdvisory()) { BaseDestination baseDestination = (BaseDestination) messageReference.getMessage().getRegionDestination(); ActiveMQTopic topic = AdvisorySupport.getMessageConsumedAdvisoryTopic(baseDestination.getActiveMQDestination()); Message payload = messageReference.getMessage().copy(); if (!baseDestination.isIncludeBodyForAdvisory()) { payload.clearBody(); } ActiveMQMessage advisoryMessage = new ActiveMQMessage(); advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_MESSAGE_ID, payload.getMessageId().toString()); advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_DESTINATION, baseDestination.getActiveMQDestination().getQualifiedName()); fireAdvisory(context, topic, payload, null, advisoryMessage); } } catch (Exception e) { handleFireFailure("consumed", e); } }
@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()));
if (destination.isTemporary() && connection.isDeleted(destination)) { throw new InvalidDestinationException("Cannot publish to a deleted Destination: " + destination); msg.setDestination(destination); msg.setMessageId(new MessageId(producer.getProducerInfo().getProducerId(), sequenceNumber)); message.setJMSMessageID(msg.getMessageId().toString()); msg.setConnection(connection); msg.onSend(); msg.setProducerId(msg.getMessageId().getProducerId()); if (LOG.isTraceEnabled()) { LOG.trace(getSessionId() + " sending message: " + msg);
private LocalTransactionId beginLocalTransaction(int numDestinations, ConnectionContext connectionContext, Message message) throws Exception { LocalTransactionId result = null; if (transactedSend && numDestinations > 1 && message.isPersistent() && message.getTransactionId() == null) { result = new LocalTransactionId(new ConnectionId(message.getMessageId().getProducerId().toString()), message.getMessageId().getProducerSequenceId()); connectionContext.getBroker().beginTransaction(connectionContext, result); connectionContext.setTransaction(connectionContext.getTransactions().get(result)); message.setTransactionId(result); } return result; }
checkClosedOrFailed(); if (destination.isTemporary() && isDeleted(destination)) { throw new JMSException("Cannot publish to a deleted Destination: " + destination); msg.setJMSDestination(destination); msg.setJMSDeliveryMode(deliveryMode); long expiration = 0L; msg.setJMSTimestamp(timeStamp); if (timeToLive > 0) { expiration = timeToLive + timeStamp; msg.setMessageId(messageId); msg.onSend(); msg.setProducerId(msg.getMessageId().getProducerId());
@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); }
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); }
for (final MessageReference node : dispatched) { MessageId messageId = node.getMessageId(); if (ack.getFirstMessageId() == null || ack.getFirstMessageId().equals(messageId)) { inAckRange = true; if (ack.getLastMessageId().equals(messageId)) { destination = (Destination) node.getRegionDestination(); callDispatchMatched = true; if (ack.getLastMessageId().equals(messageId)) { final MessageReference node = iter.next(); Destination nodeDest = (Destination) node.getRegionDestination(); if (ack.getLastMessageId().equals(node.getMessageId())) { Destination nodeDest = (Destination) node.getRegionDestination(); MessageId messageId = node.getMessageId(); if (ack.getFirstMessageId() == null || ack.getFirstMessageId().equals(messageId)) { inAckRange = true; if (ack.getLastMessageId().equals(messageId)) { contractPrefetchExtension(1); destination = (Destination) node.getRegionDestination(); || ack.getFirstMessageId().equals(messageId)) { inAckRange = true; if (ack.getLastMessageId().equals(messageId)) {
if (message.isExpired()) { earlyAck = new MessageAck(md, MessageAck.EXPIRED_ACK_TYPE, 1); earlyAck.setFirstMessageId(message.getMessageId()); } else if (connection.isDuplicate(ActiveMQSession.this, message)) { LOG.debug("{} got duplicate: {}", this, message.getMessageId()); earlyAck = new MessageAck(md, MessageAck.POSION_ACK_TYPE, 1); earlyAck.setFirstMessageId(md.getMessage().getMessageId()); earlyAck.setPoisonCause(new Throwable("Duplicate delivery to " + this)); lastDeliveredSequenceId = message.getMessageId().getBrokerSequenceId(); final MessageAck ack = new MessageAck(md, MessageAck.STANDARD_ACK_TYPE, 1); ack.setFirstMessageId(md.getMessage().getMessageId()); doStartTransaction(); ack.setTransactionId(getTransactionContext().getTransactionId());
public void removeMessage(ConnectionContext context, MessageAck ack) throws IOException { KahaRemoveMessageCommand command = new KahaRemoveMessageCommand(); command.setDestination(dest); command.setMessageId(ack.getLastMessageId().toString()); command.setTransactionInfo(createTransactionInfo(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); }
throws IOException, Exception { final ConnectionContext context = producerExchange.getConnectionContext(); message.getMessageId().setBrokerSequenceId(getDestinationSequenceId()); Future<Object> result = null; if (topicStore != null && message.isPersistent() && !canOptimizeOutPersistence()) { if (systemUsage.getStoreUsage().isFull(getStoreUsageHighWaterMark())) { final String logMessage = "Persistent store is Full, " + getStoreUsageHighWaterMark() + "% of " + systemUsage.getStoreUsage().getLimit() + ". Stopping producer (" + message.getProducerId() + ") to prevent flooding " + getActiveMQDestination().getQualifiedName() + "." + " See http://activemq.apache.org/producer-flow-control.html for more info"; if (!context.isNetworkConnection() && systemUsage.isSendFailIfNoSpace()) { throw new javax.jms.ResourceAllocationException(logMessage); message.incrementReferenceCount(); if (context.isInTransaction()) { context.getTransaction().addSynchronization(new Synchronization() { @Override public void afterCommit() throws Exception {
@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); }
@Override public void messageExpired(ConnectionContext context, MessageReference messageReference, Subscription subscription) { super.messageExpired(context, messageReference, subscription); try { if(!messageReference.isAdvisory()) { ActiveMQTopic topic = AdvisorySupport.getExpiredMessageTopic(messageReference.getMessage().getDestination()); Message payload = messageReference.getMessage().copy(); payload.clearBody(); ActiveMQMessage advisoryMessage = new ActiveMQMessage(); advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_MESSAGE_ID, payload.getMessageId().toString()); fireAdvisory(context, topic, payload, null, advisoryMessage); } } catch (Exception e) { handleFireFailure("expired", e); } }
/** * @param message */ public IndirectMessageReference(final Message message) { this.message = message; this.messageId = message.getMessageId().copy(); message.getMessageId(); message.getGroupID(); message.getGroupSequence(); }