Search in sources :

Example 1 with StompProtocolException

use of com.sun.messaging.bridge.api.StompProtocolException in project openmq by eclipse-ee4j.

the class StompConnectionImpl method beginTransactedSession.

/**
 */
@Override
public synchronized void beginTransactedSession(String tid) throws Exception {
    Connection conn = _connection;
    checkConnection(conn);
    if (tid == null) {
        throw new IllegalArgumentException("Unexpected call: null transaction id");
    }
    if (_txSession == null) {
        _txSession = new StompTransactedSession(this);
    }
    String currtid = _txSession.getStompTransactionId();
    if (currtid != null) {
        throw new StompProtocolException(_sbr.getKString(_sbr.X_NESTED_TXN_NOT_ALLOWED, currtid, tid));
    }
    _txSession.setStompTransactionId(tid);
}
Also used : StompConnection(com.sun.messaging.bridge.api.StompConnection) StompProtocolException(com.sun.messaging.bridge.api.StompProtocolException)

Example 2 with StompProtocolException

use of com.sun.messaging.bridge.api.StompProtocolException in project openmq by eclipse-ee4j.

the class StompConnectionImpl method abortTransactedSession.

/**
 */
@Override
public synchronized void abortTransactedSession(String tid) throws Exception {
    Connection conn = _connection;
    checkConnection(conn);
    if (tid == null) {
        throw new IllegalArgumentException("Unexpected call: null transaction id");
    }
    if (_txSession == null) {
        throw new StompProtocolException(_sbr.getKString(_sbr.X_TXN_NO_SESSION, tid));
    }
    String currtid = _txSession.getStompTransactionId();
    String lastrb = _txSession.getLastRolledbackStompTransactionId();
    if (currtid == null && lastrb != null && lastrb.equals(tid)) {
        _logger.log(Level.INFO, _sbr.getString(_sbr.I_TXN_ALREADY_ROLLEDBACK, tid));
        return;
    }
    if (currtid == null || !currtid.equals(tid)) {
        throw new StompProtocolException(_sbr.getKString(_sbr.X_TXN_NOT_FOUND, tid) + (currtid == null ? "" : " " + _sbr.getString(_sbr.I_CURRENT_TXN, currtid)));
    }
    _txSession.rollback();
}
Also used : StompConnection(com.sun.messaging.bridge.api.StompConnection) StompProtocolException(com.sun.messaging.bridge.api.StompProtocolException)

Example 3 with StompProtocolException

use of com.sun.messaging.bridge.api.StompProtocolException in project openmq by eclipse-ee4j.

the class StompConnectionImpl method commitTransactedSession.

/**
 */
@Override
public synchronized void commitTransactedSession(String tid) throws Exception {
    Connection conn = _connection;
    checkConnection(conn);
    if (tid == null) {
        throw new IllegalArgumentException("Unexpected call: null transaction id");
    }
    if (_txSession == null) {
        throw new StompProtocolException(_sbr.getKString(_sbr.X_TXN_NO_SESSION, tid));
    }
    String currtid = _txSession.getStompTransactionId();
    if (currtid == null || !currtid.equals(tid)) {
        throw new StompProtocolException(_sbr.getKString(_sbr.X_TXN_NOT_FOUND, tid) + (currtid == null ? "" : " " + _sbr.getString(_sbr.I_CURRENT_TXN, currtid)));
    }
    _txSession.commit();
}
Also used : StompConnection(com.sun.messaging.bridge.api.StompConnection) StompProtocolException(com.sun.messaging.bridge.api.StompProtocolException)

Example 4 with StompProtocolException

use of com.sun.messaging.bridge.api.StompProtocolException in project openmq by eclipse-ee4j.

the class StompTransactedSession method createSubscriber.

