use of com.sun.messaging.bridge.api.StompProtocolException in project openmq by eclipse-ee4j.
the class StompConnectionImpl method connect.
/**
* @return the connection id
*/
@Override
public synchronized String connect(String login, String passcode, String clientid) throws Exception {
this.clientID = clientid;
if (connectionID != null) {
throw new jakarta.jms.IllegalStateException("Unexpected " + StompFrameMessage.Command.CONNECT + ", already connected");
}
JMSServiceReply reply = jmsservice.createConnection(login, passcode);
long connid = reply.getJMQConnectionID();
connectionID = Long.valueOf(connid);
closed = false;
Connection conn = Globals.getConnectionManager().getConnection(new ConnectionUID(connid));
if (conn != null) {
conn.addConnectionClosedListener(this);
} else {
throw new StompProtocolException("No connection");
}
jmsservice.setClientId(connid, clientid, false, /* share */
null);
jmsservice.startConnection(connid);
return connectionID.toString();
}
use of com.sun.messaging.bridge.api.StompProtocolException in project openmq by eclipse-ee4j.
the class StompSubscriberSession method ack.
public void ack(String msgid, boolean nack) throws Exception {
checkSession();
String cmd = (nack ? "[NACK]" : "[ACK]");
long conid = consumerId;
if (conid == 0L) {
throw new StompProtocolException("Can't " + cmd + msgid + " because the subscriber " + subid + "is closed");
}
SysMessageID sysid = null;
try {
sysid = SysMessageID.get(msgid);
} catch (RuntimeException e) {
throw new StompProtocolException(cmd + "invalid message-id" + e.getMessage(), e);
}
List<SysMessageID> list = new ArrayList<>();
synchronized (unackedMessages) {
int index = unackedMessages.indexOf(sysid);
if (index < 0) {
String emsg = cmd + br.getKString(br.X_STOMP_MSG_NOTFOUND_ON_ACK, msgid, this.toString());
throw new StompProtocolException(emsg);
}
if (clientackThisMessage || nack) {
list.add(sysid);
} else {
SysMessageID tmpsysid = null;
for (int i = 0; i <= index; i++) {
tmpsysid = unackedMessages.get(i);
list.add(tmpsysid);
}
}
}
if (logger.isFineLoggable() || stompconn.getDEBUG()) {
logger.logInfo(cmd + list.size() + " messages for subscriber " + subid + " on connection " + stompconn, null);
}
Iterator<SysMessageID> itr = list.iterator();
SysMessageID tmpsysid = null;
while (itr.hasNext()) {
tmpsysid = itr.next();
if (logger.isFinestLoggable() || stompconn.getDEBUG()) {
logger.logInfo(cmd + "message " + tmpsysid + " for subscriber " + subid + " on connection " + stompconn, null);
}
if (!nack) {
jmsservice.acknowledgeMessage(connectionId, sessionId, consumerId, tmpsysid, 0L, MessageAckType.ACKNOWLEDGE, 0);
} else {
jmsservice.acknowledgeMessage(connectionId, sessionId, consumerId, tmpsysid, 0L, MessageAckType.DEAD, 1, "STOMP:NACK", null);
}
unackedMessages.remove(tmpsysid);
}
}
use of com.sun.messaging.bridge.api.StompProtocolException in project openmq by eclipse-ee4j.
the class StompProtocolHandlerImpl method negotiateVersion.
@Override
public String negotiateVersion(String acceptVersions) throws StompProtocolException {
if (acceptVersions == null) {
throw new StompProtocolException(br.getKString(br.X_STOMP_PROTOCOL_VERSION_NO_SUPPORT, StompFrameMessage.STOMP_PROTOCOL_VERSION_10));
}
StringTokenizer st = new StringTokenizer(acceptVersions, ",");
String ver = null;
while (st.hasMoreElements()) {
ver = st.nextToken();
if (Version.compareVersions(ver, StompFrameMessage.STOMP_PROTOCOL_VERSION_12) == 0) {
return StompFrameMessage.STOMP_PROTOCOL_VERSION_12;
}
}
throw new StompProtocolException(br.getKString(br.X_STOMP_PROTOCOL_VERSION_NO_SUPPORT, acceptVersions));
}
use of com.sun.messaging.bridge.api.StompProtocolException in project openmq by eclipse-ee4j.
the class StompConnectionImpl method createSubscriberSession.
/**
*/
private synchronized StompSubscriberSession createSubscriberSession(String subid, StompAckMode ackMode) throws Exception {
Connection conn = _connection;
checkConnection(conn);
if (subid == null) {
throw new IllegalArgumentException("No subscription id");
}
StompSubscriberSession ss = _subSessions.get(subid);
if (ss != null) {
throw new StompProtocolException(_sbr.getKString(_sbr.X_SUBSCRIBER_ID_EXIST, subid));
}
ss = new StompSubscriberSession(subid, ackMode, this);
_subSessions.put(subid, ss);
return ss;
}
use of com.sun.messaging.bridge.api.StompProtocolException in project openmq by eclipse-ee4j.
the class StompTransactedSession method begin.
public void begin(String stomptid) throws Exception {
checkSession();
synchronized (this) {
if (getDEBUG()) {
logger.log(logger.INFO, "Begin transaction " + stomptid + " in [" + this + "]");
}
if (tid != null) {
throw new StompProtocolException("Transaction session has current transaction " + tid);
}
JMSServiceReply reply = jmsservice.startTransaction(connectionId, sessionId, null, 0, TransactionAutoRollback.UNSPECIFIED, 0L);
transactionId = reply.getJMQTransactionID();
setStompTransactionId(stomptid);
}
}
Aggregations