use of com.swiftmq.jms.TopicImpl in project swiftmq-ce by iitsoftware.
the class TopicInput method start.
@Override
public void start() throws Exception {
if (started)
return;
if (!ctx.ctx.topicManager.isTopicDefined(destinationName))
ctx.ctx.topicManager.createTopic(destinationName);
MessageSelector ms = null;
if (selector != null) {
ms = new MessageSelector(selector);
ms.compile();
}
if (durable) {
ActiveLogin dlogin = ctx.ctx.authenticationSwiftlet.createActiveLogin(clientId, "DURABLE");
dlogin.setClientId(clientId);
TopicImpl topic = ctx.ctx.topicManager.verifyTopic(new TopicImpl(destinationName));
queueName = ctx.ctx.topicManager.subscribeDurable(durableName, topic, ms, false, dlogin);
} else {
queueName = ctx.ctx.queueManager.createTemporaryQueue();
subscriberId = ctx.ctx.topicManager.subscribe(destinationName, ms, false, queueName, true);
}
QueueReceiver receiver = ctx.ctx.queueManager.createQueueReceiver(queueName, (ActiveLogin) null, null);
messageProcessor = new QueueMessageProcessor(ctx, this, receiver, null);
messageProcessor.restart();
started = true;
}
use of com.swiftmq.jms.TopicImpl in project swiftmq-ce by iitsoftware.
the class NontransactedTopicSession method visit.
public void visit(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();
int producerId = req.getQueueProducerId();
Producer producer = null;
try {
MessageImpl msg = SMQPUtil.getMessage(req);
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);
}
}
if (req.isReplyRequired())
reply.send();
}
use of com.swiftmq.jms.TopicImpl in project swiftmq-ce by iitsoftware.
the class NontransactedTopicSession method visit.
public void visit(CreateDurableRequest req) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCreateDurableRequest");
CreateDurableReply reply = (CreateDurableReply) req.createReply();
try {
ctx.activeLogin.getResourceLimitGroup().incConsumers();
} catch (ResourceLimitException e) {
reply.setOk(false);
reply.setException(new JMSException(e.toString()));
reply.send();
return;
}
TopicImpl topic = req.getTopic();
String messageSelector = req.getMessageSelector();
boolean noLocal = req.isNoLocal();
String durableName = req.getDurableName();
try {
int consumerId = 0;
TopicDurableConsumer consumer = null;
consumerId = ArrayListTool.setFirstFreeOrExpand(consumerList, null);
consumer = new TopicDurableConsumer(ctx, durableName, topic, messageSelector, noLocal);
consumerList.set(consumerId, consumer);
consumer.createReadTransaction();
consumer.createTransaction();
reply.setOk(true);
reply.setTopicSubscriberId(consumerId);
reply.setQueueName(consumer.getQueueName() + '@' + SwiftletManager.getInstance().getRouterName());
if (durableEntityList != null) {
Entity durEntity = durableEntityList.createEntity();
durEntity.setName(ctx.activeLogin.getClientId() + "$" + durableName);
durEntity.createCommands();
Property prop = durEntity.getProperty("clientid");
prop.setValue(ctx.activeLogin.getClientId());
prop.setReadOnly(true);
prop = durEntity.getProperty("durablename");
prop.setValue(durableName);
prop.setReadOnly(true);
prop = durEntity.getProperty("topic");
prop.setValue(topic.getTopicName());
prop.setReadOnly(true);
prop = durEntity.getProperty("boundto");
prop.setValue(consumer.getQueueName());
prop.setReadOnly(true);
prop = durEntity.getProperty("nolocal");
prop.setValue(new Boolean(noLocal));
prop.setReadOnly(true);
prop = durEntity.getProperty("selector");
if (messageSelector != null) {
prop.setValue(messageSelector);
}
prop.setReadOnly(true);
durableEntityList.addEntity(durEntity);
}
} catch (InvalidSelectorException e) {
ctx.activeLogin.getResourceLimitGroup().decConsumers();
ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/CreateDurable has invalid Selector: " + e);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/CreateDurable has invalid Selector: " + e);
reply.setOk(false);
reply.setException(e);
} catch (Exception e1) {
ctx.activeLogin.getResourceLimitGroup().decConsumers();
ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/Exception during create durable: " + e1);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/Exception during create durable: " + e1);
reply.setOk(false);
reply.setException(e1);
}
reply.send();
}
use of com.swiftmq.jms.TopicImpl in project swiftmq-ce by iitsoftware.
the class TransactedTopicSession method visitCreateDurableRequest.
public void visitCreateDurableRequest(CreateDurableRequest req) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCreateDurableRequest");
CreateDurableReply reply = (CreateDurableReply) req.createReply();
try {
ctx.activeLogin.getResourceLimitGroup().incConsumers();
} catch (ResourceLimitException e) {
reply.setOk(false);
reply.setException(new JMSException(e.toString()));
reply.send();
return;
}
TopicImpl topic = req.getTopic();
String messageSelector = req.getMessageSelector();
boolean noLocal = req.isNoLocal();
String durableName = req.getDurableName();
try {
int consumerId = 0;
TopicDurableConsumer consumer = null;
consumerId = ArrayListTool.setFirstFreeOrExpand(consumerList, null);
consumer = new TopicDurableConsumer(ctx, durableName, topic, messageSelector, noLocal);
consumerList.set(consumerId, consumer);
reply.setOk(true);
reply.setTopicSubscriberId(consumerId);
if (durableEntityList != null) {
Entity durEntity = durableEntityList.createEntity();
durEntity.setName(ctx.activeLogin.getClientId() + "$" + durableName);
durEntity.createCommands();
Property prop = durEntity.getProperty("clientid");
prop.setValue(ctx.activeLogin.getClientId());
prop.setReadOnly(true);
prop = durEntity.getProperty("durablename");
prop.setValue(durableName);
prop.setReadOnly(true);
prop = durEntity.getProperty("topic");
prop.setValue(topic.getTopicName());
prop.setReadOnly(true);
prop = durEntity.getProperty("boundto");
prop.setValue(consumer.getQueueName());
prop.setReadOnly(true);
prop = durEntity.getProperty("nolocal");
prop.setValue(new Boolean(noLocal));
prop.setReadOnly(true);
prop = durEntity.getProperty("selector");
if (messageSelector != null) {
prop.setValue(messageSelector);
}
prop.setReadOnly(true);
durableEntityList.addEntity(durEntity);
}
consumer.createReadTransaction();
// enlist it at the transaction manager
transactionManager.addTransactionFactory(consumer);
} catch (InvalidSelectorException e) {
ctx.activeLogin.getResourceLimitGroup().decConsumers();
ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/CreateDurable has invalid Selector: " + e);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/CreateDurable has invalid Selector: " + e);
reply.setOk(false);
reply.setException(e);
} catch (Exception e1) {
ctx.activeLogin.getResourceLimitGroup().decConsumers();
ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/Exception during create durable: " + e1);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/Exception during create durable: " + e1);
reply.setOk(false);
reply.setException((e1 instanceof JMSException) ? e1 : new javax.jms.JMSException(e1.toString()));
}
reply.send();
}
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();
}
Aggregations