Search in sources :

Example 16 with JMSException

use of javax.jms.JMSException in project ACS by ACS-Community.

the class DefaultSubscriberImpl method close.

/**
   * Method close
   *
   *
   */
public void close() {
    cat.debug("close()");
    synchronized (subscribers) {
        SubscriptionHandle handle = null;
        keepAliveEnabled = false;
        try {
            Iterator iterator = subscribers.values().iterator();
            while (iterator.hasNext()) {
                handle = (SubscriptionHandle) iterator.next();
                if (!NotificationHelper.isNotification(handle.getSubscriptionTopic())) {
                    publishNotification(NotificationHelper.CONSUMER_CLOSE_NOTIFICATION, handle);
                }
                handle.getSubscriber().close();
                handle.getSession().close();
            }
            subscribers.clear();
            if (notificationPublisher != null) {
                notificationPublisher.close();
                notificationPublisher = null;
            }
            if (serviceSession != null) {
                serviceSession.close();
                serviceSession = null;
            }
            if (topicDirectory != null) {
                topicDirectory.clear();
                topicDirectory = null;
            }
        } catch (JMSException e) {
            cat.error("Exception raised closing a Subscriber : " + e.getMessage());
        }
        if (connection != null) {
            try {
                connection.stop();
            } catch (ConnectionException ce) {
                ce.printStackTrace();
            }
            connection.close();
            connection = null;
        }
        closed = true;
    }
    cat.debug("closed.");
}
Also used : Iterator(java.util.Iterator) JMSException(javax.jms.JMSException)

Example 17 with JMSException

use of javax.jms.JMSException in project Protocol-Adapter-IEC61850 by OSGP.

the class PublicLightingGetStatusRequestMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing public lighting get status request message");
    String correlationUid = null;
    String domain = null;
    String domainVersion = null;
    String messageType = null;
    String organisationIdentification = null;
    String deviceIdentification = null;
    String ipAddress = null;
    int retryCount = 0;
    boolean isScheduled = false;
    try {
        correlationUid = message.getJMSCorrelationID();
        domain = message.getStringProperty(Constants.DOMAIN);
        domainVersion = message.getStringProperty(Constants.DOMAIN_VERSION);
        messageType = message.getJMSType();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        ipAddress = message.getStringProperty(Constants.IP_ADDRESS);
        retryCount = message.getIntProperty(Constants.RETRY_COUNT);
        isScheduled = message.propertyExists(Constants.IS_SCHEDULED) ? message.getBooleanProperty(Constants.IS_SCHEDULED) : false;
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        LOGGER.debug("correlationUid: {}", correlationUid);
        LOGGER.debug("domain: {}", domain);
        LOGGER.debug("domainVersion: {}", domainVersion);
        LOGGER.debug("messageType: {}", messageType);
        LOGGER.debug("organisationIdentification: {}", organisationIdentification);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("ipAddress: {}", ipAddress);
        return;
    }
    final RequestMessageData requestMessageData = new RequestMessageData(null, domain, domainVersion, messageType, retryCount, isScheduled, correlationUid, organisationIdentification, deviceIdentification);
    this.printDomainInfo(messageType, domain, domainVersion);
    final Iec61850DeviceResponseHandler iec61850DeviceResponseHandler = this.createIec61850DeviceResponseHandler(requestMessageData, message);
    final DeviceRequest deviceRequest = new DeviceRequest(organisationIdentification, deviceIdentification, correlationUid, domain, domainVersion, messageType, ipAddress, retryCount, isScheduled);
    this.deviceService.getStatus(deviceRequest, iec61850DeviceResponseHandler);
}
Also used : Iec61850DeviceResponseHandler(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.services.Iec61850DeviceResponseHandler) JMSException(javax.jms.JMSException) DeviceRequest(com.alliander.osgp.adapter.protocol.iec61850.device.DeviceRequest) RequestMessageData(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.RequestMessageData)

Example 18 with JMSException

use of javax.jms.JMSException in project Protocol-Adapter-IEC61850 by OSGP.

the class DeviceRequestMessageListener method onMessage.

/*
     * (non-Javadoc)
     *
     * @see
     * org.springframework.jms.listener.SessionAwareMessageListener#onMessage
     * (javax.jms.Message, javax.jms.Session)
     */
