Package javax.jms

Examples of javax.jms.ConnectionConsumer


        final TopicConnection connection = connectionFactory.createTopicConnection();
        connection.setClientID("TestClient");
        connection.start();
        final TestServerSessionPool pool = new TestServerSessionPool(connection);
        final ConnectionConsumer connectionConsumer = connection.createDurableConnectionConsumer(topic, "TestSubscriber", null, pool, 1);
        while (true) {
            int lastMsgCount = 0;
            int msgCount = 0;
            do {
                lastMsgCount = msgCount;
                Thread.sleep(200L);
                synchronized (processedSessions) {
                    msgCount = processedSessions.size();
                }
            } while (lastMsgCount < msgCount);

            if (lastMsgCount == 0) {
                break;
            }

            final LinkedList<TestServerSession> collected;
            synchronized (processedSessions) {
                collected = new LinkedList<TestServerSession>(processedSessions);
                processedSessions.clear();
            }

            final Iterator<TestServerSession> sessions = collected.iterator();
            while (sessions.hasNext()) {
                final TestServerSession session = sessions.next();
                committedSessions.add(session);
                session.getSession().commit();
                session.getSession().close();
            }
        }

        connectionConsumer.close();
        final TopicSession finalSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        finalSession.unsubscribe("TestSubscriber");
        finalSession.close();
        connection.close();
        assertEquals(MESSAGE_COUNT, committedSessions.size());
View Full Code Here

TOP

Related Classes of javax.jms.ConnectionConsumer

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.