Search in sources :

Example 1 with VCQueueConsumer

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

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

the class ConsumerContextJms method run.

public void run() {
    bProcessing = true;
    System.out.println(toString() + " consumer thread starting.");
    while (bProcessing) {
        MessageProducerSessionJms temporaryMessageProducerSession = null;
        try {
            Message jmsMessage = jmsMessageConsumer.receive(CONSUMER_POLLING_INTERVAL_MS);
            if (jmsMessage != null) {
                // System.out.println(toString()+"===============message received within "+CONSUMER_POLLING_INTERVAL_MS+" ms");
                if (vcConsumer instanceof VCQueueConsumer) {
                    VCQueueConsumer queueConsumer = (VCQueueConsumer) vcConsumer;
                    VCMessageJms vcMessage = new VCMessageJms(jmsMessage, vcMessagingServiceJms.getDelegate());
                    vcMessage.loadBlobFile();
                    vcMessagingServiceJms.getDelegate().onMessageReceived(vcMessage, vcConsumer.getVCDestination());
                    temporaryMessageProducerSession = new MessageProducerSessionJms(vcMessagingServiceJms);
                    queueConsumer.getQueueListener().onQueueMessage(vcMessage, temporaryMessageProducerSession);
                    temporaryMessageProducerSession.commit();
                    jmsSession.commit();
                    vcMessage.removeBlobFile();
                } else if (vcConsumer instanceof VCTopicConsumer) {
                    VCTopicConsumer topicConsumer = (VCTopicConsumer) vcConsumer;
                    VCMessageJms vcMessage = new VCMessageJms(jmsMessage, vcMessagingServiceJms.getDelegate());
                    vcMessage.loadBlobFile();
                    vcMessagingServiceJms.getDelegate().onMessageReceived(vcMessage, vcConsumer.getVCDestination());
                    temporaryMessageProducerSession = new MessageProducerSessionJms(vcMessagingServiceJms);
                    topicConsumer.getTopicListener().onTopicMessage(vcMessage, temporaryMessageProducerSession);
                    temporaryMessageProducerSession.commit();
                    jmsSession.commit();
                // 
                // if we knew this was the only subscriber for this topic, then remove file immediately.
                // since we don't know for sure, don't remove the file here.
                // instead, we need to periodically remove old Blob files (maybe daily)
                // 
                // vcMessage.removeBlobFile();
                } else {
                    throw new RuntimeException("unexpected VCConsumer type " + vcConsumer);
                }
            } else {
            // System.out.println(toString()+"no message received within "+CONSUMER_POLLING_INTERVAL_MS+" ms");
            }
        } catch (JMSException e) {
            onException(e);
        } catch (RollbackException e) {
            log.exception(e);
            try {
                jmsSession.rollback();
            } catch (JMSException e1) {
                onException(e1);
            }
        } catch (Exception e) {
            log.exception(e);
        } finally {
            if (temporaryMessageProducerSession != null) {
                temporaryMessageProducerSession.close();
            }
        }
    }
    System.out.println(toString() + " consumer thread exiting.");
}
Also used : Message(javax.jms.Message) VCTopicConsumer(cbit.vcell.message.VCTopicConsumer) JMSException(javax.jms.JMSException) RollbackException(cbit.vcell.message.RollbackException) JMSException(javax.jms.JMSException) RollbackException(cbit.vcell.message.RollbackException) VCMessagingException(cbit.vcell.message.VCMessagingException) VCQueueConsumer(cbit.vcell.message.VCQueueConsumer)

Example 3 with VCQueueConsumer

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

the class DatabaseServer method init.

