Example usage for javax.jms MessageProducer close

List of usage examples for javax.jms MessageProducer close

Introduction

In this page you can find the example usage for javax.jms MessageProducer close.

Prototype


void close() throws JMSException;

Source Link

Document

Closes the message producer.

Usage

From source file:org.gss_project.gss.server.ejb.AdminAPIBean.java

public void indexFile(Long fileId, boolean delete) {
    Connection qConn = null;//from  ww w .j  ava 2  s  .  c  om
    Session session = null;
    MessageProducer sender = null;
    try {
        Context jndiCtx = new InitialContext();
        ConnectionFactory factory = (QueueConnectionFactory) jndiCtx.lookup("java:/JmsXA");
        Queue queue = (Queue) jndiCtx.lookup("queue/gss-indexingQueue");
        qConn = factory.createConnection();
        session = qConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        sender = session.createProducer(queue);

        MapMessage map = session.createMapMessage();
        map.setObject("id", fileId);
        map.setBoolean("delete", delete);
        sender.send(map);
    } catch (NamingException e) {
        logger.error("Index was not updated: ", e);
    } catch (JMSException e) {
        logger.error("Index was not updated: ", e);
    } finally {
        try {
            if (sender != null)
                sender.close();
            if (session != null)
                session.close();
            if (qConn != null)
                qConn.close();
        } catch (JMSException e) {
            logger.warn(e);
        }
    }
}

From source file:org.gss_project.gss.server.ejb.ExternalAPIBean.java

private void indexFile(Long fileId, boolean delete) {
     Connection qConn = null;//ww w .  ja v  a2  s  .  c  o  m
     Session session = null;
     MessageProducer sender = null;
     try {
         Context jndiCtx = new InitialContext();
         ConnectionFactory factory = (QueueConnectionFactory) jndiCtx.lookup("java:/JmsXA");
         Queue queue = (Queue) jndiCtx.lookup("queue/gss-indexingQueue");
         qConn = factory.createConnection();
         session = qConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
         sender = session.createProducer(queue);

         MapMessage map = session.createMapMessage();
         map.setObject("id", fileId);
         map.setBoolean("delete", delete);
         sender.send(map);
     } catch (NamingException e) {
         logger.error("Index was not updated: ", e);
     } catch (JMSException e) {
         logger.error("Index was not updated: ", e);
     } finally {
         try {
             if (sender != null)
                 sender.close();
             if (session != null)
                 session.close();
             if (qConn != null)
                 qConn.close();
         } catch (JMSException e) {
             logger.warn(e);
         }
     }
 }

From source file:org.jbpm.bpel.integration.jms.OutstandingRequest.java

public void sendReply(Map parts, QName faultName, Session jmsSession) throws JMSException {
    MessageProducer producer = null;
    try {/*from w  w w .  j  a v a2s .  co  m*/
        producer = jmsSession.createProducer(replyDestination);
        /*
         * the given parts likely are an instance of PersistentMap which does not serialize nicely;
         * copy the parts to a transient Map implementation
         */
        switch (parts.size()) {
        case 0:
            parts = Collections.EMPTY_MAP;
            break;
        case 1: {
            Map.Entry single = (Entry) parts.entrySet().iterator().next();
            parts = Collections.singletonMap(single.getKey(), single.getValue());
            break;
        }
        default:
            parts = new HashMap(parts);
            break;
        }
        Message responseMsg = jmsSession.createObjectMessage((Serializable) parts);
        responseMsg.setJMSCorrelationID(correlationID);
        // set the fault name, if any
        if (faultName != null) {
            responseMsg.setStringProperty(IntegrationConstants.FAULT_NAME_PROP, faultName.getLocalPart());
        }
        // send the response
        producer.send(responseMsg);
        log.debug("sent response: " + RequestListener.messageToString(responseMsg));
    } finally {
        if (producer != null) {
            try {
                producer.close();
            } catch (JMSException e) {
                log.warn("could not close jms producer", e);
            }
        }
    }
}

From source file:org.jbpm.bpel.integration.server.SoapHandler.java

protected ObjectMessage sendRequest(SOAPMessage soapMessage, Session jmsSession, JbpmContext jbpmContext)
        throws SOAPException, JMSException {
    // create a jms message to deliver the incoming content
    ObjectMessage jmsRequest = jmsSession.createObjectMessage();

    // put the partner link identified by handle in a jms property
    PartnerLinkEntry partnerLinkEntry = integrationControl.getPartnerLinkEntry(portTypeName, serviceName,
            portName);//from w w  w. ja  v a  2s . c  o m
    long partnerLinkId = partnerLinkEntry.getId();
    jmsRequest.setLongProperty(IntegrationConstants.PARTNER_LINK_ID_PROP, partnerLinkId);

    Operation operation = determineOperation(soapMessage);
    if (operation == null)
        throw new SOAPException("could not determine operation to perform");

    // put the operation name in a jms property
    String operationName = operation.getName();
    jmsRequest.setStringProperty(IntegrationConstants.OPERATION_NAME_PROP, operationName);

    log.debug("received request: partnerLink=" + partnerLinkId + ", operation=" + operationName);

    // extract message content
    HashMap requestParts = new HashMap();
    formatter.readMessage(operationName, soapMessage, requestParts, MessageDirection.INPUT);
    jmsRequest.setObject(requestParts);

    // fill message properties
    BpelProcessDefinition process = integrationControl.getDeploymentDescriptor()
            .findProcessDefinition(jbpmContext);
    MessageType requestType = process.getImportDefinition()
            .getMessageType(operation.getInput().getMessage().getQName());
    fillCorrelationProperties(requestParts, jmsRequest, requestType.getPropertyAliases());

    // set up producer
    MessageProducer producer = jmsSession.createProducer(partnerLinkEntry.getDestination());
    try {
        // is the exchange pattern request/response?
        if (operation.getOutput() != null) {
            Destination replyTo = integrationControl.getIntegrationServiceFactory().getResponseDestination();
            jmsRequest.setJMSReplyTo(replyTo);

            // have jms discard request message if response timeout expires
            Number responseTimeout = getResponseTimeout(jbpmContext);
            if (responseTimeout != null)
                producer.setTimeToLive(responseTimeout.longValue());
        } else {
            // have jms discard message if one-way timeout expires
            Number oneWayTimeout = getOneWayTimeout(jbpmContext);
            if (oneWayTimeout != null)
                producer.setTimeToLive(oneWayTimeout.longValue());
        }

        // send request message
        producer.send(jmsRequest);
        log.debug("sent request: " + RequestListener.messageToString(jmsRequest));

        return jmsRequest;
    } finally {
        // release producer resources
        producer.close();
    }
}

