Search in sources :

Example 11 with VCMessage

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

the class JavaSimulationExecutable method init.

protected void init() throws JMSException {
    // 
    // session used for sending worker events.
    // 
    this.workerEventSession = vcMessagingService.createProducerSession();
    // 
    // message consumer for Service Control topic message (to stop simulation).
    // 
    VCellTopic topic = VCellTopic.ServiceControlTopic;
    TopicListener listener = new TopicListener() {

        public void onTopicMessage(VCMessage vcMessage, VCMessageSession session) {
            if (lg.isTraceEnabled())
                lg.trace("JavaSimulationExecutable::onControlTopicMessage(): " + vcMessage.show());
            try {
                String msgType = vcMessage.getStringProperty(VCMessagingConstants.MESSAGE_TYPE_PROPERTY);
                if (msgType != null && msgType.equals(MessageConstants.MESSAGE_TYPE_STOPSIMULATION_VALUE)) {
                    Long longkey = vcMessage.getLongProperty(MessageConstants.SIMKEY_PROPERTY);
                    KeyValue simKey = new KeyValue(longkey + "");
                    int jobIndex = vcMessage.getIntProperty(MessageConstants.JOBINDEX_PROPERTY);
                    if (simKey.equals(simulationTask.getSimKey()) && jobIndex == simulationTask.getSimulationJob().getJobIndex()) {
                        solver.stopSolver();
                    }
                }
            } catch (MessagePropertyNotFoundException ex) {
                lg.error(ex.getMessage(), ex);
                return;
            }
        }
    };
    VCMessageSelector selector = null;
    String threadName = "Service Control Topic Consumer";
    VCTopicConsumer serviceControlConsumer = new VCTopicConsumer(topic, listener, selector, threadName, MessageConstants.PREFETCH_LIMIT_SERVICE_CONTROL);
    vcMessagingService.addMessageConsumer(serviceControlConsumer);
}
Also used : TopicListener(cbit.vcell.message.VCTopicConsumer.TopicListener) KeyValue(org.vcell.util.document.KeyValue) MessagePropertyNotFoundException(cbit.vcell.message.MessagePropertyNotFoundException) VCMessageSelector(cbit.vcell.message.VCMessageSelector) VCMessage(cbit.vcell.message.VCMessage) VCTopicConsumer(cbit.vcell.message.VCTopicConsumer) VCMessageSession(cbit.vcell.message.VCMessageSession) VCellTopic(cbit.vcell.message.VCellTopic)

Example 12 with VCMessage

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

the class StatusMessage method sendToClient.

/**
 * Insert the method's description here.
 * Creation date: (2/5/2004 1:59:04 PM)
 * @return javax.jms.Message
 * @param session cbit.vcell.messaging.VCellSession
 * @throws VCMessagingException
 */
public void sendToClient(VCMessageSession session) throws VCMessagingException {
    VCMessage message = toMessage(session);
    session.sendTopicMessage(VCellTopic.ClientStatusTopic, message);
}
Also used : VCMessage(cbit.vcell.message.VCMessage)

Example 13 with VCMessage

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

the class StatusMessage method toMessage.

/**
 * Insert the method's description here.
 * Creation date: (2/5/2004 1:59:04 PM)
 * @return javax.jms.Message
 * @param session cbit.vcell.messaging.VCellSession
 */
private VCMessage toMessage(VCMessageSession session) {
    VCMessage message = session.createObjectMessage(jobStatus);
    message.setStringProperty(VCMessagingConstants.MESSAGE_TYPE_PROPERTY, MessageConstants.MESSAGE_TYPE_SIMSTATUS_VALUE);
    message.setStringProperty(VCMessagingConstants.USERNAME_PROPERTY, userName);
    if (progress != null) {
        message.setDoubleProperty(MessageConstants.SIMULATION_STATUS_PROGRESS_PROPERTY, progress.doubleValue());
    }
    if (timePoint != null) {
        message.setDoubleProperty(MessageConstants.SIMULATION_STATUS_TIMEPOINT_PROPERTY, timePoint.doubleValue());
    }
    return message;
}
Also used : VCMessage(cbit.vcell.message.VCMessage)

