use of com.swiftmq.swiftlet.queue.QueueSender in project swiftmq-ce by iitsoftware.
the class TopicAnnounceSender method visit.
public void visit(PODestinationAdded po) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.topicManager.getName(), toString() + "/" + po);
RemoteTopicManager rtm = (RemoteTopicManager) rtmList.get(po.getRoute().getDestination());
if (rtm == null) {
try {
QueueSender sender = ctx.queueManager.createQueueSender(po.getRoute().getOutboundQueueName(), null);
rtmList.put(po.getRoute().getDestination(), new RemoteTopicManager(po.getRoute().getDestination(), sender));
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.topicManager.getName(), toString() + "/" + po + ", Exception: " + e);
}
} else {
if (rtm.getSender() == null) {
try {
QueueSender sender = ctx.queueManager.createQueueSender(po.getRoute().getOutboundQueueName(), null);
rtm.setSender(sender);
rtm.processBuffer();
if (!rtm.isValid()) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.topicManager.getName(), toString() + "/" + po + ", RTM object invalid, close!");
rtm.close();
rtmList.remove(po.getRoute().getDestination());
}
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.topicManager.getName(), toString() + "/" + po + ", Exception: " + e);
}
}
}
}
use of com.swiftmq.swiftlet.queue.QueueSender in project swiftmq-ce by iitsoftware.
the class XADeliveryStage method close.
public void close() {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close ...");
super.close();
closed = true;
if (notificationList.size() > 0) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, final notify ...");
for (Iterator iter = notificationList.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
DeliveryRequest dr = (DeliveryRequest) entry.getValue();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, final notify: " + dr);
dr.callback.delivered(dr);
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, final notify done");
notificationList.clear();
}
if (outboundTransactions.size() > 0) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, passing prepared outbound tx to XAResourceManager ...");
for (Iterator iter = outboundTransactions.entrySet().iterator(); iter.hasNext(); ) {
try {
Map.Entry entry = (Map.Entry) iter.next();
XidImpl xid = (XidImpl) entry.getKey();
XAContext xac = ctx.xaResourceManagerSwiftlet.createXAContext(xid);
int id = xac.register(toString());
QueuePullTransaction t = (QueuePullTransaction) entry.getValue();
xac.addTransaction(id, t.getQueueName(), t);
xac.unregister(id, false);
xac.setPrepared(true);
} catch (XAContextException e) {
ctx.logSwiftlet.logError(ctx.routingSwiftlet.getName(), toString() + "/close, passing prepared outbound tx to XAResourceManager, exception: " + e);
}
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, passing prepared outbound tx to XAResourceManager done");
outboundTransactions.clear();
}
if (inboundTransactions.size() > 0) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, passing prepared inbound tx to XAResourceManager ...");
for (Iterator iter = inboundTransactions.entrySet().iterator(); iter.hasNext(); ) {
((Tx) ((Map.Entry) iter.next()).getValue()).handOver();
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString() + "/close, passing prepared inbound tx to XAResourceManager done");
}
for (Iterator iter = producers.entrySet().iterator(); iter.hasNext(); ) {
QueueSender sender = (QueueSender) ((Map.Entry) iter.next()).getValue();
try {
sender.close();
} catch (Exception e) {
}
}
producers.clear();
for (Iterator iter = consumers.entrySet().iterator(); iter.hasNext(); ) {
QueueReceiver receiver = (QueueReceiver) ((Map.Entry) iter.next()).getValue();
try {
receiver.close();
} catch (Exception e) {
}
}
consumers.clear();
if (throttleQueue != null)
throttleQueue.close();
visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.SMQRFactory.START_STAGE_REQ, null);
visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.SMQRFactory.SEND_ROUTE_REQ, null);
visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.SMQRFactory.DELIVERY_REQ, null);
visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v942.SMQRFactory.ROUTE_REQ, null);
visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v942.SMQRFactory.ADJUST_REQ, null);
visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v942.SMQRFactory.TRANSACTION_REQ, null);
visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v942.SMQRFactory.COMMIT_REQ, null);
visitor.setRequestHandler(com.swiftmq.impl.routing.single.smqpr.v942.SMQRFactory.COMMIT_REPREQ, null);
}
use of com.swiftmq.swiftlet.queue.QueueSender in project swiftmq-ce by iitsoftware.
the class XADeliveryStage method processTransactionRequest.
private void processTransactionRequest(TransactionRequest request) throws Exception {
XidImpl xid = request.getXid();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + " ...");
Tx tx = new Tx(xid);
inboundTransactions.put(xid, tx);
List messageList = request.getMessageList();
for (int i = 0; i < messageList.size(); i++) {
boolean msgValid = true;
MessageImpl msg = (MessageImpl) messageList.get(i);
String queueName = null;
if (msg.getDestRouter().equals(ctx.routerName))
queueName = msg.getDestQueue();
else
queueName = SchedulerRegistry.QUEUE_PREFIX + msg.getDestRouter();
QueueSender sender = (QueueSender) producers.get(queueName);
if (sender == null) {
try {
sender = ctx.queueManager.createQueueSender(queueName, null);
producers.put(queueName, sender);
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + ", exception creating sender, queue=" + queueName);
if (ctx.queueManager.isTemporaryQueue(queueName)) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + ", temp queue, forget it");
msgValid = false;
} else {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + ", using unroutable queue");
sender = (QueueSender) producers.get(RoutingSwiftletImpl.UNROUTABLE_QUEUE);
msg.setStringProperty(MessageImpl.PROP_UNROUTABLE_REASON, e.toString());
}
}
}
if (msgValid) {
try {
QueuePushTransaction t = tx.getTransaction(queueName);
if (t == null) {
t = sender.createTransaction();
tx.addTransaction(queueName, t);
}
t.putMessage(msg);
} catch (Exception e) {
try {
if (!sender.getQueueName().startsWith(RoutingSwiftletImpl.UNROUTABLE_QUEUE))
sender.close();
} catch (Exception e1) {
}
producers.remove(queueName);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + ", exception put message, queue=" + queueName);
if (ctx.queueManager.isTemporaryQueue(queueName)) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + ", temp queue, forget it");
} else {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + ", using unroutable queue");
sender = (QueueSender) producers.get(RoutingSwiftletImpl.UNROUTABLE_QUEUE);
msg.setStringProperty(MessageImpl.PROP_UNROUTABLE_REASON, e.toString());
QueuePushTransaction t = tx.getTransaction(RoutingSwiftletImpl.UNROUTABLE_QUEUE);
if (t == null) {
t = sender.createTransaction();
tx.addTransaction(RoutingSwiftletImpl.UNROUTABLE_QUEUE, t);
}
t.putMessage(msg);
}
}
}
}
try {
tx.prepare();
} catch (Exception e) {
tx.rollback();
inboundTransactions.remove(xid);
throw e;
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.routingSwiftlet.getName(), toString("INBOUND") + "/processTransactionRequest, xid=" + xid + " done");
}
use of com.swiftmq.swiftlet.queue.QueueSender 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.QueueSender 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.");
}
}
Aggregations