Search in sources :

Example 1 with VCTopicConsumer

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

the class ClientTopicMessageCollector method init.

/**
 * onException method comment.
 */
public void init() {
    VCMessageSelector selector = null;
    topicConsumer = new VCTopicConsumer(VCellTopic.ClientStatusTopic, this, selector, "Client Status Topic Consumer", MessageConstants.PREFETCH_LIMIT_CLIENT_TOPIC);
    vcMessagingService.addMessageConsumer(topicConsumer);
}
Also used : VCMessageSelector(cbit.vcell.message.VCMessageSelector) VCTopicConsumer(cbit.vcell.message.VCTopicConsumer)

Example 2 with VCTopicConsumer

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

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

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

VCTopicConsumer (cbit.vcell.message.VCTopicConsumer)4 VCMessageSelector (cbit.vcell.message.VCMessageSelector)3 VCMessage (cbit.vcell.message.VCMessage)2 VCMessageSession (cbit.vcell.message.VCMessageSession)2 VCMessagingException (cbit.vcell.message.VCMessagingException)2 TopicListener (cbit.vcell.message.VCTopicConsumer.TopicListener)2 MessagePropertyNotFoundException (cbit.vcell.message.MessagePropertyNotFoundException)1 RollbackException (cbit.vcell.message.RollbackException)1 VCQueueConsumer (cbit.vcell.message.VCQueueConsumer)1 VCellTopic (cbit.vcell.message.VCellTopic)1 FileNotFoundException (java.io.FileNotFoundException)1 JMSException (javax.jms.JMSException)1 Message (javax.jms.Message)1 KeyValue (org.vcell.util.document.KeyValue)1