Search in sources :

Example 1 with QueueListener

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

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

Example 3 with QueueListener

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

the class TestBlobMessages method testBlobMessages.

@Test
public void testBlobMessages() throws VCMessagingException {
    // creating one messageProducer session
    ArrayList<VCMessageSession> sessions = new ArrayList<VCMessageSession>();
    for (int i = 0; i < NUM_PRODUCERS; i++) {
        sessions.add(messagingService.createProducerSession());
    }
    AtomicInteger messagesToRead = new AtomicInteger(0);
    long startTime_MS = System.currentTimeMillis();
    final long TIMEOUT_MS = 1000 * 2;
    for (int i = 0; i < NUM_MESSAGES; i++) {
        for (int s = 0; s < NUM_PRODUCERS; s++) {
            VCMessageSession session = sessions.get(s);
            byte[] objectContent = new byte[40000 * (i + 1)];
            Arrays.fill(objectContent, (byte) 22);
            VCMessage message = session.createObjectMessage(objectContent);
            // VCMessage message = session.createObjectMessage(new byte[100000000]);
            session.sendQueueMessage(VCellTestQueue.JimQueue, message, false, 100000L);
            session.commit();
            int numMessages = messagesToRead.incrementAndGet();
            System.out.println("sent message:  messages unread = " + numMessages);
        }
    }
    // create N comsumers
    for (int i = 0; i < NUM_COMSUMERS; i++) {
        QueueListener listener = new QueueListener() {

            public void onQueueMessage(VCMessage vcMessage, VCMessageSession session) throws RollbackException {
                Object objectContent = vcMessage.getObjectContent();
                System.out.println("object content is '" + objectContent + "' of type " + objectContent.getClass().getName());
                String blobInfo = "<no blob>";
                if (vcMessage.propertyExists(VCMessageJms.BLOB_MESSAGE_MONGODB_OBJECTID)) {
                    String objectType = vcMessage.getStringProperty(VCMessageJms.BLOB_MESSAGE_OBJECT_TYPE);
                    int objectSize = vcMessage.getIntProperty(VCMessageJms.BLOB_MESSAGE_OBJECT_SIZE);
                    String objectid = vcMessage.getStringProperty(VCMessageJms.BLOB_MESSAGE_MONGODB_OBJECTID);
                    String persistenceType = vcMessage.getStringProperty(VCMessageJms.BLOB_MESSAGE_PERSISTENCE_TYPE);
                    blobInfo = "BLOB: persistenceType=" + persistenceType + ", object=" + objectType + ", size=" + objectSize + ", objectId=" + objectid;
                }
                System.out.println("<<<< onQueueMessage() >>>> timestampMS=" + vcMessage.getTimestampMS() + ", " + toString() + ",  elapsedTimeS=" + ((System.currentTimeMillis() - vcMessage.getTimestampMS()) / 1000.0) + ", Received: " + blobInfo);
                session.commit();
                int numMessages = messagesToRead.decrementAndGet();
                System.out.println("read message:  messages unread = " + numMessages);
            }
        };
        VCQueueConsumer queueConsumer = new VCQueueConsumer(VCellTestQueue.JimQueue, listener, null, "Queue[" + VCellTestQueue.JimQueue.getName() + "] ==== Consumer Thread " + i, 1);
        messagingService.addMessageConsumer(queueConsumer);
    }
    System.out.println("waiting for messages to be read");
    int numUnreadMessages = messagesToRead.get();
    while (numUnreadMessages > 0) {
        long elapsedTime = System.currentTimeMillis() - startTime_MS;
        System.out.println("elapsed time is " + elapsedTime + " ms, " + numUnreadMessages + " unread messages");
        if (elapsedTime > TIMEOUT_MS) {
            throw new RuntimeException("timeout before processing all messages, " + numUnreadMessages + " unread");
        }
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
        }
        numUnreadMessages = messagesToRead.get();
    }
    System.out.println("done");
}
Also used : QueueListener(cbit.vcell.message.VCQueueConsumer.QueueListener) VCMessageSession(cbit.vcell.message.VCMessageSession) ArrayList(java.util.ArrayList) VCQueueConsumer(cbit.vcell.message.VCQueueConsumer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) VCMessage(cbit.vcell.message.VCMessage) Test(org.junit.Test)

Example 4 with QueueListener

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

VCMessage (cbit.vcell.message.VCMessage)4 VCMessageSession (cbit.vcell.message.VCMessageSession)4 VCQueueConsumer (cbit.vcell.message.VCQueueConsumer)4 QueueListener (cbit.vcell.message.VCQueueConsumer.QueueListener)4 RollbackException (cbit.vcell.message.RollbackException)2 VCMessageSelector (cbit.vcell.message.VCMessageSelector)2 ArrayList (java.util.ArrayList)2 SimpleMessagingDelegate (cbit.vcell.message.SimpleMessagingDelegate)1 VCMessagingException (cbit.vcell.message.VCMessagingException)1 VCMessagingService (cbit.vcell.message.VCMessagingService)1 VCPooledQueueConsumer (cbit.vcell.message.VCPooledQueueConsumer)1 VCRpcMessageHandler (cbit.vcell.message.VCRpcMessageHandler)1 VCellQueue (cbit.vcell.message.VCellQueue)1 VCMessagingServiceEmbedded (cbit.vcell.message.jms.activeMQ.VCMessagingServiceEmbedded)1 SimulationTaskMessage (cbit.vcell.message.messages.SimulationTaskMessage)1 HtcProxy (cbit.vcell.message.server.htc.HtcProxy)1 SimulationTask (cbit.vcell.messaging.server.SimulationTask)1 HtcJobID (cbit.vcell.server.HtcJobID)1 SimulationService (cbit.vcell.server.SimulationService)1 SolverException (cbit.vcell.solver.SolverException)1