use of com.swiftmq.jms.MessageImpl in project swiftmq-ce by iitsoftware.
the class QueueCleanupDLQJob method cleanupQueue.
private int cleanupQueue(String queueName) throws Exception {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/cleanupQueue ...");
receiver = ctx.queueManager.createQueueReceiver(queueName, null, null);
pullTx = receiver.createTransaction(false);
targetQueue = new QueueImpl(QueueManagerImpl.DLQ + '@' + SwiftletManager.getInstance().getRouterName());
sender = ctx.queueManager.createQueueSender(targetQueue.getQueueName(), null);
pushTx = sender.createTransaction();
if (stopCalled) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/cleanupQueue, stopCalled (2)");
closeResources();
return 0;
}
int cnt = 0;
MessageEntry entry = null;
while ((entry = pullTx.getExpiredMessage(0)) != null) {
MessageImpl msg = entry.getMessage();
pushTx.putMessage(msg);
cnt++;
pushTx.commit();
pullTx.commit();
if (stopCalled) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/cleanupQueue, stopCalled (2)");
closeResources();
return cnt;
}
pullTx = receiver.createTransaction(false);
pushTx = sender.createTransaction();
}
closeResources();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/cleanupQueue done, cnt=" + cnt);
return cnt;
}
use of com.swiftmq.jms.MessageImpl in project swiftmq-client by iitsoftware.
the class MessageConsumerImpl method reportDelivered.
private void reportDelivered(Message message) {
try {
MessageIndex messageIndex = ((MessageImpl) message).getMessageIndex();
requestRegistry.request(new MessageDeliveredRequest(dispatchId, serverQueueConsumerId, messageIndex));
} catch (Exception e) {
}
}
use of com.swiftmq.jms.MessageImpl in project swiftmq-ce by iitsoftware.
the class JMSMappingInboundTransformer method transform.
public MessageImpl transform(TransferFrame frame, DestinationFactory destinationFactory) throws AMQPException, JMSException {
jmsTypeProp = getValue(PROP_JMS_TYPE, null);
MessageImpl jmsMessage = null;
try {
AMQPMessage amqpMessage = null;
if (frame.getMorePayloads() != null) {
List morePayloads = frame.getMorePayloads();
byte[][] b = new byte[morePayloads.size() + 1][];
b[0] = frame.getPayload();
for (int i = 0; i < morePayloads.size(); i++) b[i + 1] = (byte[]) morePayloads.get(i);
amqpMessage = new AMQPMessage(b, frame.getPayloadLength());
} else
amqpMessage = new AMQPMessage(frame.getPayload());
jmsMessage = messageFactory.create(amqpMessage);
jmsMessage.setLongProperty(prefixVendor + Util.PROP_MESSAGE_FORMAT, frame.getMessageFormat().getValue());
jmsMessage.setBooleanProperty(amqpNative, false);
Header header = amqpMessage.getHeader();
if (header != null)
transformHeader(header, jmsMessage);
DeliveryAnnotations deliveryAnnotations = amqpMessage.getDeliveryAnnotations();
if (deliveryAnnotations != null)
transformMap(deliveryAnnotations.getValue(), jmsMessage, prefixDA);
MessageAnnotations messageAnnotations = amqpMessage.getMessageAnnotations();
if (messageAnnotations != null)
transformMap(messageAnnotations.getValue(), jmsMessage, prefixMA);
Properties properties = amqpMessage.getProperties();
if (properties != null)
transformProperties(properties, jmsMessage, destinationFactory);
ApplicationProperties applicationProperties = amqpMessage.getApplicationProperties();
if (applicationProperties != null)
transformApplicationProperties(applicationProperties, jmsMessage);
Footer footer = amqpMessage.getFooter();
if (footer != null)
transformMap(footer.getValue(), jmsMessage, prefixFT);
} catch (Exception e) {
throw new AMQPException(e.toString());
}
jmsMessage.reset();
return jmsMessage;
}
use of com.swiftmq.jms.MessageImpl in project swiftmq-ce by iitsoftware.
the class TransactedTopicSession method visitCommitRequest.
public void visitCommitRequest(CommitRequest req) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCommitRequest");
CommitReply reply = (CommitReply) req.createReply();
reply.setOk(true);
try {
// first: produce all messages
Object[] wrapper = req.getMessages();
ctx.incMsgsSent(wrapper.length);
req.setMessages(null);
long fcDelay = 0;
RingBuffer tempProducers = null;
for (int i = 0; i < wrapper.length; i++) {
DataByteArrayInputStream dis = new DataByteArrayInputStream((byte[]) wrapper[i]);
int producerId = dis.readInt();
int type = dis.readInt();
MessageImpl msg = MessageImpl.createInstance(type);
msg.readContent(dis);
dis.close();
Producer producer = null;
if (producerId == -1) {
TopicImpl topic = (TopicImpl) msg.getJMSDestination();
if (topic.getType() != DestinationFactory.TYPE_TEMPTOPIC)
ctx.authSwiftlet.verifyTopicSenderSubscription(topic.getTopicName(), ctx.activeLogin.getLoginId());
producer = new TopicProducer(ctx, topic);
if (tempProducers == null)
tempProducers = new RingBuffer(8);
tempProducers.add(producer);
transactionManager.addTransactionFactory(producer);
} else {
producer = (Producer) producerList.get(producerId);
}
QueuePushTransaction transaction = (QueuePushTransaction) producer.getTransaction();
transaction.putMessage(msg);
fcDelay = Math.max(fcDelay, transaction.getFlowControlDelay());
if (producerId == -1)
producer.markForClose();
}
// Next: do the commit
transactionManager.commit();
if (tempProducers != null) {
int size = tempProducers.getSize();
for (int i = 0; i < size; i++) {
((Producer) tempProducers.remove()).close();
}
}
reply.setDelay(fcDelay);
purgeMarkedProducers();
purgeMarkedConsumers();
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/commit produced messages failed: " + e.getMessage());
reply.setOk(false);
reply.setException((e instanceof JMSException) ? e : new javax.jms.JMSException(e.toString()));
}
reply.send();
}
use of com.swiftmq.jms.MessageImpl in project swiftmq-ce by iitsoftware.
the class NontransactedQueueSession method visitProduceMessageRequest.
public void visitProduceMessageRequest(ProduceMessageRequest req) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitProduceMessageRequest");
ctx.incMsgsSent(1);
ProduceMessageReply reply = null;
if (req.isReplyRequired())
reply = (ProduceMessageReply) req.createReply();
MessageImpl msg = req.getMessage();
int producerId = req.getQueueProducerId();
Producer producer = null;
try {
if (producerId == -1) {
String queueName = ((QueueImpl) msg.getJMSDestination()).getQueueName();
if (!ctx.queueManager.isQueueRunning(queueName))
throw new InvalidDestinationException("Invalid destination: " + queueName);
producer = new QueueProducer(ctx, queueName);
} else {
producer = (Producer) producerList.get(producerId);
}
QueuePushTransaction transaction = (QueuePushTransaction) producer.createTransaction();
transaction.putMessage(msg);
transaction.commit();
if (req.isReplyRequired()) {
reply.setDelay(transaction.getFlowControlDelay());
reply.setOk(true);
}
if (producerId == -1)
producer.close();
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/produce messages failed: " + e.getMessage());
if (req.isReplyRequired()) {
reply.setOk(false);
reply.setException((e instanceof JMSException) ? e : new javax.jms.JMSException(e.toString()));
}
}
if (req.isReplyRequired())
reply.send();
}
Aggregations