Search in sources :

Example 1 with VCPooledQueueConsumer

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

use of cbit.vcell.message.VCPooledQueueConsumer 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_int.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_int.addMessageConsumer(rpcConsumer);
    this.databaseCleanupThread = new DatabaseCleanupThread(databaseServerImpl);
    this.databaseCleanupThread.start();
}
Also used : VCPooledQueueConsumer(cbit.vcell.message.VCPooledQueueConsumer) VCRpcMessageHandler(cbit.vcell.message.VCRpcMessageHandler) VCQueueConsumer(cbit.vcell.message.VCQueueConsumer)

Example 3 with VCPooledQueueConsumer

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

the class HtcSimulationWorker method initQueueConsumer.

// ------------------------------Job Monitor Section END
private void initQueueConsumer() {
    startJobMonitor();
    this.messageProducer_sim = vcMessagingService_sim.createProducerSession();
    this.messageProducer_int = vcMessagingService_int.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);
                addMonitorJob(pbsId.getJobNumber(), simTask, false);
                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 (messageProducer_sim) {
                    WorkerEventMessage.sendAccepted(messageProducer_sim, HtcSimulationWorker.class.getName(), simTask, ManageUtils.getHostName(), pbsId);
                    WorkerEventMessage.sendStarting(messageProducer_sim, HtcSimulationWorker.class.getName(), simTask, ManageUtils.getHostName(), SimulationMessage.MESSAGE_WORKEREVENT_STARTING);
                    WorkerEventMessage.sendProgress(messageProducer_sim, HtcSimulationWorker.class.getName(), simTask, ManageUtils.getHostName(), 0, 0, SimulationMessage.MESSAGE_JOB_RUNNING_UNKNOWN);
                }
                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 (messageProducer_sim) {
                            WorkerEventMessage.sendFailed(messageProducer_sim, 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_int = new VCPooledQueueConsumer(queueListener, numHtcworkerThreads, messageProducer_int);
    this.pooledQueueConsumer_int.initThreadPool();
    VCellQueue queue = VCellQueue.SimJobQueue;
    VCMessageSelector selector = vcMessagingService_int.createSelector(getJobSelector());
    String threadName = "SimJob Queue Consumer";
    queueConsumer = new VCQueueConsumer(queue, pooledQueueConsumer_int, selector, threadName, MessageConstants.PREFETCH_LIMIT_SIM_JOB_HTC);
    vcMessagingService_int.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) ExecutableException(org.vcell.util.exe.ExecutableException) XmlParseException(cbit.vcell.xml.XmlParseException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) UnknownHostException(java.net.UnknownHostException) VCMessagingException(cbit.vcell.message.VCMessagingException) FileNotFoundException(java.io.FileNotFoundException) RollbackException(cbit.vcell.message.RollbackException) SolverException(cbit.vcell.solver.SolverException) 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 4 with VCPooledQueueConsumer

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

the class SimDataServer method init.

public void init() throws Exception {
    String dataRequestFilter = "(" + VCMessagingConstants.MESSAGE_TYPE_PROPERTY + "='" + VCMessagingConstants.MESSAGE_TYPE_RPC_SERVICE_VALUE + "') " + " AND (" + VCMessagingConstants.SERVICE_TYPE_PROPERTY + "='" + ServiceType.DATA.getName() + "')";
    String exportOnlyFilter = "(" + ServiceType.DATAEXPORT.getName() + " is NOT NULL)";
    String dataOnlyFilter = "(" + ServiceType.DATAEXPORT.getName() + " is NULL)";
    VCMessageSelector selector;
    ServiceType serviceType = serviceInstanceStatus.getType();
    int numThreads;
    switch(simDataServiceType) {
        case CombinedData:
            {
                selector = vcMessagingService_int.createSelector(dataRequestFilter);
                int exportThreads = Integer.parseInt(PropertyLoader.getProperty(PropertyLoader.exportdataThreadsProperty, "3"));
                int simdataThreads = Integer.parseInt(PropertyLoader.getProperty(PropertyLoader.simdataThreadsProperty, "5"));
                numThreads = exportThreads + simdataThreads;
                break;
            }
        case ExportDataOnly:
            {
                selector = vcMessagingService_int.createSelector(dataRequestFilter + " AND " + exportOnlyFilter);
                numThreads = Integer.parseInt(PropertyLoader.getProperty(PropertyLoader.exportdataThreadsProperty, "3"));
                break;
            }
        case SimDataOnly:
            {
                selector = vcMessagingService_int.createSelector(dataRequestFilter + " AND " + dataOnlyFilter);
                numThreads = Integer.parseInt(PropertyLoader.getProperty(PropertyLoader.simdataThreadsProperty, "5"));
                break;
            }
        default:
            {
                throw new RuntimeException("expecting either Service type of " + ServiceType.DATA + " or " + ServiceType.DATAEXPORT);
            }
    }
    this.sharedProducerSession = vcMessagingService_int.createProducerSession();
    rpcMessageHandler = new VCRpcMessageHandler(dataServerImpl, VCellQueue.DataRequestQueue);
    this.pooledQueueConsumer = new VCPooledQueueConsumer(rpcMessageHandler, numThreads, sharedProducerSession);
    this.pooledQueueConsumer.initThreadPool();
    rpcConsumer = new VCQueueConsumer(VCellQueue.DataRequestQueue, pooledQueueConsumer, selector, serviceType.getName() + " RPC Server Thread", MessageConstants.PREFETCH_LIMIT_DATA_REQUEST);
    vcMessagingService_int.addMessageConsumer(rpcConsumer);
}
Also used : VCMessageSelector(cbit.vcell.message.VCMessageSelector) ServiceType(cbit.vcell.message.server.bootstrap.ServiceType) VCPooledQueueConsumer(cbit.vcell.message.VCPooledQueueConsumer) VCRpcMessageHandler(cbit.vcell.message.VCRpcMessageHandler) VCQueueConsumer(cbit.vcell.message.VCQueueConsumer)

Example 5 with VCPooledQueueConsumer

use of cbit.vcell.message.VCPooledQueueConsumer 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);
        String jmshost = PropertyLoader.getRequiredProperty(PropertyLoader.jmsIntHostInternal);
        int jmsport = Integer.parseInt(PropertyLoader.getRequiredProperty(PropertyLoader.jmsIntPortInternal));
        messagingService.setConfiguration(new SimpleMessagingDelegate(), jmshost, jmsport);
        // 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

