Example usage for javax.jms Session getAcknowledgeMode

List of usage examples for javax.jms Session getAcknowledgeMode

Introduction

In this page you can find the example usage for javax.jms Session getAcknowledgeMode.

Prototype

int getAcknowledgeMode() throws JMSException;

Source Link

Document

Returns the acknowledgement mode of the session.

Usage

From source file:org.apache.qpid.disttest.jms.ClientJmsDelegate.java

public void createSession(final CreateSessionCommand command) {
    try {/*  w w w .j  a  va 2 s  . c o m*/
        final Connection connection = _testConnections.get(command.getConnectionName());
        if (connection == null) {
            throw new DistributedTestException(
                    "No test connection found called: " + command.getConnectionName(), command);
        }
        final boolean transacted = command.getAcknowledgeMode() == Session.SESSION_TRANSACTED;

        final Session newSession = connection.createSession(transacted, command.getAcknowledgeMode());
        LOGGER.debug("Created session " + command.getSessionName() + " with transacted = "
                + newSession.getTransacted() + " and acknowledgeMode = " + newSession.getAcknowledgeMode());

        addSession(command.getSessionName(), newSession);
    } catch (final JMSException jmse) {
        throw new DistributedTestException("Unable to create new session: " + command, jmse);
    }
}

From source file:org.apache.qpid.disttest.jms.ClientJmsDelegate.java

public int getAcknowledgeMode(final String sessionName) {
    try {//from  www.  ja v  a  2  s .  c  o m
        final Session session = _testSessions.get(sessionName);
        return session.getAcknowledgeMode();
    } catch (final JMSException jmse) {
        throw new DistributedTestException(
                "Unable to determine acknowledgement mode for session: " + sessionName, jmse);
    }
}

From source file:org.apache.qpid.disttest.jms.ClientJmsDelegate.java

public void commitOrAcknowledgeMessageIfNecessary(final String sessionName, final Message message) {
    try {// w w  w . j  a v  a 2s . c o  m
        final Session session = _testSessions.get(sessionName);
        if (session.getTransacted()) {
            synchronized (session) {
                session.commit();
            }
        } else if (message != null && session.getAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE) {
            message.acknowledge();
        }
    } catch (final JMSException jmse) {
        throw new DistributedTestException("Unable to commit or acknowledge message on session: " + sessionName,
                jmse);
    }
}

From source file:org.apache.qpid.disttest.jms.ClientJmsDelegate.java

public void rollbackOrRecoverIfNecessary(String sessionName) {
    try {/*from w w w  . ja  va  2  s . c o  m*/
        final Session session = _testSessions.get(sessionName);
        synchronized (session) {
            if (session.getTransacted()) {
                session.rollback();
            } else if (session.getAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE) {
                session.recover();
            }
        }
    } catch (final JMSException jmse) {
        throw new DistributedTestException("Unable to rollback or recover on session: " + sessionName, jmse);
    }
}

From source file:org.codehaus.stomp.jms.ProtocolConverter.java

protected void onStompConnect(StompFrame command) throws IOException, JMSException {
    if (noneXaSession != null) {
        throw new ProtocolException("Already connected.");
    }/*  w w  w . j ava  2  s . c  o m*/

    Map<String, Object> headers = command.getHeaders();
    login = (String) headers.get(Stomp.Headers.Connect.LOGIN);
    passcode = (String) headers.get(Stomp.Headers.Connect.PASSCODE);
    clientId = (String) headers.get(Stomp.Headers.Connect.CLIENT_ID);

    Connection noneXaConnection;
    if (login != null) {
        noneXaConnection = noneXAConnectionFactory.createConnection(login, passcode);
    } else {
        noneXaConnection = noneXAConnectionFactory.createConnection();
    }
    if (clientId != null) {
        noneXaConnection.setClientID(clientId);
    }

    noneXaConnection.start();

    Session session = noneXaConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    if (log.isDebugEnabled()) {
        log.debug("Created session with ack mode: " + session.getAcknowledgeMode());
    }
    this.noneXaSession = new StompSession(initialContext, this, session, noneXaConnection);

    Map<String, Object> responseHeaders = new HashMap<String, Object>();

    responseHeaders.put(Stomp.Headers.Connected.SESSION, clientId);
    String requestId = (String) headers.get(Stomp.Headers.Connect.REQUEST_ID);
    if (requestId == null) {
        // TODO legacy
        requestId = (String) headers.get(Stomp.Headers.RECEIPT_REQUESTED);
    }
    if (requestId != null) {
        // TODO legacy
        responseHeaders.put(Stomp.Headers.Connected.RESPONSE_ID, requestId);
        responseHeaders.put(Stomp.Headers.Response.RECEIPT_ID, requestId);
    }

    StompFrame sc = new StompFrame();
    sc.setAction(Stomp.Responses.CONNECTED);
    sc.setHeaders(responseHeaders);
    sendToStomp(sc);
}

From source file:org.springframework.jms.core.JmsTemplate.java

protected boolean isClientAcknowledge(Session session) throws JMSException {
    return (session.getAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE);
}

From source file:org.springframework.jms.support.JmsAccessor.java

/**
 * Determine whether the given Session is in client acknowledge mode.
 * <p>This implementation uses JMS 1.1 API.
 * @param session the JMS Session to check
 * @return whether the given Session is in client acknowledge mode
 * @throws javax.jms.JMSException if thrown by JMS API methods
 * @see javax.jms.Session#getAcknowledgeMode()
 * @see javax.jms.Session#CLIENT_ACKNOWLEDGE
 *///w w w  .  j  ava2s . com
protected boolean isClientAcknowledge(Session session) throws JMSException {
    return (session.getAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE);
}