From source file:org.jbpm.executor.impl.ExecutorImpl.java

protected void sendMessage(String messageBody, int priority) {
    if (connectionFactory == null && queue == null) {
        throw new IllegalStateException("ConnectionFactory and Queue cannot be null");
    }/*  w  w w .  j  av a2 s .com*/
    Connection queueConnection = null;
    Session queueSession = null;
    MessageProducer producer = null;
    try {
        queueConnection = connectionFactory.createConnection();
        queueSession = queueConnection.createSession(transacted, Session.AUTO_ACKNOWLEDGE);

        TextMessage message = queueSession.createTextMessage(messageBody);
        producer = queueSession.createProducer(queue);
        producer.setPriority(priority);

        queueConnection.start();

        producer.send(message);
    } catch (Exception e) {
        throw new RuntimeException("Error when sending JMS message with executor job request", e);
    } finally {
        if (producer != null) {
            try {
                producer.close();
            } catch (JMSException e) {
                logger.warn("Error when closing producer", e);
            }
        }

        if (queueSession != null) {
            try {
                queueSession.close();
            } catch (JMSException e) {
                logger.warn("Error when closing queue session", e);
            }
        }

        if (queueConnection != null) {
            try {
                queueConnection.close();
            } catch (JMSException e) {
                logger.warn("Error when closing queue connection", e);
            }
        }
    }
}

From source file:org.mot.common.mq.ActiveMQFactory.java

public void closeMessageProducer(MessageProducer mp) {

    try {/*from  w  w  w  .  j  a v  a  2 s. c  om*/
        mp.close();

    } catch (JMSException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.mule.transport.jms.integration.AbstractJmsFunctionalTestCase.java

public void send(Scenario scenario) throws Exception {
    Connection connection = null;
    try {/*  w  w w . j  a  v  a2  s.  c o  m*/
        connection = getConnection(false, false);
        connection.start();
        Session session = null;
        try {
            session = connection.createSession(scenario.isTransacted(), scenario.getAcknowledge());
            Destination destination = createInputDestination(session, scenario);
            MessageProducer producer = null;
            try {
                producer = session.createProducer(destination);
                if (scenario.isPersistent()) {
                    producer.setDeliveryMode(DeliveryMode.PERSISTENT);
                }
                scenario.send(session, producer);
            } finally {
                if (producer != null) {
                    producer.close();
                }
            }
        } finally {
            if (session != null) {
                session.close();
            }
        }
    } finally {
        if (connection != null) {
            connection.close();
        }
    }
}

From source file:org.openengsb.opencit.core.projectmanager.internal.ProjectManagerImpl.java

private void stopProject(Project project) {
    scheduler.suspendScmPoller(project.getId());

    MessageProducer producer = project.getProducer();
    if (producer != null) {
        try {//from   w w  w. j a v  a2 s.  co m
            producer.close();
        } catch (JMSException e) {
            log.error("Failed to close JMS topic for project " + project.getId(), e);
        }
    }
    project.setProducer(null);
    project.setTopic(null);
}

From source file:org.openengsb.opencit.core.projectmanager.internal.ProjectManagerImpl.java

@Override
public void sendFeedback(String channel, BuildFeedback feedback) {
    if (session == null) {
        /* OK, this shouldn't happen. How did we get the update notification if JMS is not up? */
        log.info("JMS not started, not sending feedback\n");
        return;/*from w ww .ja  v a2 s  .  c om*/
    }

    try {
        Destination topic = session.createQueue(channel);
        MessageProducer producer = session.createProducer(topic);
        ObjectMessage msg = session.createObjectMessage(feedback);
        producer.send(msg);
        producer.close();
        log.info("Build feedback sent\n");
    } catch (JMSException e) {
        log.error("Error delivering feedback", e);
    }
}

From source file:org.sofun.core.messaging.SofunMessagingServiceImpl.java

@Override
public void sendMessage(Serializable message, String destination) {

    Connection connection = null;
    Session session = null;/*from w w w  . jav  a2s.c o m*/
    MessageProducer sender = null;
    Queue q = getQueueFor(destination);
    if (q == null) {
        log.error("Cannot find associated queue for destination=" + destination);
    }
    try {
        connection = connFactory.createConnection(SofunMessagingCredentials.USERNAME,
                SofunMessagingCredentials.PASSWORD);
        session = connection.createSession(true, 0);
        sender = session.createProducer(q);
        ObjectMessage msg = session.createObjectMessage(message);
        sender.send(msg);
    } catch (Exception e) {
        log.error(e.getMessage());
    } finally {
        try {
            if (sender != null) {
                sender.close();
            }
            if (session != null) {
                session.close();
            }
            if (connection != null) {
                connection.close();
            }
        } catch (JMSException e) {
            log.error(e.getMessage());
        }

    }

}