@Override
public void onMessage(final Message message, final Session session) throws JMSException {
    final ObjectMessage objectMessage = (ObjectMessage) message;
    String messageType = null;
    MessageProcessor processor = null;
    try {
        messageType = message.getJMSType();
        LOGGER.info("Received message of type: {}", messageType);
        processor = this.iec61850RequestMessageProcessorMap.getMessageProcessor(objectMessage);
    } catch (final IllegalArgumentException | JMSException e) {
        LOGGER.error("Unexpected IllegalArgumentException | JMSExceptionduring during onMessage(Message)", e);
        this.createAndSendException(objectMessage, messageType);
        return;
    }
    processor.processMessage(objectMessage);
}
Also used : ObjectMessage(javax.jms.ObjectMessage) MessageProcessor(com.alliander.osgp.shared.infra.jms.MessageProcessor) JMSException(javax.jms.JMSException)

Example 19 with JMSException

use of javax.jms.JMSException in project Protocol-Adapter-IEC61850 by OSGP.

the class DeviceRequestMessageProcessorMap method getMessageProcessor.

@Override
public MessageProcessor getMessageProcessor(final ObjectMessage message) throws JMSException {
    if (message.getJMSType() == null) {
        LOGGER.error("Unknown message type: {}", message.getJMSType());
        throw new JMSException("Unknown message type");
    }
    final DeviceRequestMessageType messageType = DeviceRequestMessageType.valueOf(message.getJMSType());
    if (messageType.name() == null) {
        LOGGER.error("No message processor found for message type: {}", message.getJMSType());
        throw new JMSException("Unknown message processor for message type: " + message.getJMSType());
    }
    final MessageProcessor messageProcessor = this.messageProcessors.get(messageType.ordinal());
    if (messageProcessor == null) {
        LOGGER.error("No message processor instance found in message processor map for message type: {}", message.getJMSType());
        throw new JMSException("Unknown message processor");
    }
    return messageProcessor;
}
Also used : MessageProcessor(com.alliander.osgp.shared.infra.jms.MessageProcessor) JMSException(javax.jms.JMSException)

Example 20 with JMSException

use of javax.jms.JMSException in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850LogItemRequestMessageSender method send.

public void send(final Iec61850LogItemRequestMessage iec61850LogItemRequestMessage) {
    LOGGER.debug("Sending Iec61850LogItemRequestMessage");
    this.iec61850LogItemRequestsJmsTemplate.send(new MessageCreator() {

        @Override
        public Message createMessage(final Session session) throws JMSException {
            final ObjectMessage objectMessage = session.createObjectMessage();
            objectMessage.setJMSType(Constants.IEC61850_LOG_ITEM_REQUEST);
            objectMessage.setStringProperty(Constants.IS_INCOMING, iec61850LogItemRequestMessage.isIncoming().toString());
            objectMessage.setStringProperty(Constants.ENCODED_MESSAGE, iec61850LogItemRequestMessage.getEncodedMessage());
            objectMessage.setStringProperty(Constants.DECODED_MESSAGE, iec61850LogItemRequestMessage.getDecodedMessage());
            objectMessage.setStringProperty(Constants.DEVICE_IDENTIFICATION, iec61850LogItemRequestMessage.getDeviceIdentification());
            objectMessage.setStringProperty(Constants.ORGANISATION_IDENTIFICATION, iec61850LogItemRequestMessage.getOrganisationIdentification());
            objectMessage.setStringProperty(Constants.IS_VALID, iec61850LogItemRequestMessage.isValid().toString());
            objectMessage.setIntProperty(Constants.PAYLOAD_MESSAGE_SERIALIZED_SIZE, iec61850LogItemRequestMessage.getPayloadMessageSerializedSize());
            return objectMessage;
        }
    });
}
Also used : ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException) MessageCreator(org.springframework.jms.core.MessageCreator) Session(javax.jms.Session)

Aggregations

JMSException (javax.jms.JMSException)1038 Message (javax.jms.Message)335 Test (org.junit.Test)320 Session (javax.jms.Session)297 TextMessage (javax.jms.TextMessage)288 Connection (javax.jms.Connection)253 MessageProducer (javax.jms.MessageProducer)160 MessageConsumer (javax.jms.MessageConsumer)148 Destination (javax.jms.Destination)99 ObjectMessage (javax.jms.ObjectMessage)98 Queue (javax.jms.Queue)93 MapMessage (javax.jms.MapMessage)66 ConnectionFactory (javax.jms.ConnectionFactory)63 CountDownLatch (java.util.concurrent.CountDownLatch)61 IOException (java.io.IOException)59 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)53 BytesMessage (javax.jms.BytesMessage)52 MessageListener (javax.jms.MessageListener)50 MessageFormatException (javax.jms.MessageFormatException)43 HashMap (java.util.HashMap)40