public void init() throws Exception {
    int numDatabaseThreads = Integer.parseInt(PropertyLoader.getProperty(PropertyLoader.databaseThreadsProperty, "5"));
    this.sharedProducerSession = vcMessagingService.createProducerSession();
    rpcMessageHandler = new VCRpcMessageHandler(databaseServerImpl, VCellQueue.DbRequestQueue);
    this.pooledQueueConsumer = new VCPooledQueueConsumer(rpcMessageHandler, numDatabaseThreads, sharedProducerSession);
    this.pooledQueueConsumer.initThreadPool();
    rpcConsumer = new VCQueueConsumer(VCellQueue.DbRequestQueue, this.pooledQueueConsumer, null, "Database RPC Server Thread", MessageConstants.PREFETCH_LIMIT_DB_REQUEST);
    vcMessagingService.addMessageConsumer(rpcConsumer);
    initControlTopicListener();
}
Also used : VCPooledQueueConsumer(cbit.vcell.message.VCPooledQueueConsumer) VCRpcMessageHandler(cbit.vcell.message.VCRpcMessageHandler) VCQueueConsumer(cbit.vcell.message.VCQueueConsumer)

Example 4 with VCQueueConsumer

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

the class SimulationDispatcher method init.

public void init() {
    // 
    // set up consumer for WorkerEvent messages
    // 
    QueueListener workerEventListener = new QueueListener() {

        public void onQueueMessage(VCMessage vcMessage, VCMessageSession session) throws RollbackException {
            onWorkerEventMessage(vcMessage, session);
        }
    };
    VCMessageSelector workerEventSelector = null;
    String threadName = "Worker Event Consumer";
    workerEventConsumer = new VCQueueConsumer(VCellQueue.WorkerEventQueue, workerEventListener, workerEventSelector, threadName, MessageConstants.PREFETCH_LIMIT_WORKER_EVENT);
    vcMessagingService.addMessageConsumer(workerEventConsumer);
    // 
    // set up consumer for Simulation Request (non-blocking RPC) messages
    // 
    SimulationService simServiceImpl = new SimulationServiceImpl();
    VCMessageSelector simRequestSelector = null;
    threadName = "Sim Request Consumer";
    this.rpcMessageHandler = new VCRpcMessageHandler(simServiceImpl, VCellQueue.SimReqQueue);
    simRequestConsumer = new VCQueueConsumer(VCellQueue.SimReqQueue, rpcMessageHandler, simRequestSelector, threadName, MessageConstants.PREFETCH_LIMIT_SIM_REQUEST);
    vcMessagingService.addMessageConsumer(simRequestConsumer);
    this.dispatcherQueueSession = vcMessagingService.createProducerSession();
    this.dispatchThread = new DispatchThread();
    this.dispatchThread.start();
    initControlTopicListener();
    this.simMonitorThreadSession = vcMessagingService.createProducerSession();
    this.simMonitor = new SimulationMonitor();
}
Also used : QueueListener(cbit.vcell.message.VCQueueConsumer.QueueListener) VCMessageSelector(cbit.vcell.message.VCMessageSelector) VCMessage(cbit.vcell.message.VCMessage) VCMessageSession(cbit.vcell.message.VCMessageSession) VCRpcMessageHandler(cbit.vcell.message.VCRpcMessageHandler) SimulationService(cbit.vcell.server.SimulationService) VCQueueConsumer(cbit.vcell.message.VCQueueConsumer)

Example 5 with VCQueueConsumer

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

the class HtcSimulationWorker method initQueueConsumer.

