use of com.swiftmq.jms.TopicImpl in project swiftmq-ce by iitsoftware.
the class NontransactedTopicSession method visit.
public void visit(CreatePublisherRequest req) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCreatePublisherRequest");
CreatePublisherReply reply = (CreatePublisherReply) req.createReply();
try {
ctx.activeLogin.getResourceLimitGroup().incProducers();
} catch (ResourceLimitException e) {
reply.setOk(false);
reply.setException(new JMSException(e.toString()));
reply.send();
return;
}
TopicImpl topic = req.getTopic();
try {
if (topic.getType() != DestinationFactory.TYPE_TEMPTOPIC)
ctx.authSwiftlet.verifyTopicSenderSubscription(topic.getTopicName(), ctx.activeLogin.getLoginId());
int producerId;
TopicProducer producer;
producerId = ArrayListTool.setFirstFreeOrExpand(producerList, null);
producer = new TopicProducer(ctx, topic);
producerList.set(producerId, producer);
reply.setTopicPublisherId(producerId);
reply.setOk(true);
if (publisherEntityList != null) {
Entity publisherEntity = publisherEntityList.createEntity();
publisherEntity.setName(topic.getTopicName() + "-" + producerId);
publisherEntity.setDynamicObject(producer);
publisherEntity.createCommands();
Property prop = publisherEntity.getProperty("topic");
prop.setReadOnly(false);
prop.setValue(topic.getTopicName());
prop.setReadOnly(true);
publisherEntityList.addEntity(publisherEntity);
}
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/exception creating publisher: " + e.getMessage());
ctx.logSwiftlet.logError("sys$jms", ctx.tracePrefix + "/exception creating publisher: " + e.getMessage());
reply.setOk(false);
reply.setException(e);
ctx.activeLogin.getResourceLimitGroup().decProducers();
}
reply.send();
}
use of com.swiftmq.jms.TopicImpl in project swiftmq-ce by iitsoftware.
the class NontransactedTopicSession method visit.
public void visit(CreateSubscriberRequest req) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCreateSubscriberRequest");
CreateSubscriberReply reply = (CreateSubscriberReply) 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();
try {
Entity subEntity = null;
if (subscriberEntityList != null)
subEntity = subscriberEntityList.createEntity();
int consumerId = 0;
TopicConsumer consumer = null;
if (topic.getType() == DestinationFactory.TYPE_TOPIC) {
consumerId = ArrayListTool.setFirstFreeOrExpand(consumerList, null);
consumer = new TopicConsumer(ctx, topic, messageSelector, noLocal);
consumerList.set(consumerId, consumer);
if (subEntity != null) {
Property prop = subEntity.getProperty("topic");
prop.setReadOnly(false);
prop.setValue(topic.getTopicName());
prop.setReadOnly(true);
prop = subEntity.getProperty("boundto");
prop.setReadOnly(false);
prop.setValue(topic.getQueueName());
prop.setReadOnly(true);
subEntity.setDynamicObject(consumer);
}
if (subEntity != null)
subEntity.setName(topic.getTopicName() + "-" + consumerId);
} else {
consumerId = ArrayListTool.setFirstFreeOrExpand(consumerList, null);
consumer = new TopicConsumer(ctx, topic, messageSelector, noLocal);
consumerList.set(consumerId, consumer);
if (subEntity != null)
subEntity.setDynamicObject(consumer);
if (subEntity != null) {
subEntity.setName(topic.getQueueName() + "-" + consumerId);
Property prop = subEntity.getProperty("temptopic");
prop.setReadOnly(false);
prop.setValue(new Boolean(true));
prop.setReadOnly(true);
prop = subEntity.getProperty("boundto");
prop.setReadOnly(false);
prop.setValue(topic.getQueueName());
prop.setReadOnly(true);
}
}
consumer.setAutoCommit(req.isAutoCommit());
consumer.createReadTransaction();
consumer.createTransaction();
reply.setOk(true);
reply.setTopicSubscriberId(consumerId);
reply.setTmpQueueName((consumer).getQueueName());
if (subEntity != null) {
Property prop = subEntity.getProperty("nolocal");
prop.setReadOnly(false);
prop.setValue(new Boolean(noLocal));
prop.setReadOnly(true);
subEntity.createCommands();
prop = subEntity.getProperty("selector");
if (messageSelector != null) {
prop.setValue(messageSelector);
}
prop.setReadOnly(true);
subscriberEntityList.addEntity(subEntity);
}
} catch (InvalidSelectorException e) {
ctx.activeLogin.getResourceLimitGroup().decConsumers();
ctx.logSwiftlet.logWarning("sys$jms", ctx.tracePrefix + "/CreateSubscriber has invalid Selector: " + e);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/CreateSubscriber 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 subscriber: " + e1);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/Exception during create subscriber: " + e1);
reply.setOk(false);
reply.setException(e1);
}
reply.send();
}
use of com.swiftmq.jms.TopicImpl in project swiftmq-ce by iitsoftware.
the class NontransactedTopicSession method visit.
public void visit(CreatePublisherRequest req) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/visitCreatePublisherRequest");
CreatePublisherReply reply = (CreatePublisherReply) req.createReply();
try {
ctx.activeLogin.getResourceLimitGroup().incProducers();
} catch (ResourceLimitException e) {
reply.setOk(false);
reply.setException(new JMSException(e.toString()));
reply.send();
return;
}
TopicImpl topic = req.getTopic();
try {
if (topic.getType() != DestinationFactory.TYPE_TEMPTOPIC)
ctx.authSwiftlet.verifyTopicSenderSubscription(topic.getTopicName(), ctx.activeLogin.getLoginId());
int producerId;
TopicProducer producer;
producerId = ArrayListTool.setFirstFreeOrExpand(producerList, null);
producer = new TopicProducer(ctx, topic);
producerList.set(producerId, producer);
reply.setTopicPublisherId(producerId);
reply.setOk(true);
if (publisherEntityList != null) {
Entity publisherEntity = publisherEntityList.createEntity();
publisherEntity.setName(topic.getTopicName() + "-" + producerId);
publisherEntity.setDynamicObject(producer);
publisherEntity.createCommands();
Property prop = publisherEntity.getProperty("topic");
prop.setReadOnly(false);
prop.setValue(topic.getTopicName());
prop.setReadOnly(true);
publisherEntityList.addEntity(publisherEntity);
}
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$jms", ctx.tracePrefix + "/exception creating publisher: " + e.getMessage());
ctx.logSwiftlet.logError("sys$jms", ctx.tracePrefix + "/exception creating publisher: " + e.getMessage());
reply.setOk(false);
reply.setException(e);
ctx.activeLogin.getResourceLimitGroup().decProducers();
}
reply.send();
}
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);
long ttl = msg.getJMSExpiration();
if (ttl > 0)
msg.setJMSExpiration(System.currentTimeMillis() + ttl);
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 ClusterMetricPublisher method createMessage.
private BytesMessageImpl createMessage(Versionable versionable) throws Exception {
BytesMessageImpl msg = new BytesMessageImpl();
versionable.transferToMessage(msg);
msg.setJMSDeliveryMode(javax.jms.DeliveryMode.NON_PERSISTENT);
msg.setJMSDestination(new TopicImpl(QueueManagerImpl.CLUSTER_TOPIC));
msg.setJMSPriority(MessageImpl.MAX_PRIORITY);
if (interval > 0)
msg.setJMSExpiration(System.currentTimeMillis() + interval * 2);
msg.setStringProperty(PROP_SOURCE_ROUTER, SwiftletManager.getInstance().getRouterName());
msg.setReadOnly(false);
return msg;
}
Aggregations