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);
}
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();
}
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();
}
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;
}
}
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;
}
}
Aggregations