Example usage for javax.jms TopicConnectionFactory createTopicConnection

List of usage examples for javax.jms TopicConnectionFactory createTopicConnection

Introduction

In this page you can find the example usage for javax.jms TopicConnectionFactory createTopicConnection.

Prototype


TopicConnection createTopicConnection() throws JMSException;

Source Link

Document

Creates a topic connection with the default user identity.

Usage

From source file:org.wso2.carbon.event.core.internal.delivery.jms.JMSDeliveryManager.java

public TopicConnection getTopicConnection(String userName) throws EventBrokerException {
    InitialContext initialContext = null;
    try {/*from ww w. j ava 2  s.co m*/

        initialContext = new InitialContext(getInitialContextProperties(userName,
                EventBrokerHolder.getInstance().getQpidServerDetails().getAccessKey()));
        TopicConnectionFactory topicConnectionFactory = getTopicConnectionFactory(initialContext);

        TopicConnection topicConnection = topicConnectionFactory.createTopicConnection();
        topicConnection.start();
        return topicConnection;
    } catch (NamingException e) {
        throw new EventBrokerException("Can not create the initial context", e);
    } catch (JMSException e) {
        throw new EventBrokerException("Can not create topic connection", e);
    } catch (Exception e) {
        throw new EventBrokerException("Can not create topic connection", e);
    } finally {
        if (initialContext != null) {
            try {
                initialContext.close();
            } catch (NamingException e) {
                log.error("Can not close the inital context factory ", e);
            }
        }
    }
}

From source file:eu.learnpad.simulator.mon.manager.ResponseDispatcher.java

public ResponseDispatcher(InitialContext initConn, TopicConnectionFactory connectionFact,
        HashMap<Object, ConsumerProfile> requestMap) {

    ResponseDispatcher.requestMap = requestMap;
    ResponseDispatcher.initConn = initConn;
    try {/*from   w  w  w  .j  a va2s  . co  m*/
        connection = connectionFact.createTopicConnection();
        publishSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    } catch (JMSException e) {
        e.printStackTrace();
    }
}

From source file:org.wso2.carbon.andes.event.core.internal.delivery.jms.JMSDeliveryManager.java

/**
 * Initialize and return topic connection
 *
 * @param userName username//from w  ww  .  j  av a 2s  . co m
 * @return topic connection
 * @throws EventBrokerException
 */
public TopicConnection getTopicConnection(String userName) throws EventBrokerException {
    InitialContext initialContext = null;
    try {

        initialContext = new InitialContext(getInitialContextProperties(userName,
                EventBrokerHolder.getInstance().getQpidServerDetails().getAccessKey()));
        TopicConnectionFactory topicConnectionFactory = getTopicConnectionFactory(initialContext);

        TopicConnection topicConnection = topicConnectionFactory.createTopicConnection();
        topicConnection.start();
        return topicConnection;
    } catch (NamingException e) {
        throw new EventBrokerException("Can not create the initial context", e);
    } catch (EventBrokerException | JMSException e) {
        throw new EventBrokerException("Can not create topic connection", e);
    } finally {
        if (initialContext != null) {
            try {
                initialContext.close();
            } catch (NamingException e) {
                log.error("Can not close the inital context factory ", e);
            }
        }
    }
}

From source file:it.cnr.isti.labse.glimpse.impl.ComplexEventProcessorImpl.java

public void init(TopicConnectionFactory connectionFact, InitialContext initConn) {
    try {//from  w  w  w .jav a2  s.c o m
        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Creating connection object ");
        connection = connectionFact.createTopicConnection();
        DebugMessages.ok();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Creating public session object ");
        publishSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        DebugMessages.ok();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Creating subscribe object ");
        subscribeSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        DebugMessages.ok();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Setting up reading topic ");
        connectionTopic = (Topic) initConn.lookup(topic);
        tSub = subscribeSession.createSubscriber(connectionTopic, null, true);
        DebugMessages.ok();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Setting up destination topic ");
        connectionTopic = publishSession.createTopic(this.topic);
        tPub = publishSession.createPublisher(connectionTopic);
        DebugMessages.ok();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Reading knowledge base ");
        kbase = readKnowledgeBase();
        ksession = kbase.newStatefulKnowledgeSession();
        ksession.setGlobal("EVENTS EntryPoint", eventStream);
        eventStream = ksession.getWorkingMemoryEntryPoint("DEFAULT");
        cepRuleManager = new DroolsRulesManager(kbuilder, kbase, ksession);
        DebugMessages.ok();

    } catch (JMSException e) {
        e.printStackTrace();
    } catch (NamingException e) {
        e.printStackTrace();
    }
}

From source file:org.wso2.carbon.appfactory.resource.mgt.listeners.TenantCreationDurableSubscriber.java