public StompSubscriber createSubscriber(String subid, StompDestination d, String selector, String duraname, boolean nolocal, StompOutputHandler out) throws Exception {
    checkSession();
    synchronized (this) {
        if (subscribers.get(subid) != null) {
            throw new StompProtocolException("Subscriber " + subid + " already exist in transacted session " + this);
        }
        String stompdest = stompconn.getProtocolHandler().toStompFrameDestination(d, false);
        Destination dest = ((StompDestinationImpl) d).getDestination();
        JMSServiceReply reply = null;
        try {
            reply = jmsservice.createDestination(connectionId, dest);
        } catch (JMSServiceException jmsse) {
            JMSServiceReply.Status status = jmsse.getJMSServiceReply().getStatus();
            if (status == JMSServiceReply.Status.CONFLICT) {
                if (getDEBUG()) {
                    logger.log(logger.INFO, "Destination " + stompdest + " already exist");
                }
            } else {
                throw jmsse;
            }
        }
        reply = jmsservice.startConnection(connectionId);
        reply = jmsservice.addConsumer(connectionId, sessionId, dest, selector, duraname, (duraname != null), false, false, stompconn.getClientID(), nolocal);
        long consumerId = reply.getJMQConsumerID();
        TransactedSubscriber sub = new TransactedSubscriber(subid, consumerId, duraname, stompdest, out);
        subscribers.put(subid, sub);
        return sub;
    }
}
Also used : Destination(com.sun.messaging.jmq.jmsservice.Destination) StompDestination(com.sun.messaging.bridge.api.StompDestination) JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) StompProtocolException(com.sun.messaging.bridge.api.StompProtocolException)

Example 5 with StompProtocolException

use of com.sun.messaging.bridge.api.StompProtocolException in project openmq by eclipse-ee4j.

the class StompTransactedSession method ack.

public void ack(String subid, String msgid, boolean nack) throws Exception {
    checkSession();
    String cmd = (nack ? "NACK " : "ACK ");
    synchronized (this) {
        if (getStompTransactionId() == null) {
            throw new StompProtocolException("Transacted " + cmd + "[" + subid + ", " + msgid + "] no current transaction");
        }
        TransactedSubscriber sub = subscribers.get(subid);
        if (sub == null) {
            throw new StompProtocolException("Subscription " + subid + " not found to transacted " + cmd + " message " + msgid);
        }
        SysMessageID sysid = SysMessageID.get(msgid);
        SubscribedMessage sm = new SubscribedMessage(subid, sysid);
        int index = unackqueue.indexOf(sm);
        if (index == -1) {
            throw new StompProtocolException("Message " + msgid + " for subscription " + subid + " not found in transaction " + tid);
        }
        ArrayList<SubscribedMessage> acks = new ArrayList<>();
        if (nack) {
            acks.add(sm);
        } else {
            for (int i = 0; i <= index; i++) {
                sm = unackqueue.get(i);
                if (sm.subid.equals(subid)) {
                    acks.add(sm);
                }
            }
        }
        Iterator<SubscribedMessage> itr = acks.iterator();
        while (itr.hasNext()) {
            sm = itr.next();
            if (!nack) {
                jmsservice.acknowledgeMessage(connectionId, sessionId, sm.consumerId, sm.sysid, transactionId, MessageAckType.ACKNOWLEDGE);
            } else {
                jmsservice.acknowledgeMessage(connectionId, sessionId, sm.consumerId, sm.sysid, transactionId, MessageAckType.DEAD, 1, "STOMP:NACK", null);
            }
            unackqueue.remove(sm);
        }
        return;
    }
}
Also used : ArrayList(java.util.ArrayList) SysMessageID(com.sun.messaging.jmq.io.SysMessageID) StompProtocolException(com.sun.messaging.bridge.api.StompProtocolException)

Aggregations

StompProtocolException (com.sun.messaging.bridge.api.StompProtocolException)10 StompConnection (com.sun.messaging.bridge.api.StompConnection)5 JMSServiceReply (com.sun.messaging.jmq.jmsservice.JMSServiceReply)3 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)2 ArrayList (java.util.ArrayList)2 StompDestination (com.sun.messaging.bridge.api.StompDestination)1 Connection (com.sun.messaging.jmq.jmsserver.service.Connection)1 ConnectionUID (com.sun.messaging.jmq.jmsserver.service.ConnectionUID)1 Destination (com.sun.messaging.jmq.jmsservice.Destination)1 JMSServiceException (com.sun.messaging.jmq.jmsservice.JMSServiceException)1 StringTokenizer (java.util.StringTokenizer)1