Example 14 with VCMessage

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

the class SimulationTaskMessage method toMessage.

/**
 * Insert the method's description here.
 * Creation date: (12/31/2003 11:08:17 AM)
 * @return javax.jms.Message
 * @param session cbit.vcell.messaging.VCellSession
 * @throws VCMessagingException
 */
private VCMessage toMessage(VCMessageSession session) throws VCMessagingException {
    VCMessage message;
    try {
        message = session.createTextMessage(XmlHelper.simTaskToXML(simTask));
    } catch (XmlParseException e) {
        e.printStackTrace(System.out);
        throw new VCMessagingException("failed to restore Simulation Task from XML", e);
    }
    // must have
    message.setStringProperty(VCMessagingConstants.MESSAGE_TYPE_PROPERTY, MessageConstants.MESSAGE_TYPE_SIMULATION_JOB_VALUE);
    // must have
    message.setIntProperty(MessageConstants.JOBINDEX_PROPERTY, simTask.getSimulationJob().getJobIndex());
    // must have
    message.setIntProperty(MessageConstants.TASKID_PROPERTY, simTask.getTaskID());
    // might be used to remove from the job queue when do stopSimulation
    message.setStringProperty(VCMessagingConstants.USERNAME_PROPERTY, simTask.getUserName());
    // might be used to remove from the job queue when do stopSimulation
    message.setLongProperty(MessageConstants.SIMKEY_PROPERTY, Long.parseLong(simTask.getSimKey() + ""));
    // for worker message filter
    message.setDoubleProperty(MessageConstants.SIZE_MB_PROPERTY, simTask.getEstimatedMemorySizeMB());
    if (simTask.getComputeResource() != null) {
        // for worker message filter
        message.setStringProperty(MessageConstants.COMPUTE_RESOURCE_PROPERTY, simTask.getComputeResource());
    }
    FieldDataIdentifierSpec[] fieldDataIDs = simTask.getSimulationJob().getFieldDataIdentifierSpecs();
    if (fieldDataIDs != null && fieldDataIDs.length > 0) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < fieldDataIDs.length; i++) {
            sb.append(fieldDataIDs[i].toCSVString() + "\n");
        }
        message.setStringProperty(MessageConstants.FIELDDATAID_PROPERTY, sb.toString());
    }
    return message;
}
Also used : VCMessage(cbit.vcell.message.VCMessage) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) XmlParseException(cbit.vcell.xml.XmlParseException) VCMessagingException(cbit.vcell.message.VCMessagingException)

Example 15 with VCMessage

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

the class ServiceProvider method initControlTopicListener.

/**
 * Insert the method's description here.
 * Creation date: (11/19/2001 5:29:47 PM)
 */
