Package org.apache.activemq

Examples of org.apache.activemq.ActiveMQSession


        broker.addConnector(url);
        broker.start();

        ActiveMQConnectionFactory connFac = new ActiveMQConnectionFactory(url);
        Connection conn = connFac.createConnection();
        ActiveMQSession session = (ActiveMQSession)conn.createSession(true, Session.AUTO_ACKNOWLEDGE);
        queue = session.createQueue("CheckAccounts");
        MessageProducer producer = session.createProducer(queue);
        MapMessage map = session.createMapMessage();

        for (int i = 0; i < 3; i++) {
            String accountNumber = "C00" + (i + 1);
            float balance = (float)(1000.0 + Math.random() * 200.0);
            map.setStringProperty("accountNumber", accountNumber);
            map.setFloatProperty("balance", balance);

            map.setString("accountNumber", accountNumber);
            map.setFloat("balance", balance);

            producer.send(map);
        }
        session.commit();
        conn.close();
    }
View Full Code Here


    protected void save(String accountNumber, float balance) throws AccountNotFoundException {
        try {
            ActiveMQConnectionFactory connFac = new ActiveMQConnectionFactory(url);
            Connection conn = connFac.createConnection();
            conn.start();
            ActiveMQSession session = (ActiveMQSession)conn.createSession(true, Session.AUTO_ACKNOWLEDGE);
            MessageConsumer consumer = session.createConsumer(queue, "accountNumber = '" + accountNumber + "'");
            Message msg = consumer.receive(1000);
            if (msg == null) {
                conn.close();
                throw new AccountNotFoundException(accountNumber);
            }
            MapMessage map = session.createMapMessage();
            map.setStringProperty("accountNumber", accountNumber);
            map.setFloatProperty("balance", balance);

            map.setString("accountNumber", accountNumber);
            map.setFloat("balance", balance);

            MessageProducer producer = session.createProducer(queue);
            producer.send(map);
            conn.close();

        } catch (JMSException e) {
            throw new ServiceRuntimeException(e);
View Full Code Here

        broker.addConnector(url);
        broker.start();

        ActiveMQConnectionFactory connFac = new ActiveMQConnectionFactory(url);
        Connection conn = connFac.createConnection();
        ActiveMQSession session = (ActiveMQSession)conn.createSession(true, Session.AUTO_ACKNOWLEDGE);
        queue = session.createQueue("CheckAccounts");
        MessageProducer producer = session.createProducer(queue);
        MapMessage map = session.createMapMessage();

        for (int i = 0; i < 3; i++) {
            String accountNumber = "C00" + (i + 1);
            float balance = (float)(1000.0 + Math.random() * 200.0);
            map.setStringProperty("accountNumber", accountNumber);
            map.setFloatProperty("balance", balance);

            map.setString("accountNumber", accountNumber);
            map.setFloat("balance", balance);

            producer.send(map);
        }
        session.commit();
        conn.close();
    }
View Full Code Here

    protected void save(String accountNumber, float balance) throws AccountNotFoundException {
        try {
            ActiveMQConnectionFactory connFac = new ActiveMQConnectionFactory(url);
            Connection conn = connFac.createConnection();
            conn.start();
            ActiveMQSession session = (ActiveMQSession)conn.createSession(true, Session.AUTO_ACKNOWLEDGE);
            MessageConsumer consumer = session.createConsumer(queue, "accountNumber = '" + accountNumber + "'");
            Message msg = consumer.receive(1000);
            if (msg == null) {
                conn.close();
                throw new AccountNotFoundException(accountNumber);
            }
            MapMessage map = session.createMapMessage();
            map.setStringProperty("accountNumber", accountNumber);
            map.setFloatProperty("balance", balance);

            map.setString("accountNumber", accountNumber);
            map.setFloat("balance", balance);

            MessageProducer producer = session.createProducer(queue);
            producer.send(map);
            conn.close();

        } catch (JMSException e) {
            throw new ServiceRuntimeException(e);
View Full Code Here

    }

    private ServerSessionImpl createServerSessionImpl() throws JMSException {
        ActiveMQActivationSpec activationSpec = activeMQAsfEndpointWorker.endpointActivationKey.getActivationSpec();
        int acknowledge = (activeMQAsfEndpointWorker.transacted) ? Session.SESSION_TRANSACTED : activationSpec.getAcknowledgeModeForSession();
        final ActiveMQSession session = (ActiveMQSession) activeMQAsfEndpointWorker.connection.createSession(activeMQAsfEndpointWorker.transacted,acknowledge);           
        MessageEndpoint endpoint;
        try {               
            int batchSize = 0;
            if (activationSpec.getEnableBatchBooleanValue()) {
                batchSize = activationSpec.getMaxMessagesPerBatchIntValue();
            }
            if( activationSpec.isUseRAManagedTransactionEnabled() ) {
                // The RA will manage the transaction commit.
                endpoint = createEndpoint(null);  
                return new ServerSessionImpl(this, (ActiveMQSession)session, activeMQAsfEndpointWorker.workManager, endpoint, true, batchSize);
            } else {
                // Give the container an object to manage to transaction with.
                endpoint = createEndpoint(new LocalAndXATransaction(session.getTransactionContext()));               
                return new ServerSessionImpl(this, (ActiveMQSession)session, activeMQAsfEndpointWorker.workManager, endpoint, false, batchSize);
            }
        } catch (UnavailableException e) {
            // The container could be limiting us on the number of endpoints
            // that are being created.
            log.debug("Could not create an endpoint.", e);
            session.close();
            return null;
        }
    }
View Full Code Here

     */
    private void dispatchToSession(MessageDispatch messageDispatch) throws JMSException {

        ServerSession serverSession = getServerSession();
        Session s = serverSession.getSession();
        ActiveMQSession session = null;
        if( s instanceof ActiveMQSession ) {
            session = (ActiveMQSession) s;
        } else if(s instanceof ActiveMQQueueSession) {
            session = (ActiveMQSession) s;
        } else if(s instanceof ActiveMQTopicSession) {
            session = (ActiveMQSession) s;
        } else {
          activeMQAsfEndpointWorker.connection.onAsyncException(new JMSException("Session pool provided an invalid session type: "+s.getClass()));
        }
        session.dispatch(messageDispatch);
        serverSession.start();
    }
View Full Code Here

    }

     public void removeFromPool(ServerSessionImpl ss) {
        activeSessions.remove(ss);
        try {
            ActiveMQSession session = (ActiveMQSession) ss.getSession();
            List l = session.getUnconsumedMessages();
            for (Iterator i = l.iterator(); i.hasNext();) {
                dispatchToSession((MessageDispatch) i.next());             
            }
        } catch (Throwable t) {
            log.error("Error redispatching unconsumed messages from stale session", t);     
View Full Code Here

     * @param transacted
     * @return
     * @throws JMSException
     */
    private ManagedSessionProxy createSessionProxy(boolean transacted, int acknowledgeMode) throws JMSException {       
        ActiveMQSession session = (ActiveMQSession) getConnection().createSession(transacted, acknowledgeMode);
        ManagedTransactionContext txContext = new ManagedTransactionContext(managedConnection.getTransactionContext());
        session.setTransactionContext(txContext);       
        ManagedSessionProxy p = new ManagedSessionProxy(session);       
        p.setUseSharedTxContext(managedConnection.isInManagedTx());
        sessions.add(p);       
        return p;
    }
View Full Code Here

        final AtomicInteger counter = new AtomicInteger(0);
        final CountDownLatch done = new CountDownLatch(1);

        // Receive a message with the JMS API
        connection.start();
        ActiveMQSession session = (ActiveMQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        destination = createDestination(session, destinationType);
        MessageConsumer consumer = session.createConsumer(destination, new MessageListener() {
            public void onMessage(Message m) {
                counter.incrementAndGet();
                if (counter.get() == 4) {
                    done.countDown();
                }
View Full Code Here

        broker.addConnector(url);
        broker.start();

        ActiveMQConnectionFactory connFac = new ActiveMQConnectionFactory(url);
        Connection conn = connFac.createConnection();
        ActiveMQSession session = (ActiveMQSession)conn.createSession(true, Session.AUTO_ACKNOWLEDGE);
        queue = session.createQueue("CheckAccounts");
        MessageProducer producer = session.createProducer(queue);
        MapMessage map = session.createMapMessage();

        for (int i = 0; i < 3; i++) {
            String accountNumber = "C00" + (i + 1);
            float balance = (float)(1000.0 + Math.random() * 200.0);
            map.setStringProperty("accountNumber", accountNumber);
            map.setFloatProperty("balance", balance);

            map.setString("accountNumber", accountNumber);
            map.setFloat("balance", balance);

            producer.send(map);
        }
        session.commit();
        conn.close();
    }
View Full Code Here

TOP

Related Classes of org.apache.activemq.ActiveMQSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.