Search in sources :

Example 1 with VCMessagingInvocationTargetException

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);
    }
}
Also used : SimpleMessagingDelegate(cbit.vcell.message.SimpleMessagingDelegate) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) VCMessagingInvocationTargetException(cbit.vcell.message.VCMessagingInvocationTargetException) VCMessageSession(cbit.vcell.message.VCMessageSession) ArrayList(java.util.ArrayList) VCMessagingService(cbit.vcell.message.VCMessagingService) VCRpcRequest(cbit.vcell.message.VCRpcRequest) VCMessagingInvocationTargetException(cbit.vcell.message.VCMessagingInvocationTargetException) VCQueueConsumer(cbit.vcell.message.VCQueueConsumer) VCMessagingServiceActiveMQ(cbit.vcell.message.jms.activeMQ.VCMessagingServiceActiveMQ) VCRpcMessageHandler(cbit.vcell.message.VCRpcMessageHandler)

Example 2 with VCMessagingInvocationTargetException

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);
        }
    }
}
Also used : Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) VCMessagingInvocationTargetException(cbit.vcell.message.VCMessagingInvocationTargetException) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) VCMessage(cbit.vcell.message.VCMessage) JMSException(javax.jms.JMSException) VCMessagingException(cbit.vcell.message.VCMessagingException) VCMessagingInvocationTargetException(cbit.vcell.message.VCMessagingInvocationTargetException) JMSException(javax.jms.JMSException) ObjectMessage(javax.jms.ObjectMessage) MessageProducer(javax.jms.MessageProducer) VCMessagingException(cbit.vcell.message.VCMessagingException)

Example 3 with VCMessagingInvocationTargetException

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);
    }
}
Also used : SimpleMessagingDelegate(cbit.vcell.message.SimpleMessagingDelegate) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) VCMessagingInvocationTargetException(cbit.vcell.message.VCMessagingInvocationTargetException) VCMessageSession(cbit.vcell.message.VCMessageSession) VCPooledQueueConsumer(cbit.vcell.message.VCPooledQueueConsumer) VCMessagingService(cbit.vcell.message.VCMessagingService) VCRpcRequest(cbit.vcell.message.VCRpcRequest) VCMessagingException(cbit.vcell.message.VCMessagingException) VCMessagingInvocationTargetException(cbit.vcell.message.VCMessagingInvocationTargetException) VCQueueConsumer(cbit.vcell.message.VCQueueConsumer) VCMessagingException(cbit.vcell.message.VCMessagingException) VCRpcMessageHandler(cbit.vcell.message.VCRpcMessageHandler)

Aggregations

VCMessagingInvocationTargetException (cbit.vcell.message.VCMessagingInvocationTargetException)3 SimpleMessagingDelegate (cbit.vcell.message.SimpleMessagingDelegate)2 VCMessageSession (cbit.vcell.message.VCMessageSession)2 VCMessagingException (cbit.vcell.message.VCMessagingException)2 VCMessagingService (cbit.vcell.message.VCMessagingService)2 VCQueueConsumer (cbit.vcell.message.VCQueueConsumer)2 VCRpcMessageHandler (cbit.vcell.message.VCRpcMessageHandler)2 VCRpcRequest (cbit.vcell.message.VCRpcRequest)2 KeyValue (org.vcell.util.document.KeyValue)2 User (org.vcell.util.document.User)2 VCMessage (cbit.vcell.message.VCMessage)1 VCPooledQueueConsumer (cbit.vcell.message.VCPooledQueueConsumer)1 VCMessagingServiceActiveMQ (cbit.vcell.message.jms.activeMQ.VCMessagingServiceActiveMQ)1 ArrayList (java.util.ArrayList)1 Destination (javax.jms.Destination)1 JMSException (javax.jms.JMSException)1 Message (javax.jms.Message)1 MessageConsumer (javax.jms.MessageConsumer)1 MessageProducer (javax.jms.MessageProducer)1 ObjectMessage (javax.jms.ObjectMessage)1