use of com.sun.messaging.jmq.jmsserver.service.Connection in project openmq by eclipse-ee4j.
the class Consumer method getClientID.
public String getClientID() {
ConnectionUID cuid = getConnectionUID();
if (cuid == null) {
return "<unknown>";
}
Connection con = Globals.getConnectionManager().getConnection(cuid);
return (String) con.getClientData(IMQConnection.CLIENT_ID);
}
use of com.sun.messaging.jmq.jmsserver.service.Connection in project openmq by eclipse-ee4j.
the class Session method detatchConsumer.
/**
* @param id last SysMessageID seen (null indicates all have been seen)
* @param redeliverAll ignore id and redeliver all
* @param redeliverPendingConsume - redeliver pending messages
*/
private void detatchConsumer(ConsumerSpi con, SysMessageID id, boolean idInTransaction, boolean redeliverPendingConsume, boolean redeliverAll) {
if (DEBUG) {
logger.log(Logger.INFO, "Detaching Consumer " + con.getConsumerUID() + " on connection " + con.getConnectionUID() + " from Session " + uid + " last id was " + id);
}
con.pause("Consumer.java: Detatch consumer 1 " + con);
pause("Consumer.java: Detatch consumer A " + con);
ConsumerUID c = con.getConsumerUID();
// ConsumerUID sid = con.getStoredConsumerUID();
Object listener = listeners.remove(c);
assert listener != null;
con.removeEventListener(listener);
con.attachToSession(null);
busyConsumers.remove(c);
consumers.remove(c);
checkState(null);
Connection conn = Globals.getConnectionManager().getConnection(getConnectionUID());
if (ssop.detachConsumer(con, id, idInTransaction, redeliverPendingConsume, redeliverAll, conn)) {
synchronized (consumerToSession) {
consumerToSession.remove(c);
}
}
resume("Consumer.java: resuming after detatch " + con);
}
use of com.sun.messaging.jmq.jmsserver.service.Connection in project openmq by eclipse-ee4j.
the class HelloHandler method DUMP.
public static void DUMP(String title) {
Globals.getLogger().log(Logger.DEBUG, title);
Globals.getLogger().log(Logger.DEBUG, "------------------------");
Globals.getLogger().log(Logger.DEBUG, "Number of connections is " + Globals.getConnectionManager().getNumConnections(null));
List l = Globals.getConnectionManager().getConnectionList(null);
for (int i = 0; i < l.size(); i++) {
Connection c = (Connection) l.get(i);
Globals.getLogger().log(Logger.DEBUG, "\t" + i + "\t" + c.getConnectionUID() + " :" + c.getRemoteConnectionString());
}
Globals.getLogger().log(Logger.DEBUG, "------------------------");
}
use of com.sun.messaging.jmq.jmsserver.service.Connection in project openmq by eclipse-ee4j.
the class ClientIDHandler method setClientID.
public void setClientID(IMQConnection con, String cclientid, String namespace, boolean shared) throws BrokerException {
int status = Status.OK;
String reason = null;
try {
// validate and expand the specified clientID
String clientid = cclientid == null ? null : validate(cclientid, con);
// retrieve the old client id
String oldid = (String) con.getClientData(IMQConnection.CLIENT_ID);
if (DEBUG && oldid != null) {
logger.log(Logger.DEBUG, "ClientIDHandler: replacing clientID " + oldid + " with " + clientid);
}
if (clientid != null && (oldid == null || !oldid.equals(clientid))) {
if (namespace != null) {
// a namespace was specified
// lock the combination of namespace and clientID
String unspace = namespace + "${%%}" + clientid;
int lockstatus = Globals.getClusterBroadcast().lockClientID(unspace, con.getConnectionUID(), false);
if (lockstatus != ClusterBroadcast.LOCK_SUCCESS) {
if (lockstatus == ClusterBroadcast.LOCK_TIMEOUT) {
String emsg = Globals.getBrokerResources().getKString(BrokerResources.X_CLUSTER_CLIENTID_LOCK_REQUEST_TIMEOUT, unspace, con.getRemoteConnectionString());
logger.log(Logger.INFO, emsg);
status = Status.TIMEOUT;
throw new BrokerException(emsg, status);
} else {
// namespace/clientID combination already in use
logger.log(Logger.INFO, BrokerResources.I_CLIENT_ID_IN_USE, con.getRemoteConnectionString(), unspace);
Connection owner = Globals.getConnectionManager().matchProperty(IMQConnection.CLIENT_ID, unspace);
assert owner == null || owner instanceof IMQConnection;
if (owner == null) {
// remote
logger.log(Logger.INFO, BrokerResources.I_RMT_CID_OWNER, unspace);
} else {
logger.log(Logger.INFO, BrokerResources.I_LOCAL_CID_OWNER, unspace, ((IMQConnection) owner).getRemoteConnectionString());
}
reason = "conflict w/ clientID";
status = Status.CONFLICT;
throw new BrokerException(reason, status);
}
}
}
// now lock the clientID itself (whether shared or unshared)
int lockstatus = Globals.getClusterBroadcast().lockClientID(clientid, con.getConnectionUID(), shared);
if (lockstatus != ClusterBroadcast.LOCK_SUCCESS) {
if (lockstatus == ClusterBroadcast.LOCK_TIMEOUT) {
String emsg = Globals.getBrokerResources().getKString(BrokerResources.X_CLUSTER_CLIENTID_LOCK_REQUEST_TIMEOUT, clientid, con.getRemoteConnectionString());
logger.log(Logger.INFO, emsg);
status = Status.TIMEOUT;
throw new BrokerException(emsg, status);
} else {
logger.log(Logger.INFO, BrokerResources.I_CLIENT_ID_IN_USE, con.getRemoteConnectionString(), clientid);
Connection owner = Globals.getConnectionManager().matchProperty(IMQConnection.CLIENT_ID, clientid);
assert owner == null || owner instanceof IMQConnection;
if (owner == null) {
// remote
logger.log(Logger.INFO, BrokerResources.I_RMT_CID_OWNER, clientid);
} else {
logger.log(Logger.INFO, BrokerResources.I_LOCAL_CID_OWNER, clientid, ((IMQConnection) owner).getRemoteConnectionString());
}
reason = "conflict w/ clientID";
status = Status.CONFLICT;
throw new BrokerException(reason, status);
}
}
} else if (oldid != null && !oldid.equals(clientid)) {
/**
* we are explicitly clearing an old clientID unlock the old namespace/clientID combination (assume specified namespace
* is the same as the old one)
*/
String oldunspace = namespace + "${%%}" + oldid;
logger.log(Logger.DEBUG, "ClientIDHandler: " + "removing old namespace/clientID " + oldunspace);
Globals.getClusterBroadcast().unlockClientID(oldunspace, con.getConnectionUID());
// unlock the old clientID
logger.log(Logger.DEBUG, "ClientIDHandler: " + "removing old clientID " + oldid);
Globals.getClusterBroadcast().unlockClientID(oldid, con.getConnectionUID());
// remove the specified clientID from the connection
con.removeClientData(IMQConnection.CLIENT_ID);
}
// save the specified clientID with the connection
if (clientid != null && status != Status.CONFLICT) {
con.addClientData(IMQConnection.CLIENT_ID, clientid);
}
} catch (BrokerException ex) {
if (ex.getStatusCode() == Status.CONFLICT) {
throw ex;
}
if (ex.getStatusCode() == Status.TIMEOUT) {
throw ex;
}
logger.log(Logger.WARNING, BrokerResources.W_CLIENT_ID_INVALID, cclientid, con.toString(), ex);
status = Status.BAD_REQUEST;
reason = ex.getMessage();
throw new BrokerException(reason, ex, status);
} catch (OutOfMemoryError err) {
// throw so it is handled by higher-level memory handling code
throw err;
} catch (Throwable thr) {
logger.log(Logger.WARNING, "unexpected error processing clientid ", thr);
reason = thr.getMessage();
status = Status.ERROR;
throw new BrokerException(reason, thr, status);
}
}
use of com.sun.messaging.jmq.jmsserver.service.Connection 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();
}
Aggregations