VCPooledQueueConsumer (cbit.vcell.message.VCPooledQueueConsumer)5 VCQueueConsumer (cbit.vcell.message.VCQueueConsumer)5 VCMessageSelector (cbit.vcell.message.VCMessageSelector)3 VCMessageSession (cbit.vcell.message.VCMessageSession)3 VCMessagingException (cbit.vcell.message.VCMessagingException)3 VCRpcMessageHandler (cbit.vcell.message.VCRpcMessageHandler)3 RollbackException (cbit.vcell.message.RollbackException)2 VCMessage (cbit.vcell.message.VCMessage)2 QueueListener (cbit.vcell.message.VCQueueConsumer.QueueListener)2 VCellQueue (cbit.vcell.message.VCellQueue)2 SimulationTaskMessage (cbit.vcell.message.messages.SimulationTaskMessage)2 HtcProxy (cbit.vcell.message.server.htc.HtcProxy)2 SimulationTask (cbit.vcell.messaging.server.SimulationTask)2 HtcJobID (cbit.vcell.server.HtcJobID)2 SolverException (cbit.vcell.solver.SolverException)2 XmlParseException (cbit.vcell.xml.XmlParseException)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 UnknownHostException (java.net.UnknownHostException)2 DataAccessException (org.vcell.util.DataAccessException)2