public void initControlTopicListener() {
    if (bSlaveMode) {
        return;
    }
    TopicListener listener = new TopicListener() {

        public void onTopicMessage(VCMessage message, VCMessageSession session) {
            try {
                String msgType = message.getStringProperty(VCMessagingConstants.MESSAGE_TYPE_PROPERTY);
                String serviceID = null;
                if (msgType == null) {
                    return;
                }
                if (msgType.equals(MessageConstants.MESSAGE_TYPE_ISSERVICEALIVE_VALUE)) {
                    VCMessage reply = session.createObjectMessage(ServiceProvider.this.serviceInstanceStatus);
                    reply.setStringProperty(VCMessagingConstants.MESSAGE_TYPE_PROPERTY, MessageConstants.MESSAGE_TYPE_IAMALIVE_VALUE);
                    reply.setStringProperty(MessageConstants.SERVICE_ID_PROPERTY, serviceInstanceStatus.getID());
                    if (lg.isTraceEnabled())
                        lg.trace("sending reply [" + reply.toString() + "]");
                    if (message.getReplyTo() != null) {
                        reply.setCorrelationID(message.getMessageID());
                        session.sendTopicMessage((VCellTopic) message.getReplyTo(), reply);
                    } else {
                        session.sendTopicMessage(VCellTopic.DaemonControlTopic, reply);
                    }
                } else if (msgType.equals(MessageConstants.MESSAGE_TYPE_ASKPERFORMANCESTATUS_VALUE)) {
                    VCMessage reply = session.createObjectMessage(serviceInstanceStatus);
                    reply.setStringProperty(VCMessagingConstants.MESSAGE_TYPE_PROPERTY, MessageConstants.MESSAGE_TYPE_REPLYPERFORMANCESTATUS_VALUE);
                    reply.setStringProperty(MessageConstants.SERVICE_ID_PROPERTY, serviceInstanceStatus.getID());
                    session.sendTopicMessage(VCellTopic.DaemonControlTopic, reply);
                    if (lg.isTraceEnabled())
                        lg.trace("sending reply [" + reply.toString() + "]");
                } else if (msgType.equals(MessageConstants.MESSAGE_TYPE_STOPSERVICE_VALUE)) {
                    serviceID = message.getStringProperty(MessageConstants.SERVICE_ID_PROPERTY);
                    if (serviceID != null && serviceID.equalsIgnoreCase(serviceInstanceStatus.getID())) {
                        stopService();
                    }
                }
            } catch (Exception ex) {
                lg.error(ex.getMessage(), ex);
            }
        }
    };
    VCMessageSelector selector = vcMessagingService.createSelector(getDaemonControlFilter());
    String threadName = "Daemon Control Topic Consumer";
    vcTopicConsumer = new VCTopicConsumer(VCellTopic.DaemonControlTopic, listener, selector, threadName, MessageConstants.PREFETCH_LIMIT_DAEMON_CONTROL);
    vcMessagingService.addMessageConsumer(vcTopicConsumer);
}
Also used : TopicListener(cbit.vcell.message.VCTopicConsumer.TopicListener) VCMessageSelector(cbit.vcell.message.VCMessageSelector) VCMessage(cbit.vcell.message.VCMessage) VCTopicConsumer(cbit.vcell.message.VCTopicConsumer) VCMessageSession(cbit.vcell.message.VCMessageSession) FileNotFoundException(java.io.FileNotFoundException) VCMessagingException(cbit.vcell.message.VCMessagingException)

Aggregations

VCMessage (cbit.vcell.message.VCMessage)22 VCMessageSession (cbit.vcell.message.VCMessageSession)10 VCMessagingException (cbit.vcell.message.VCMessagingException)9 VCMessageSelector (cbit.vcell.message.VCMessageSelector)6 VCQueueConsumer (cbit.vcell.message.VCQueueConsumer)5 QueueListener (cbit.vcell.message.VCQueueConsumer.QueueListener)5 VCDestination (cbit.vcell.message.VCDestination)4 SimulationJobStatus (cbit.vcell.server.SimulationJobStatus)4 FileNotFoundException (java.io.FileNotFoundException)4 RollbackException (cbit.vcell.message.RollbackException)3 VCTopicConsumer (cbit.vcell.message.VCTopicConsumer)3 TopicListener (cbit.vcell.message.VCTopicConsumer.TopicListener)3 LocalVCMessageAdapter (cbit.vcell.message.local.LocalVCMessageAdapter)3 LocalVCMessageListener (cbit.vcell.message.local.LocalVCMessageAdapter.LocalVCMessageListener)3 SolverException (cbit.vcell.solver.SolverException)3 XmlParseException (cbit.vcell.xml.XmlParseException)3 DataAccessException (org.vcell.util.DataAccessException)3 MessagePropertyNotFoundException (cbit.vcell.message.MessagePropertyNotFoundException)2 VCMessagingService (cbit.vcell.message.VCMessagingService)2 VCPooledQueueConsumer (cbit.vcell.message.VCPooledQueueConsumer)2