Search in sources :

Example 1 with SimpleMessagingDelegate

use of cbit.vcell.message.SimpleMessagingDelegate 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 SimpleMessagingDelegate

use of cbit.vcell.message.SimpleMessagingDelegate in project vcell by virtualcell.

the class TestBlobMessages method setUp.

@Before
public void setUp() throws Exception {
    System.getProperties().put("vcell.mongodb.host", "localhost");
    System.getProperties().put("vcell.mongodb.port", "27017");
    System.getProperties().put("vcell.mongodb.database", "test");
    mongoDbDriver = VCMongoDbDriver.getInstance();
    System.getProperties().put("vcell.jms.url", "failover:(tcp://localhost:61616)");
    System.getProperties().put("vcell.jms.user", "clientUser");
    System.getProperties().put("vcell.jms.pswdfile", "~/vcellkeys/jmspswd.txt");
    System.getProperties().put("vcell.jms.blobMessageUseMongo", "true");
    System.getProperties().put("vcell.jms.blobMessageMinSize", "100000");
    messagingService = new VCMessagingServiceActiveMQ();
    messagingService.setDelegate(new SimpleMessagingDelegate());
}
Also used : SimpleMessagingDelegate(cbit.vcell.message.SimpleMessagingDelegate) VCMessagingServiceActiveMQ(cbit.vcell.message.jms.activeMQ.VCMessagingServiceActiveMQ) Before(org.junit.Before)

Example 3 with SimpleMessagingDelegate

use of cbit.vcell.message.SimpleMessagingDelegate 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)

Example 4 with SimpleMessagingDelegate

use of cbit.vcell.message.SimpleMessagingDelegate in project vcell by virtualcell.

the class TestQueues method main.

public static void main(String[] args) throws Exception {
    try {
        PropertyLoader.loadProperties();
        VCMessagingService messagingService = new VCMessagingServiceEmbedded();
        messagingService.setDelegate(new SimpleMessagingDelegate());
        final Calculator calculator = new Calculator();
        // creating one messageProducer session
        ArrayList<VCMessageSession> sessions = new ArrayList<VCMessageSession>();
        for (int i = 0; i < NUM_PRODUCERS; i++) {
            sessions.add(messagingService.createProducerSession());
        }
        int sum = 0;
        for (int i = 0; i < NUM_MESSAGES; i++) {
            for (int s = 0; s < NUM_PRODUCERS; s++) {
                sum++;
                VCMessageSession session = sessions.get(s);
                VCMessage message = session.createTextMessage("message " + i + " from session " + s);
                session.sendQueueMessage(VCellTestQueue.JimQueue, message, false, 100000L);
                session.commit();
            }
            Thread.sleep(2000);
        }
        System.out.println("Correct sum is " + sum);
        Thread.sleep(30);
        // create N comsumers
        for (int i = 0; i < NUM_COMSUMERS; i++) {
            QueueListener listener = new QueueListener() {

                public void onQueueMessage(VCMessage vcMessage, VCMessageSession session) throws RollbackException {
                    // new Thread()
                    System.out.println("timestampMS=" + vcMessage.getTimestampMS() + ", " + toString() + ",  elapsedTimeS=" + ((System.currentTimeMillis() - vcMessage.getTimestampMS()) / 1000.0) + ", Received: " + vcMessage.getTextContent());
                    // int number = Integer.parseInt(vcMessage.getTextContent());
                    calculator.add(1);
                }
            };
            VCQueueConsumer queueConsumer = new VCQueueConsumer(VCellTestQueue.JimQueue, listener, null, "Queue[" + VCellTestQueue.JimQueue.getName() + "] ==== Consumer Thread " + i, 1);
            messagingService.addMessageConsumer(queueConsumer);
        }
        while (calculator.getSum() < sum) {
            System.out.println("calculator sum = " + calculator.getSum());
            Thread.sleep(1000);
        }
        System.out.println("calculator sum = " + calculator.getSum());
        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) QueueListener(cbit.vcell.message.VCQueueConsumer.QueueListener) VCMessage(cbit.vcell.message.VCMessage) VCMessageSession(cbit.vcell.message.VCMessageSession) VCMessagingServiceEmbedded(cbit.vcell.message.jms.activeMQ.VCMessagingServiceEmbedded) ArrayList(java.util.ArrayList) VCMessagingService(cbit.vcell.message.VCMessagingService) RollbackException(cbit.vcell.message.RollbackException) VCQueueConsumer(cbit.vcell.message.VCQueueConsumer)

Aggregations

SimpleMessagingDelegate (cbit.vcell.message.SimpleMessagingDelegate)4 VCMessageSession (cbit.vcell.message.VCMessageSession)3 VCMessagingService (cbit.vcell.message.VCMessagingService)3 VCQueueConsumer (cbit.vcell.message.VCQueueConsumer)3 VCMessagingInvocationTargetException (cbit.vcell.message.VCMessagingInvocationTargetException)2 VCRpcMessageHandler (cbit.vcell.message.VCRpcMessageHandler)2 VCRpcRequest (cbit.vcell.message.VCRpcRequest)2 VCMessagingServiceActiveMQ (cbit.vcell.message.jms.activeMQ.VCMessagingServiceActiveMQ)2 ArrayList (java.util.ArrayList)2 KeyValue (org.vcell.util.document.KeyValue)2 User (org.vcell.util.document.User)2 RollbackException (cbit.vcell.message.RollbackException)1 VCMessage (cbit.vcell.message.VCMessage)1 VCMessagingException (cbit.vcell.message.VCMessagingException)1 VCPooledQueueConsumer (cbit.vcell.message.VCPooledQueueConsumer)1 QueueListener (cbit.vcell.message.VCQueueConsumer.QueueListener)1 VCMessagingServiceEmbedded (cbit.vcell.message.jms.activeMQ.VCMessagingServiceEmbedded)1 Before (org.junit.Before)1