/**
 * Subscribe as a durable subscriber to the topic.
 *
 * @throws AppFactoryEventException/*from  w  ww.j  a va 2  s.c o  m*/
 */
public void subscribe() throws AppFactoryEventException {
    Properties properties = new Properties();
    properties.put(Context.INITIAL_CONTEXT_FACTORY, AppFactoryConstants.ANDES_ICF);
    properties.put(AppFactoryConstants.CF_NAME_PREFIX + AppFactoryConstants.CF_NAME,
            Util.getTCPConnectionURL());
    properties.put(CarbonConstants.REQUEST_BASE_CONTEXT, "true");
    properties.put(AppFactoryConstants.TOPIC, topicName);
    TopicConnectionFactory connFactory;
    TopicConnection topicConnection;
    TopicSession topicSession;
    TopicSubscriber topicSubscriber;
    InitialContext ctx;
    try {
        ctx = new InitialContext(properties);
        connFactory = (TopicConnectionFactory) ctx.lookup(AppFactoryConstants.CF_NAME);
        topicConnection = connFactory.createTopicConnection();
        topicSession = topicConnection.createTopicSession(false, TopicSession.CLIENT_ACKNOWLEDGE);
        Topic topic;
        try {
            topic = (Topic) ctx.lookup(topicName);
        } catch (NamingException e) {
            topic = topicSession.createTopic(topicName);
        }
        topicSubscriber = topicSession.createDurableSubscriber(topic, subscriptionId);
        topicSubscriber.setMessageListener(
                new TenantCreationMessageListener(topicConnection, topicSession, topicSubscriber));
        topicConnection.start();
        if (log.isDebugEnabled()) {
            log.debug("Durable Subscriber created for topic " + topicName + " with subscription id : "
                    + subscriptionId);
        }
    } catch (NamingException e) {
        throw new AppFactoryEventException("Failed to subscribe to topic : " + topicName
                + " with subscription id" + " : " + subscriptionId, e);
    } catch (JMSException e) {
        throw new AppFactoryEventException("Failed to subscribe to topic : " + topicName
                + " with subscription id" + " : " + subscriptionId, e);
    }
}

From source file:org.wso2.carbon.appfactory.stratos.listeners.StratosSubscriptionDurableSubscriber.java

/**
 * Subscribe as a durable subscriber to the topic.
 *
 * @throws AppFactoryEventException//from   w  ww  .  ja va2 s . com
 */
public void subscribe() throws AppFactoryEventException {
    Properties properties = new Properties();
    properties.put(Context.INITIAL_CONTEXT_FACTORY, AppFactoryConstants.ANDES_ICF);
    properties.put(AppFactoryConstants.CF_NAME_PREFIX + AppFactoryConstants.CF_NAME,
            Util.getTCPConnectionURL());
    properties.put(CarbonConstants.REQUEST_BASE_CONTEXT, true);
    properties.put(AppFactoryConstants.TOPIC, topicName);
    TopicConnectionFactory connFactory;
    TopicConnection topicConnection;
    TopicSession topicSession;
    TopicSubscriber topicSubscriber;
    InitialContext ctx;
    try {
        ctx = new InitialContext(properties);
        connFactory = (TopicConnectionFactory) ctx.lookup(AppFactoryConstants.CF_NAME);
        topicConnection = connFactory.createTopicConnection();
        topicSession = topicConnection.createTopicSession(false, TopicSession.CLIENT_ACKNOWLEDGE);
        Topic topic;
        try {
            topic = (Topic) ctx.lookup(topicName);
        } catch (NamingException e) {
            topic = topicSession.createTopic(topicName);
        }
        topicSubscriber = topicSession.createDurableSubscriber(topic, subscriptionId);
        topicSubscriber.setMessageListener(
                new StratosSubscriptionMessageListener(topicConnection, topicSession, topicSubscriber));
        topicConnection.start();
        if (log.isDebugEnabled()) {
            log.debug("Durable Subscriber created for topic " + topicName + " with subscription id : "
                    + subscriptionId);
        }
    } catch (NamingException e) {
        throw new AppFactoryEventException("Failed to subscribe to topic : " + topicName
                + " with subscription id" + " : " + subscriptionId, e);
    } catch (JMSException e) {
        throw new AppFactoryEventException("Failed to subscribe to topic : " + topicName
                + " with subscription id" + " : " + subscriptionId, e);
    }
}

From source file:eu.learnpad.simulator.mon.impl.ComplexEventProcessorImpl.java

