use of com.swiftmq.tools.versioning.Versionable in project swiftmq-client by iitsoftware.
the class ContextImpl method lookup.
public synchronized Object lookup(String name) throws NamingException {
if (closed)
throw new NamingException("context is closed!");
if (name == null)
throw new OperationNotSupportedException("context cloning is not supported!");
boolean connectionClosed = false;
Object obj = null;
try {
checkConnection();
TemporaryQueue tq = session.createTemporaryQueue();
MessageConsumer consumer = session.createConsumer(tq);
Versionable versionable = new Versionable();
versionable.addVersioned(Versions.JNDI_CURRENT, createVersioned(Versions.JNDI_CURRENT, new LookupRequest(name)), "com.swiftmq.jndi.protocol.v" + Versions.JNDI_CURRENT + ".JNDIRequestFactory");
BytesMessage request = createMessage(versionable, tq);
producer.send(getLookupDestination(session), request, DeliveryMode.NON_PERSISTENT, MessageImpl.MAX_PRIORITY, 0);
MessageImpl reply = null;
if (jndiInfo.getTimeout() == 0)
reply = (MessageImpl) consumer.receive();
else
reply = (MessageImpl) consumer.receive(jndiInfo.getTimeout());
if (reply != null) {
if (reply instanceof ObjectMessageImpl)
obj = ((ObjectMessageImpl) reply).getObject();
else {
BytesMessageImpl msg = (BytesMessageImpl) reply;
Versionable vreply = Versionable.toVersionable(msg);
vreply.selectVersions(Versions.cutAfterIndex(Versions.getSelectedIndex(Versions.JMS_CURRENT, Versions.JMS), Versions.JMS));
obj = vreply.createVersionedObject();
}
}
if (!((SwiftMQMessageConsumer) consumer).isClosed()) {
consumer.close();
tq.delete();
} else
connectionClosed = true;
} catch (Exception e) {
throw new CommunicationException("exception occurred during lookup: " + e);
}
if (connectionClosed)
throw new CommunicationException("Connection lost!");
if (obj == null)
throw new NameNotFoundException("Name '" + name + "' not found (timeout occured)!");
return obj;
}
use of com.swiftmq.tools.versioning.Versionable in project swiftmq-client by iitsoftware.
the class ContextImpl method bind.
public synchronized void bind(String name, Object obj) throws NamingException {
if (closed)
throw new NamingException("context is closed!");
if (!(obj instanceof TemporaryTopicImpl || obj instanceof TemporaryQueueImpl))
throw new OperationNotSupportedException("bind is only supported for TemporaryQueues/TemporaryTopics!");
try {
checkConnection();
TemporaryTopic tt = session.createTemporaryTopic();
MessageConsumer consumer = session.createConsumer(tt);
Versionable versionable = new Versionable();
versionable.addVersioned(Versions.JNDI_CURRENT, createVersioned(Versions.JNDI_CURRENT, new BindRequest(name, (QueueImpl) obj)), "com.swiftmq.jndi.protocol.v" + Versions.JNDI_CURRENT + ".JNDIRequestFactory");
BytesMessage request = createMessage(versionable, tt);
producer.send(session.createTopic(JNDISwiftlet.JNDI_TOPIC), request, DeliveryMode.NON_PERSISTENT, MessageImpl.MAX_PRIORITY, 0);
TextMessage reply = (TextMessage) consumer.receive();
String text = reply.getText();
consumer.close();
tt.delete();
if (text != null)
throw new Exception(text);
} catch (Exception e) {
throw new NamingException("exception occurred during bind: " + e);
}
}
use of com.swiftmq.tools.versioning.Versionable in project swiftmq-ce by iitsoftware.
the class TopicManagerImpl method registerJNDI.
private void registerJNDI(String name, TopicImpl topic) {
try {
DataByteArrayOutputStream dos = new DataByteArrayOutputStream();
DestinationFactory.dumpDestination(topic, dos);
Versionable versionable = new Versionable();
versionable.addVersioned(-1, new Versioned(-1, dos.getBuffer(), dos.getCount()), "com.swiftmq.jms.DestinationFactory");
ctx.jndiSwiftlet.registerJNDIObject(name, versionable);
} catch (IOException e) {
e.printStackTrace();
}
}
use of com.swiftmq.tools.versioning.Versionable 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.tools.versioning.Versionable in project swiftmq-ce by iitsoftware.
the class ClusterMetricPublisher method performTimeAction.
public void performTimeAction() {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/performTimeAction ...");
ClusteredQueueMetricCollection cmc = ctx.dispatchPolicyRegistry.getClusteredQueueMetricCollection();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/performTimeAction, cmc=" + cmc);
List list = cmc.getClusteredQueueMetrics();
if (list != null) {
for (int i = 0; i < list.size(); i++) {
ClusteredQueueMetric cm = (ClusteredQueueMetric) list.get(i);
List list2 = cm.getQueueMetrics();
if (list2 != null) {
for (int j = 0; j < list2.size(); j++) {
QueueMetric qm = (QueueMetric) list2.get(j);
AbstractQueue queue = ctx.queueManager.getQueueForInternalUse(qm.getQueueName());
if (queue != null) {
try {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/performTimeAction, queue=" + qm.getQueueName() + ", qm.hasReceiver()=" + qm.hasReceiver() + ", cm.isReceiverSomewhere()=" + cm.isReceiverSomewhere() + ", qm.isRedispatch()=" + qm.isRedispatch() + ", queue.getNumberQueueMessages()=" + queue.getNumberQueueMessages());
if (!qm.hasReceiver() && cm.isReceiverSomewhere() && qm.isRedispatch() && queue.getNumberQueueMessages() > 0)
ctx.redispatcherController.redispatch(qm.getQueueName(), cm.getClusteredQueueName());
} catch (QueueException e) {
}
}
}
}
}
}
try {
QueuePushTransaction transaction = sender.createTransaction();
Versionable versionable = new Versionable();
versionable.addVersioned(700, createVersioned(700, cmc), "com.swiftmq.impl.queue.standard.cluster.v700.MetricFactory");
BytesMessageImpl msg = createMessage(versionable);
transaction.putMessage(msg);
transaction.commit();
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/performTimeAction, exception=" + e);
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.queueManager.getName(), toString() + "/performTimeAction done");
}
Aggregations