use of cbit.vcell.message.VCMessagingInvocationTargetException in project vcell by virtualcell.
the class TestBlobRpcMessages method main.
public static void main(String[] args) throws Exception {
try {
PropertyLoader.loadProperties();
// System.getProperties().setProperty(PropertyLoader.jmsURL,"tcp://nrcamdev5.cam.uchc.edu:61616");
VCMessagingService messagingService = new VCMessagingServiceActiveMQ();
messagingService.setDelegate(new SimpleMessagingDelegate());
// reading message and computing sum
// create N comsumers
MyRpcServer myRpcServer = new MyRpcServer();
for (int i = 0; i < NUM_COMSUMERS; i++) {
VCRpcMessageHandler rpcMessageHandler = new VCRpcMessageHandler(myRpcServer, VCellTestQueue.JimQueue);
VCQueueConsumer rpcConsumer = new VCQueueConsumer(VCellTestQueue.JimQueue, rpcMessageHandler, null, "Queue[" + VCellTestQueue.JimQueue.getName() + "] ==== RPC Consumer Thread " + i, 1);
messagingService.addMessageConsumer(rpcConsumer);
}
// creating one messageProducer session
ArrayList<VCMessageSession> sessions = new ArrayList<VCMessageSession>();
for (int i = 0; i < NUM_PRODUCERS; i++) {
sessions.add(messagingService.createProducerSession());
}
for (int i = 0; i < NUM_MESSAGES; i++) {
for (int s = 0; s < NUM_PRODUCERS; s++) {
VCMessageSession session = sessions.get(s);
try {
//
// create simple RPC request for service "Testing_Service"
//
User user = new User("schaff", new KeyValue("17"));
byte[] array1 = new byte[20000000];
byte[] array2 = new byte[20000000];
VCRpcRequest rpcRequest = new VCRpcRequest(user, RpcServiceType.TESTING_SERVICE, "concat", new Object[] { array1, array2 });
//
// send request and block for response (or timeout).
// RPC invocations don't need commits.
//
Object returnValue = session.sendRpcMessage(VCellTestQueue.JimQueue, rpcRequest, true, 20000, null, null, null);
//
if (returnValue instanceof byte[]) {
System.out.println("concat(byte[" + array1.length + "], byte[" + array2.length + "]) ===> byte[" + (((byte[]) returnValue).length) + "]");
} else {
System.out.println("unexpected return value of " + returnValue);
}
} catch (VCMessagingInvocationTargetException e) {
e.printStackTrace(System.out);
System.out.println("the rpc service threw an exception");
e.getTargetException().printStackTrace(System.out);
}
}
}
System.out.println("main program calling closeAll()");
messagingService.close();
System.out.println("main program exiting");
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
use of cbit.vcell.message.VCMessagingInvocationTargetException in project vcell by virtualcell.
the class MessageProducerSessionJms method sendRpcMessage.
// public MessageProducerSessionJms(Session session, VCMessagingServiceJms vcMessagingServiceJms) {
// System.out.println("-----\nmpjms MessageProducerSessionJms(Session session, VCMessagingServiceJms vcMessagingServiceJms)\ntmpQCnt="+(++tmpQCnt)+"----------");
// Thread.dumpStack();
// this.vcMessagingServiceJms = vcMessagingServiceJms;
// this.session = session;
// this.bIndependent = false;
// }
public /*synchronized*/
Object sendRpcMessage(VCellQueue queue, VCRpcRequest vcRpcRequest, boolean returnRequired, long timeoutMS, String[] specialProperties, Object[] specialValues, UserLoginInfo userLoginInfo) throws VCMessagingException, VCMessagingInvocationTargetException {
MessageProducer messageProducer = null;
MessageProducerSessionJms tempMessageProducerSessionJms = null;
try {
if (!bIndependent) {
throw new VCMessagingException("cannot invoke RpcMessage from within another transaction, create an independent message producer");
}
Destination destination = session.createQueue(queue.getName());
messageProducer = session.createProducer(destination);
//
// use MessageProducerSessionJms to create the rpcRequest message (allows "Blob" messages to be formed as needed).
//
tempMessageProducerSessionJms = new MessageProducerSessionJms(vcMessagingServiceJms);
// tempMessageProducerSessionJms = new MessageProducerSessionJms(session,vcMessagingServiceJms);
VCMessageJms vcRpcRequestMessage = (VCMessageJms) tempMessageProducerSessionJms.createObjectMessage(vcRpcRequest);
Message rpcMessage = vcRpcRequestMessage.getJmsMessage();
rpcMessage.setStringProperty(VCMessagingConstants.MESSAGE_TYPE_PROPERTY, VCMessagingConstants.MESSAGE_TYPE_RPC_SERVICE_VALUE);
rpcMessage.setStringProperty(VCMessagingConstants.SERVICE_TYPE_PROPERTY, vcRpcRequest.getRequestedServiceType().getName());
// rpcMessage.setJMSExpiration(5000);
if (specialValues != null) {
for (int i = 0; i < specialValues.length; i++) {
rpcMessage.setObjectProperty(specialProperties[i], specialValues[i]);
}
}
if (returnRequired) {
rpcMessage.setJMSReplyTo(commonTemporaryQueue);
messageProducer.setTimeToLive(timeoutMS);
messageProducer.send(rpcMessage);
session.commit();
vcMessagingServiceJms.getDelegate().onRpcRequestSent(vcRpcRequest, userLoginInfo, vcRpcRequestMessage);
System.out.println("MessageProducerSessionJms.sendRpcMessage(): looking for reply message with correlationID = " + rpcMessage.getJMSMessageID());
String filter = VCMessagingConstants.JMSCORRELATIONID_PROPERTY + "='" + rpcMessage.getJMSMessageID() + "'";
MessageConsumer replyConsumer = null;
Message replyMessage = null;
try {
replyConsumer = session.createConsumer(commonTemporaryQueue, filter);
replyMessage = replyConsumer.receive(timeoutMS);
} finally {
replyConsumer.close();
}
if (replyMessage == null) {
System.out.println("Request timed out");
}
if (replyMessage == null || !(replyMessage instanceof ObjectMessage)) {
throw new JMSException("Server is temporarily not responding, please try again. If problem persists, contact VCell_Support@uchc.edu." + " (server " + vcRpcRequest.getRequestedServiceType().getName() + ", method " + vcRpcRequest.getMethodName() + ")");
} else {
VCMessageJms vcReplyMessage = new VCMessageJms(replyMessage, vcMessagingServiceJms.getDelegate());
vcReplyMessage.loadBlobFile();
Object returnValue = vcReplyMessage.getObjectContent();
vcReplyMessage.removeBlobFile();
if (returnValue instanceof Exception) {
throw new VCMessagingInvocationTargetException((Exception) returnValue);
} else {
return returnValue;
}
}
} else {
rpcMessage.setJMSReplyTo(commonTemporaryQueue);
messageProducer.setTimeToLive(timeoutMS);
messageProducer.send(rpcMessage);
commit();
vcMessagingServiceJms.getDelegate().onRpcRequestSent(vcRpcRequest, userLoginInfo, vcRpcRequestMessage);
return null;
}
} catch (JMSException e) {
onException(e);
throw new VCMessagingException(e.getMessage(), e);
} finally {
try {
if (tempMessageProducerSessionJms != null) {
tempMessageProducerSessionJms.commit();
tempMessageProducerSessionJms.close();
}
if (messageProducer != null) {
messageProducer.close();
}
// try{Thread.sleep(10000);}catch(Exception e){e.printStackTrace();}
} catch (JMSException e) {
onException(e);
}
}
}
use of cbit.vcell.message.VCMessagingInvocationTargetException in project vcell by virtualcell.
the class TestRPC method main.
public static void main(String[] args) throws Exception {
try {
PropertyLoader.loadProperties();
VCMessagingService messagingService = VCellServiceHelper.getInstance().loadService(VCMessagingService.class);
messagingService.setDelegate(new SimpleMessagingDelegate());
// reading message and computing sum
// create N comsumers
MyRpcServer myRpcServer = new MyRpcServer();
VCRpcMessageHandler rpcMessageHandler = new VCRpcMessageHandler(myRpcServer, VCellTestQueue.JimQueue);
VCPooledQueueConsumer pooledQueueConsumer = new VCPooledQueueConsumer(rpcMessageHandler, NUM_THREADS, messagingService.createProducerSession());
pooledQueueConsumer.initThreadPool();
VCQueueConsumer rpcConsumer = new VCQueueConsumer(VCellTestQueue.JimQueue, pooledQueueConsumer, null, "Queue[" + VCellTestQueue.JimQueue.getName() + "] ==== RPC Consumer Master Thread ", 1000);
// VCRpcMessageHandler rpcMessageHandler = new VCRpcMessageHandler(myRpcServer, VCellQueue.JimQueue, log);
// VCQueueConsumer rpcConsumer = new VCQueueConsumer(VCellQueue.JimQueue, rpcMessageHandler, null, "Queue["+VCellQueue.JimQueue.getName()+"] ==== RPC Consumer Master Thread ", 1000);
messagingService.addMessageConsumer(rpcConsumer);
for (int i = 0; i < NUM_MESSAGES; i++) {
// creating one messageProducer session
final VCMessageSession messageSession = messagingService.createProducerSession();
class MyTask implements Runnable {
int msgNum;
MyTask(int msgNum) {
this.msgNum = msgNum;
}
public void run() {
try {
//
// create simple RPC request for service "Testing_Service"
//
User user = new User("schaff", new KeyValue("17"));
Integer n1 = new Integer(msgNum);
Integer n2 = new Integer(msgNum + 1);
VCRpcRequest rpcRequest = new VCRpcRequest(user, RpcServiceType.TESTING_SERVICE, "add", new Object[] { n1, n2 });
//
// send request and block for response (or timeout).
// RPC invocations don't need commits.
//
Object returnValue = messageSession.sendRpcMessage(VCellTestQueue.JimQueue, rpcRequest, true, 20000, null, null, null);
//
if (returnValue instanceof Integer) {
System.out.println("add(" + n1 + "," + n2 + ") ===> " + returnValue);
} else {
System.out.println("unexpected return value of " + returnValue);
}
} catch (VCMessagingInvocationTargetException e) {
e.printStackTrace(System.out);
System.out.println("the rpc service threw an exception");
e.getTargetException().printStackTrace(System.out);
} catch (VCMessagingException e) {
e.printStackTrace();
}
}
}
;
new Thread(new MyTask(i)).start();
}
Thread.sleep(2000);
System.out.println("main program calling closeAll()");
pooledQueueConsumer.shutdownAndAwaitTermination();
messagingService.close();
System.out.println("main program exiting");
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
Aggregations