Search in sources :

Example 1 with VCellQueue

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

the class VCMessagingServiceActiveMQ method createConsumer.

@Override
public MessageConsumer createConsumer(Session jmsSession, VCDestination vcDestination, VCMessageSelector vcSelector, int prefetchLimit) throws JMSException {
    Destination jmsDestination;
    MessageConsumer jmsMessageConsumer;
    if (vcDestination instanceof VCellQueue) {
        jmsDestination = jmsSession.createQueue(vcDestination.getName() + "?consumer.prefetchSize=" + prefetchLimit);
    } else {
        jmsDestination = jmsSession.createTopic(vcDestination.getName() + "?consumer.prefetchSize=" + prefetchLimit);
    }
    if (vcSelector == null) {
        jmsMessageConsumer = jmsSession.createConsumer(jmsDestination);
    } else {
        jmsMessageConsumer = jmsSession.createConsumer(jmsDestination, vcSelector.getSelectionString());
    }
    return jmsMessageConsumer;
}
Also used : VCDestination(cbit.vcell.message.VCDestination) Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) VCellQueue(cbit.vcell.message.VCellQueue)

Example 2 with VCellQueue

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

the class VCMessagingServiceEmbedded method createConsumer.

@Override
public MessageConsumer createConsumer(Session jmsSession, VCDestination vcDestination, VCMessageSelector vcSelector, int prefetchLimit) throws JMSException, VCMessagingException {
    if (!initialized) {
        initialized = true;
        init();
    }
    Destination jmsDestination;
    MessageConsumer jmsMessageConsumer;
    if (vcDestination instanceof VCellQueue) {
        jmsDestination = jmsSession.createQueue(vcDestination.getName() + "?consumer.prefetchSize=" + prefetchLimit);
    } else {
        jmsDestination = jmsSession.createTopic(vcDestination.getName() + "?consumer.prefetchSize=" + prefetchLimit);
    }
    if (vcSelector == null) {
        jmsMessageConsumer = jmsSession.createConsumer(jmsDestination);
    } else {
        jmsMessageConsumer = jmsSession.createConsumer(jmsDestination, vcSelector.getSelectionString());
    }
    return jmsMessageConsumer;
}
Also used : VCDestination(cbit.vcell.message.VCDestination) Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) VCellQueue(cbit.vcell.message.VCellQueue)

Example 3 with VCellQueue

use of cbit.vcell.message.VCellQueue 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 4 with VCellQueue

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

the class RpcRestlet method handle.

