use of com.swiftmq.jms.TopicImpl in project swiftmq-ce by iitsoftware.
the class CompositeQueue method putMessage.
public void putMessage(Object object, MessageImpl message) throws QueueException {
if (ctx.queueSpace.enabled)
ctx.queueSpace.trace(getQueueName(), "putMessage, cTxId=" + object + " ...");
boolean needCopy = false;
boolean hasDefaultDelivery = false;
int timesDelivered = 0;
List entries = ((CompositeTransactionId) object).getEntries();
for (int i = 0; i < entries.size(); i++) {
CompositeTransactionIdEntry entry = (CompositeTransactionIdEntry) entries.get(i);
if (entry.isDefaultBinding)
hasDefaultDelivery = true;
if (!entry.isDefaultBinding && (entry.selector == null || entry.selector.isSelected(message))) {
try {
MessageImpl m = message;
if (needCopy)
m = copyMessage(message);
else
needCopy = true;
if (entry.generateNewMessageId)
m.setJMSMessageID(nextId());
if (entry.changeDestination)
m.setJMSDestination(new QueueImpl(ctx.queueManager.fqn(entry.originalName)));
if (!entry.isQueue)
m.setJMSDestination(new TopicImpl(entry.originalName));
if (ctx.queueSpace.enabled)
ctx.queueSpace.trace(getQueueName(), "putMessage on binding '" + entry.queue.getQueueName());
entry.queue.putMessage(entry.txId, m);
timesDelivered++;
} catch (Exception e) {
ctx.logSwiftlet.logError(ctx.queueManager.getName(), "Composite Queue '" + getQueueName() + "': putMessage on binding queue '" + entry.queue.getQueueName() + "', exception=" + e);
if (ctx.queueSpace.enabled)
ctx.queueSpace.trace(getQueueName(), "putMessage on binding queue '" + entry.queue.getQueueName() + "', exception=" + e);
}
}
}
if (ctx.queueSpace.enabled)
ctx.queueSpace.trace(getQueueName(), "putMessage delivered to " + timesDelivered + " bindings, hasDefaultDelivery=" + hasDefaultDelivery);
if (timesDelivered == 0 && hasDefaultDelivery) {
if (ctx.queueSpace.enabled)
ctx.queueSpace.trace(getQueueName(), "putMessage, let's check the default bindings ...");
for (int i = 0; i < entries.size(); i++) {
CompositeTransactionIdEntry entry = (CompositeTransactionIdEntry) entries.get(i);
if (entry.isDefaultBinding) {
try {
MessageImpl m = message;
if (needCopy)
m = copyMessage(message);
else
needCopy = true;
if (entry.generateNewMessageId)
m.setJMSMessageID(nextId());
if (entry.changeDestination)
m.setJMSDestination(new QueueImpl(ctx.queueManager.fqn(entry.originalName)));
if (!entry.isQueue)
m.setJMSDestination(new TopicImpl(entry.originalName));
if (ctx.queueSpace.enabled)
ctx.queueSpace.trace(getQueueName(), "putMessage on DEFAULT binding '" + entry.queue.getQueueName());
entry.queue.putMessage(entry.txId, m);
} catch (Exception e) {
ctx.logSwiftlet.logError(ctx.queueManager.getName(), "Composite Queue '" + getQueueName() + "': putMessage on binding queue '" + entry.queue.getQueueName() + "', exception=" + e);
if (ctx.queueSpace.enabled)
ctx.queueSpace.trace(getQueueName(), "putMessage on binding queue '" + entry.queue.getQueueName() + "', exception=" + e);
}
}
}
}
if (ctx.queueSpace.enabled)
ctx.queueSpace.trace(getQueueName(), "putMessage, cTxId=" + object + " done");
}
use of com.swiftmq.jms.TopicImpl in project swiftmq-client by iitsoftware.
the class TopicConnectionConsumerImpl method createDurableSubscriber.
void createDurableSubscriber(TopicImpl topic, String messageSelector, String durableName) throws JMSException {
try {
SwiftUtilities.verifyDurableName(durableName);
} catch (Exception e) {
throw new JMSException(e.getMessage());
}
Reply reply = null;
try {
reply = (CreateDurableReply) requestRegistry.request(new CreateDurableRequest(dispatchId, (TopicImpl) topic, messageSelector, false, durableName));
} catch (Exception e) {
throw ExceptionConverter.convert(e);
}
if (reply.isOk()) {
queueName = ((CreateDurableReply) reply).getQueueName();
} else {
throw ExceptionConverter.convert(reply.getException());
}
fillCache();
}
use of com.swiftmq.jms.TopicImpl in project swiftmq-client by iitsoftware.
the class TopicConnectionConsumerImpl method createDurableSubscriber.
void createDurableSubscriber(TopicImpl topic, String messageSelector, String durableName) throws JMSException {
try {
SwiftUtilities.verifyDurableName(durableName);
} catch (Exception e) {
throw new JMSException(e.getMessage());
}
Reply reply = null;
try {
reply = (CreateDurableReply) requestRegistry.request(new CreateDurableRequest(dispatchId, (TopicImpl) topic, messageSelector, false, durableName));
} catch (Exception e) {
throw ExceptionConverter.convert(e);
}
if (reply.isOk()) {
queueName = ((CreateDurableReply) reply).getQueueName();
} else {
throw ExceptionConverter.convert(reply.getException());
}
fillCache();
}
use of com.swiftmq.jms.TopicImpl 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.TopicImpl in project swiftmq-ce by iitsoftware.
the class NontransactedTopicSession 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) {
TopicImpl topic = (TopicImpl) msg.getJMSDestination();
if (topic.getType() != DestinationFactory.TYPE_TEMPTOPIC)
ctx.authSwiftlet.verifyTopicSenderSubscription(topic.getTopicName(), ctx.activeLogin.getLoginId());
producer = new TopicProducer(ctx, topic);
} 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