private void initQueueConsumer() {
    this.sharedMessageProducer = vcMessagingService.createProducerSession();
    QueueListener queueListener = new QueueListener() {

        @Override
        public void onQueueMessage(VCMessage vcMessage, VCMessageSession session) throws RollbackException {
            SimulationTask simTask = null;
            try {
                SimulationTaskMessage simTaskMessage = new SimulationTaskMessage(vcMessage);
                simTask = simTaskMessage.getSimulationTask();
                if (lg.isInfoEnabled()) {
                    lg.info("onQueueMessage() run simulation key=" + simTask.getSimKey() + ", job=" + simTask.getSimulationJobID() + ", task=" + simTask.getTaskID() + " for user " + simTask.getUserName());
                }
                PostProcessingChores rd = choresFor(simTask);
                HtcProxy clonedHtcProxy = htcProxy.cloneThreadsafe();
                if (lg.isInfoEnabled()) {
                    lg.info("onQueueMessage() submit job: simulation key=" + simTask.getSimKey() + ", job=" + simTask.getSimulationJobID() + ", task=" + simTask.getTaskID() + " for user " + simTask.getUserName());
                }
                HtcJobID pbsId = submit2PBS(simTask, clonedHtcProxy, rd);
                if (lg.isInfoEnabled()) {
                    lg.info("onQueueMessage() sending 'accepted' message for job: simulation key=" + simTask.getSimKey() + ", job=" + simTask.getSimulationJobID() + ", task=" + simTask.getTaskID() + " for user " + simTask.getUserName());
                }
                synchronized (sharedMessageProducer) {
                    WorkerEventMessage.sendAccepted(sharedMessageProducer, HtcSimulationWorker.class.getName(), simTask, ManageUtils.getHostName(), pbsId);
                }
                if (lg.isInfoEnabled()) {
                    lg.info("onQueueMessage() sent 'accepted' message for job: simulation key=" + simTask.getSimKey() + ", job=" + simTask.getSimulationJobID() + ", task=" + simTask.getTaskID() + " for user " + simTask.getUserName());
                }
            } catch (Exception e) {
                lg.error(e.getMessage(), e);
                if (simTask != null) {
                    try {
                        lg.error("failed to process simTask request: " + e.getMessage() + " for simulation key=" + simTask.getSimKey() + ", job=" + simTask.getSimulationJobID() + ", task=" + simTask.getTaskID() + " for user " + simTask.getUserName(), e);
                        synchronized (sharedMessageProducer) {
                            WorkerEventMessage.sendFailed(sharedMessageProducer, HtcSimulationWorker.class.getName(), simTask, ManageUtils.getHostName(), SimulationMessage.jobFailed(e.getMessage()));
                        }
                        lg.error("sent 'failed' message for simulation key=" + simTask.getSimKey() + ", job=" + simTask.getSimulationJobID() + ", task=" + simTask.getTaskID() + " for user " + simTask.getUserName(), e);
                    } catch (VCMessagingException e1) {
                        lg.error(e1.getMessage(), e);
                    }
                } else {
                    lg.error("failed to process simTask request: " + e.getMessage(), e);
                }
            }
        }
    };
    int numHtcworkerThreads = Integer.parseInt(PropertyLoader.getProperty(PropertyLoader.htcworkerThreadsProperty, "5"));
    this.pooledQueueConsumer = new VCPooledQueueConsumer(queueListener, numHtcworkerThreads, sharedMessageProducer);
    this.pooledQueueConsumer.initThreadPool();
    VCellQueue queue = VCellQueue.SimJobQueue;
    VCMessageSelector selector = vcMessagingService.createSelector(getJobSelector());
    String threadName = "SimJob Queue Consumer";
    queueConsumer = new VCQueueConsumer(queue, pooledQueueConsumer, selector, threadName, MessageConstants.PREFETCH_LIMIT_SIM_JOB_HTC);
    vcMessagingService.addMessageConsumer(queueConsumer);
}
Also used : QueueListener(cbit.vcell.message.VCQueueConsumer.QueueListener) SimulationTask(cbit.vcell.messaging.server.SimulationTask) HtcProxy(cbit.vcell.message.server.htc.HtcProxy) VCMessageSelector(cbit.vcell.message.VCMessageSelector) VCMessageSession(cbit.vcell.message.VCMessageSession) VCPooledQueueConsumer(cbit.vcell.message.VCPooledQueueConsumer) VCMessagingException(cbit.vcell.message.VCMessagingException) FileNotFoundException(java.io.FileNotFoundException) ConfigurationException(org.vcell.util.ConfigurationException) ExecutableException(org.vcell.util.exe.ExecutableException) RollbackException(cbit.vcell.message.RollbackException) XmlParseException(cbit.vcell.xml.XmlParseException) SolverException(cbit.vcell.solver.SolverException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) UnknownHostException(java.net.UnknownHostException) VCQueueConsumer(cbit.vcell.message.VCQueueConsumer) VCMessage(cbit.vcell.message.VCMessage) VCMessagingException(cbit.vcell.message.VCMessagingException) HtcJobID(cbit.vcell.server.HtcJobID) VCellQueue(cbit.vcell.message.VCellQueue) SimulationTaskMessage(cbit.vcell.message.messages.SimulationTaskMessage)

Aggregations

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