public void init(TopicConnectionFactory connectionFact, InitialContext initConn) {
    try {//from w ww . ja  v  a 2s  .  com
        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Creating connection object ");
        connection = connectionFact.createTopicConnection();
        DebugMessages.ok();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Creating public session object ");
        publishSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        DebugMessages.ok();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Creating subscribe object ");
        subscribeSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        DebugMessages.ok();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Setting up reading topic ");
        connectionTopic = (Topic) initConn.lookup(topic);
        tSub = subscribeSession.createSubscriber(connectionTopic, null, true);
        DebugMessages.ok();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Setting up destination topic ");
        connectionTopic = publishSession.createTopic(this.topic);
        tPub = publishSession.createPublisher(connectionTopic);
        DebugMessages.ok();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Reading knowledge base ");

        knowledgeBase = createKnowledgeBase();
        ksession = knowledgeBase.newStatefulKnowledgeSession();
        ksession.setGlobal("EVENTS EntryPoint", eventStream);
        eventStream = ksession.getWorkingMemoryEntryPoint("DEFAULT");
        cepRuleManager = new DroolsRulesManager(knowledgeBuilder, knowledgeBase, ksession);
        DebugMessages.ok();

    } catch (JMSException e) {
        DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), e.getMessage());
    } catch (NamingException e) {
        DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), e.getMessage());
    }
}

From source file:it.cnr.isti.labse.glimpse.manager.GlimpseManager.java

public void setupConnection(TopicConnectionFactory connectionFact, InitialContext initConn) {
    try {/* w  ww.  j  a  va 2 s  .c o  m*/
        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Creating connection object ");
        connection = connectionFact.createTopicConnection();
        DebugMessages.ok();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Creating public session object ");
        publishSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        DebugMessages.ok();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Creating subscribe object");
        subscribeSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        DebugMessages.ok();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Setting up destination topic ");
        connectionTopic = (Topic) initConn.lookup(serviceTopic);
        tPub = publishSession.createPublisher(connectionTopic);
        DebugMessages.ok();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Setting up reading topic ");
        tSub = subscribeSession.createSubscriber(connectionTopic, "DESTINATION = 'monitor'", true);
        tSub.setMessageListener(this);
        DebugMessages.ok();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Creating response dispatcher ");
        responder = new ResponseDispatcher(initConn, connectionFact, requestMap);
        DebugMessages.ok();

    } catch (JMSException e) {
        e.printStackTrace();
    } catch (NamingException e) {
        e.printStackTrace();
    }
}

From source file:it.cnr.isti.labsedc.glimpse.impl.ComplexEventProcessorImpl.java

public void init(TopicConnectionFactory connectionFact, InitialContext initConn) {
    try {//from   www  . j a v  a 2  s. c om
        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Creating connection object ");
        connection = connectionFact.createTopicConnection();
        DebugMessages.ok();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Creating public session object ");
        publishSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        DebugMessages.ok();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Creating subscribe object ");
        subscribeSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        DebugMessages.ok();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Setting up reading topic ");
        connectionTopic = (Topic) initConn.lookup(topic);
        tSub = subscribeSession.createSubscriber(connectionTopic, null, true);
        DebugMessages.ok();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Setting up destination topic ");
        connectionTopic = publishSession.createTopic(this.topic);
        tPub = publishSession.createPublisher(connectionTopic);
        DebugMessages.ok();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Reading knowledge base ");
        knowledgeBase = createKnowledgeBase();
        ksession = knowledgeBase.newStatefulKnowledgeSession();
        ksession.setGlobal("EVENTS EntryPoint", eventStream);
        eventStream = ksession.getWorkingMemoryEntryPoint("DEFAULT");
        cepRuleManager = new DroolsRulesManager(knowledgeBuilder, knowledgeBase, ksession);
        DebugMessages.ok();

    } catch (JMSException e) {
        DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), e.getMessage());
    } catch (NamingException e) {
        DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), e.getMessage());
    }
}

From source file:eu.learnpad.simulator.mon.manager.GlimpseManager.java

public void setupConnection(TopicConnectionFactory connectionFact, InitialContext initConn) {
    try {/* ww w .  ja v a  2s  .  com*/
        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Creating connection object ");
        connection = connectionFact.createTopicConnection();
        DebugMessages.ok();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Creating public session object ");
        publishSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        DebugMessages.ok();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Creating subscribe object");
        subscribeSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        DebugMessages.ok();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Setting up destination topic ");
        connectionTopic = (Topic) initConn.lookup(serviceTopic);
        tPub = publishSession.createPublisher(connectionTopic);
        DebugMessages.ok();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Setting up reading topic ");
        tSub = subscribeSession.createSubscriber(connectionTopic, "DESTINATION = 'monitor'", true);
        tSub.setMessageListener(this);
        DebugMessages.ok();

        DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(),
                "Creating response dispatcher ");
        responder = new ResponseDispatcher(initConn, connectionFact, requestMap, learnerAssessmentManager);
        if (responder != null)
            DebugMessages.ok();

    } catch (JMSException e) {
        e.printStackTrace();
    } catch (NamingException e) {
        e.printStackTrace();
    }
}