use of com.swiftmq.swiftlet.queue.QueuePushTransaction in project swiftmq-ce by iitsoftware.
the class DispatchQueue method dispatchClientRequest.
private void dispatchClientRequest(ClientRequest event) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/dispatchClientRequest, event: " + event + " ...");
Dispatcher d = (Dispatcher) dispatchers.get(event.getQueueName());
if (d != null) {
if (d.isInvalid()) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/dispatchClientRequest, event: " + event + ", dispatcher invalid (1): " + d);
d.close();
dispatchers.remove(event.getQueueName());
} else {
d.process(event);
if (d.isInvalid()) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/dispatchClientRequest, event: " + event + ", dispatcher invalid (2): " + d);
d.close();
dispatchers.remove(event.getQueueName());
}
}
} else {
try {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/dispatchClientRequest, event: " + event + " try ProtocolRequest ...");
dis.reset();
dis.setBuffer(event.getBuffer());
ProtocolRequest r = null;
try {
r = (ProtocolRequest) Dumpalizer.construct(dis, factory);
} catch (NullPointerException e) {
// Since we can get old LeaseRequests here, we can ignore it.
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/dispatchClientRequest, got exception: " + e + ", probably old LeaseRequest, ignore!");
return;
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/dispatchClientRequest, event: " + event + " got ProtocolRequest: " + r);
ProtocolReply reply = (ProtocolReply) r.createReply();
switch(r.getVersion()) {
case 400:
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/dispatchClientRequest, event: " + event + " create v400 Dispatcher");
d = new com.swiftmq.impl.mgmt.standard.v400.DispatcherImpl(ctx, event.getQueueName());
dispatchers.put(event.getQueueName(), d);
reply.setOk(true);
break;
case 750:
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/dispatchClientRequest, event: " + event + " create v750 Dispatcher");
d = new com.swiftmq.impl.mgmt.standard.v750.DispatcherImpl(ctx, event.getUserName(), event.getQueueName());
dispatchers.put(event.getQueueName(), d);
reply.setOk(true);
break;
default:
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/dispatchClientRequest, event: " + event + " failed: Unsupported protocol version: " + r.getVersion());
reply.setOk(false);
reply.setException(new Exception("Unsupported protocol version: " + r.getVersion()));
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/dispatchClientRequest, event: " + event + " send reply: " + reply);
QueueSender sender = ctx.queueManager.createQueueSender(event.getQueueName(), null);
BytesMessageImpl msg = new BytesMessageImpl();
msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
msg.setJMSDestination(new QueueImpl(event.getQueueName()));
msg.setJMSPriority(MessageImpl.MAX_PRIORITY - 1);
dos.rewind();
Dumpalizer.dump(dos, reply);
msg.writeBytes(dos.getBuffer(), 0, dos.getCount());
QueuePushTransaction t = sender.createTransaction();
t.putMessage(msg);
t.commit();
sender.close();
checkStartLeases();
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/dispatchClientRequest, event: " + event + " got exception: " + e);
ctx.logSwiftlet.logError(ctx.mgmtSwiftlet.getName(), toString() + "/dispatchClientRequest, event: " + event + " got exception: " + e);
dispatchers.remove(event.getQueueName());
}
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/dispatchClientRequest, event: " + event + " done");
}
use of com.swiftmq.swiftlet.queue.QueuePushTransaction in project swiftmq-ce by iitsoftware.
the class RequestVisitor method visit.
public void visit(BindRequest request) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request);
String name = request.getName();
QueueImpl queue = request.getQueue();
String msg = null;
boolean registered = false;
try {
String queueName = queue.getQueueName();
if (queueName.endsWith(SwiftletManager.getInstance().getRouterName())) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + " is local");
registered = true;
name = name != null ? name : queueName;
if (ctx.jndiSwiftlet.getJNDIObject(name) != null)
throw new Exception("bind failed, object '" + name + "' is already registered!");
ctx.jndiSwiftlet.registerJNDIObject(name, queue);
}
} catch (Exception e) {
msg = e.getMessage();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + ": exception: " + msg);
}
if (registered) {
if (replyToQueue != null) {
try {
QueueSender sender = ctx.queueManager.createQueueSender(replyToQueue.getQueueName(), null);
QueuePushTransaction transaction = sender.createTransaction();
TextMessageImpl reply = new TextMessageImpl();
reply.setJMSDeliveryMode(javax.jms.DeliveryMode.NON_PERSISTENT);
reply.setJMSDestination(replyToQueue);
reply.setJMSPriority(MessageImpl.MAX_PRIORITY);
reply.setText(msg);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + ": sending reply " + reply);
transaction.putMessage(reply);
transaction.commit();
sender.close();
} catch (Exception e1) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + ": exception occurred while sending reply: " + e1);
}
} else if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + ": replyTo is not set. Unable to send.");
}
}
use of com.swiftmq.swiftlet.queue.QueuePushTransaction in project swiftmq-ce by iitsoftware.
the class RequestVisitor method visit.
public void visit(LookupRequest request) {
String name = request.getName();
Object object = ctx.jndiSwiftlet.getJNDIObject(name);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + ": request '" + name + " returns: " + object);
if (object == null) {
if (forwardToTopic) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + ": not found, forward to topic " + JNDISwiftlet.JNDI_TOPIC);
try {
QueueSender sender = ctx.queueManager.createQueueSender(ctx.topicManager.getQueueForTopic(JNDISwiftlet.JNDI_TOPIC), null);
QueuePushTransaction transaction = sender.createTransaction();
Versionable versionable = new Versionable();
versionable.addVersioned(400, createVersioned(400, request), "com.swiftmq.jndi.protocol.v400.JNDIRequestFactory");
BytesMessageImpl msg = createMessage(versionable, replyToQueue);
transaction.putMessage(msg);
transaction.commit();
sender.close();
} catch (Exception e1) {
e1.printStackTrace();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + ": exception occurred while forwarding lookup request: " + e1);
}
}
} else {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + ": replyTo " + replyToQueue);
if (replyToQueue != null) {
try {
QueueSender sender = ctx.queueManager.createQueueSender(replyToQueue.getQueueName(), null);
QueuePushTransaction transaction = sender.createTransaction();
MessageImpl reply = createReply(object);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + ": sending reply " + reply);
transaction.putMessage(reply);
transaction.commit();
sender.close();
} catch (Exception e1) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + ": exception occurred while sending reply: " + e1);
}
} else if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + ": replyTo is not set. Unable to send.");
}
}
use of com.swiftmq.swiftlet.queue.QueuePushTransaction in project swiftmq-ce by iitsoftware.
the class RequestVisitor method visit.
public void visit(RebindRequest request) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request);
String name = request.getName();
QueueImpl queue = request.getQueue();
String msg = null;
boolean registered = false;
try {
String queueName = queue.getQueueName();
if (queueName.endsWith(SwiftletManager.getInstance().getRouterName())) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + " is local");
registered = true;
if (ctx.jndiSwiftlet.getJNDIObject(name) != null)
throw new Exception("rebind failed, object '" + name + "' is already registered!");
String oldName = ctx.jndiSwiftlet.getJNDIObjectName(queue);
if (oldName != null) {
Object ro = ctx.jndiSwiftlet.getJNDIObject(oldName);
if (ro != null) {
if (ro.getClass() != queue.getClass())
throw new Exception("rebind failed; attempt to overwrite a different registration class!");
ctx.jndiSwiftlet.deregisterJNDIObject(oldName);
}
}
ctx.jndiSwiftlet.registerJNDIObject(name, queue);
}
} catch (Exception e) {
msg = e.getMessage();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + ": exception: " + msg);
}
if (registered) {
if (replyToQueue != null) {
try {
QueueSender sender = ctx.queueManager.createQueueSender(replyToQueue.getQueueName(), null);
QueuePushTransaction transaction = sender.createTransaction();
TextMessageImpl reply = new TextMessageImpl();
reply.setJMSDeliveryMode(javax.jms.DeliveryMode.NON_PERSISTENT);
reply.setJMSDestination(replyToQueue);
reply.setJMSPriority(MessageImpl.MAX_PRIORITY);
reply.setText(msg);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + ": sending reply " + reply);
transaction.putMessage(reply);
transaction.commit();
sender.close();
} catch (Exception e1) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + ": exception occurred while sending reply: " + e1);
}
} else if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.jndiSwiftlet.getName(), "visitor " + request + ": replyTo is not set. Unable to send.");
}
}
use of com.swiftmq.swiftlet.queue.QueuePushTransaction 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