Search in sources :

Example 1 with Connection

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);
}
Also used : Connection(com.sun.messaging.jmq.jmsserver.service.Connection) IMQConnection(com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection) ConnectionUID(com.sun.messaging.jmq.jmsserver.service.ConnectionUID)

Example 2 with Connection

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);
}
Also used : Connection(com.sun.messaging.jmq.jmsserver.service.Connection)

Example 3 with Connection

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, "------------------------");
}
Also used : IMQBasicConnection(com.sun.messaging.jmq.jmsserver.service.imq.IMQBasicConnection) Connection(com.sun.messaging.jmq.jmsserver.service.Connection) IMQConnection(com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection)

Example 4 with Connection

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);
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) IMQConnection(com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection) Connection(com.sun.messaging.jmq.jmsserver.service.Connection) IMQBasicConnection(com.sun.messaging.jmq.jmsserver.service.imq.IMQBasicConnection) IMQConnection(com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection)

Example 5 with Connection

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();
}
Also used : JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) StompConnection(com.sun.messaging.bridge.api.StompConnection) Connection(com.sun.messaging.jmq.jmsserver.service.Connection) ConnectionUID(com.sun.messaging.jmq.jmsserver.service.ConnectionUID) StompProtocolException(com.sun.messaging.bridge.api.StompProtocolException)

Aggregations

Connection (com.sun.messaging.jmq.jmsserver.service.Connection)10 IMQConnection (com.sun.messaging.jmq.jmsserver.service.imq.IMQConnection)6 ConnectionUID (com.sun.messaging.jmq.jmsserver.service.ConnectionUID)4 IMQBasicConnection (com.sun.messaging.jmq.jmsserver.service.imq.IMQBasicConnection)4 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)4 PropertyUpdateException (com.sun.messaging.jmq.jmsserver.config.PropertyUpdateException)2 IOException (java.io.IOException)2 List (java.util.List)2 StompConnection (com.sun.messaging.bridge.api.StompConnection)1 StompProtocolException (com.sun.messaging.bridge.api.StompProtocolException)1 FailedLoginException (com.sun.messaging.jmq.auth.api.FailedLoginException)1 AccessController (com.sun.messaging.jmq.jmsserver.auth.AccessController)1 AuthCacheData (com.sun.messaging.jmq.jmsserver.auth.AuthCacheData)1 HAMonitorService (com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAMonitorService)1 ConsumerSpi (com.sun.messaging.jmq.jmsserver.plugin.spi.ConsumerSpi)1 CoreLifecycleSpi (com.sun.messaging.jmq.jmsserver.plugin.spi.CoreLifecycleSpi)1 ConnectionManager (com.sun.messaging.jmq.jmsserver.service.ConnectionManager)1 IMQService (com.sun.messaging.jmq.jmsserver.service.imq.IMQService)1 JMSServiceReply (com.sun.messaging.jmq.jmsservice.JMSServiceReply)1 UID (com.sun.messaging.jmq.util.UID)1