@Override
public void handle(Request req, Response response) {
    if (req.getMethod().equals(Method.POST)) {
        String destination = null;
        String method = null;
        try {
            VCellApiApplication application = ((VCellApiApplication) getApplication());
            User vcellUser = application.getVCellUser(req.getChallengeResponse(), AuthenticationPolicy.prohibitInvalidCredentials);
            HttpRequest request = (HttpRequest) req;
            String username = vcellUser.getName();
            String userkey = vcellUser.getID().toString();
            destination = request.getHeaders().getFirstValue("Destination");
            method = request.getHeaders().getFirstValue("Method");
            String returnRequired = request.getHeaders().getFirstValue("ReturnRequired");
            String timeoutMS = request.getHeaders().getFirstValue("TimeoutMS");
            String compressed = request.getHeaders().getFirstValue("Compressed");
            String klass = request.getHeaders().getFirstValue("Class");
            StringBuffer buffer = new StringBuffer();
            buffer.append("username=" + username + ", userkey=" + userkey + ", destination=" + destination + ", method=" + method + "\n");
            buffer.append("returnRequired=" + returnRequired + ", timeoutMS=" + timeoutMS + ", compressed=" + compressed + "\n");
            buffer.append("class=" + klass);
            System.out.println(buffer.toString());
            req.bufferEntity();
            Serializable rpcRequestBodyObject = VCellApiClient.fromCompressedSerialized(req.getEntity().getStream());
            if (!(rpcRequestBodyObject instanceof VCellApiRpcBody)) {
                throw new RuntimeException("expecting post content of type VCellApiRpcBody");
            }
            VCellApiRpcBody rpcBody = (VCellApiRpcBody) rpcRequestBodyObject;
            RpcServiceType st = null;
            VCellQueue queue = null;
            switch(rpcBody.rpcRequest.rpcDestination) {
                case DataRequestQueue:
                    {
                        st = RpcServiceType.DATA;
                        queue = VCellQueue.DataRequestQueue;
                        break;
                    }
                case DbRequestQueue:
                    {
                        st = RpcServiceType.DB;
                        queue = VCellQueue.DbRequestQueue;
                        break;
                    }
                case SimReqQueue:
                    {
                        st = RpcServiceType.DISPATCH;
                        queue = VCellQueue.SimReqQueue;
                        break;
                    }
                default:
                    {
                        throw new RuntimeException("unsupported RPC Destination: " + rpcBody.rpcDestination);
                    }
            }
            VCellApiRpcRequest vcellapiRpcRequest = rpcBody.rpcRequest;
            Object[] arglist = vcellapiRpcRequest.args;
            String[] specialProperties = rpcBody.specialProperties;
            Object[] specialValues = rpcBody.specialValues;
            VCRpcRequest vcRpcRequest = new VCRpcRequest(vcellUser, st, method, arglist);
            VCellApiApplication vcellApiApplication = (VCellApiApplication) getApplication();
            RpcService rpcService = vcellApiApplication.getRpcService();
            Serializable result = rpcService.sendRpcMessage(queue, vcRpcRequest, new Boolean(rpcBody.returnedRequired), specialProperties, specialValues, new UserLoginInfo(username, null));
            byte[] serializedResultObject = VCellApiClient.toCompressedSerialized(result);
            response.setStatus(Status.SUCCESS_OK, "rpc method=" + method + " succeeded");
            response.setEntity(new ByteArrayRepresentation(serializedResultObject));
        } catch (Exception e) {
            getLogger().severe("internal error invoking " + destination + ":" + method + "(): " + e.getMessage());
            e.printStackTrace();
            response.setStatus(Status.SERVER_ERROR_INTERNAL);
            response.setEntity("internal error invoking " + destination + ":" + method + "(): " + e.getMessage(), MediaType.TEXT_PLAIN);
        }
    }
}
Also used : HttpRequest(org.restlet.engine.adapter.HttpRequest) Serializable(java.io.Serializable) User(org.vcell.util.document.User) RpcServiceType(cbit.vcell.message.VCRpcRequest.RpcServiceType) VCellApiRpcBody(org.vcell.api.client.VCellApiClient.VCellApiRpcBody) VCRpcRequest(cbit.vcell.message.VCRpcRequest) VCellApiRpcRequest(org.vcell.api.client.VCellApiRpcRequest) VCellApiApplication(org.vcell.rest.VCellApiApplication) ByteArrayRepresentation(org.restlet.representation.ByteArrayRepresentation) UserLoginInfo(org.vcell.util.document.UserLoginInfo) VCellQueue(cbit.vcell.message.VCellQueue)

Aggregations

VCellQueue (cbit.vcell.message.VCellQueue)4 VCDestination (cbit.vcell.message.VCDestination)2 Destination (javax.jms.Destination)2 MessageConsumer (javax.jms.MessageConsumer)2 RollbackException (cbit.vcell.message.RollbackException)1 VCMessage (cbit.vcell.message.VCMessage)1 VCMessageSelector (cbit.vcell.message.VCMessageSelector)1 VCMessageSession (cbit.vcell.message.VCMessageSession)1 VCMessagingException (cbit.vcell.message.VCMessagingException)1 VCPooledQueueConsumer (cbit.vcell.message.VCPooledQueueConsumer)1 VCQueueConsumer (cbit.vcell.message.VCQueueConsumer)1 QueueListener (cbit.vcell.message.VCQueueConsumer.QueueListener)1 VCRpcRequest (cbit.vcell.message.VCRpcRequest)1 RpcServiceType (cbit.vcell.message.VCRpcRequest.RpcServiceType)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 SolverException (cbit.vcell.solver.SolverException)1 XmlParseException (cbit.vcell.xml.XmlParseException)1