Search in sources :

Example 16 with BrokerException

use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.

the class ProtocolImpl method pauseSession.

/**
 * Pause a session
 * <P>
 * Packet:<B>STOP</b>
 * </p>
 *
 * @param uid session to pause
 */
@Override
public void pauseSession(SessionUID uid) throws BrokerException {
    Session ses = Session.getSession(uid);
    if (ses == null) {
        throw new BrokerException("No session for " + uid);
    }
    ses.pause("PROTOCOL");
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) Session(com.sun.messaging.jmq.jmsserver.core.Session)

Example 17 with BrokerException

use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.

the class ProtocolImpl method startTransaction.

/**
 * Start a transaction.
 *
 * @param xid The Xid of the transaction to start. Required if transaction is an XA transaction. Must be null if it is
 * not an XA transaction.
 * @param xaFlags xaFlags passed on START operation. Used only if an XA transaction.
 * @param con Connection client start packet came in on (or null if internal)
 * @param type how rollback should be handled (e.g. only not prepared)
 * @param lifetime how long the transaction should live (0 == forever)
 * @return The TransactionUID started
 */
@Override
public TransactionUID startTransaction(JMQXid xid, Integer xaFlags, AutoRollbackType type, long lifetime, IMQConnection con) throws BrokerException {
    if (DEBUG) {
        logger.log(Logger.INFO, "ProtocolImpl.START TRANSACTION:XID=" + xid + ", xaFlags=" + TransactionState.xaFlagToString(xaFlags) + ", type=" + type + ", lifetime=" + lifetime + ", conn=@" + con.hashCode() + "[" + con.getConnectionUID() + ", " + con + "]");
    }
    List conlist = con.getTransactionListThreadSafe();
    TransactionHandler handler = (TransactionHandler) pr.getHandler(PacketType.START_TRANSACTION);
    // allocated a TID
    TransactionUID id = null;
    TransactionList tl = null;
    if (xaFlags == null || TransactionState.isFlagSet(XAResource.TMNOFLAGS, xaFlags)) {
        id = new TransactionUID();
        TransactionList[] tls = DL.getTransactionList(con.getPartitionedStore());
        tl = tls[0];
        if (tl == null) {
            throw new BrokerException("No transaction List for connection " + con + " to start new transaction " + id + (xid == null ? "" : " XID=" + xid));
        }
    } else if (xid != null) {
        Object[] oo = TransactionList.mapXidToTid(xid, con);
        if (oo == null) {
            throw new BrokerException("Unknown XID " + xid, Status.NOT_FOUND);
        } else {
            tl = (TransactionList) oo[0];
            id = (TransactionUID) oo[1];
        }
    } else {
        // XID is null, something is wrong
        throw new BrokerException("Invalid xid");
    }
    if (tl == null) {
        Object[] oo = TransactionList.getTransListAndState(id, con, false, false);
        if (oo != null) {
            tl = (TransactionList) oo[0];
        }
    }
    if (tl == null) {
        throw new BrokerException("No Transaction List found for connection " + con + " to start transaction " + id + (xid == null ? "" : " XID=" + xid));
    }
    Object o = new Object();
    handler.doStart(tl, id, conlist, con, type, xid, xid != null, lifetime, 0, xaFlags, PacketType.START_TRANSACTION, false, o.toString());
    if (DEBUG) {
        logger.log(Logger.INFO, "ProtocolImpl.STARTED TRANSACTION:TID=" + id + ", XID=" + xid + ", type=" + type + ", con=" + con);
    }
    return id;
}
Also used : TransactionUID(com.sun.messaging.jmq.jmsserver.data.TransactionUID) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) TransactionHandler(com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler) DestinationList(com.sun.messaging.jmq.jmsserver.core.DestinationList) List(java.util.List) ArrayList(java.util.ArrayList) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList)

Example 18 with BrokerException

use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.

the class ProtocolImpl method commitTransaction.

/**
 * Commit a transaction.
 *
 * @param id The TransactionUID to commit
 * @param xid The Xid of the transaction to commit. Required if transaction is an XA transaction. Must be null if it is
 * not an XA transaction.
 * @param xaFlags xaFlags passed on COMMIT operation. Used only if an XA transaction.
 * @param con Connection client commit packet came in on (or null if internal)
 */
@Override
public void commitTransaction(TransactionUID id, JMQXid xid, Integer xaFlags, IMQConnection con) throws BrokerException {
    if (DEBUG) {
        logger.log(Logger.INFO, "ProtocolImpl.COMMIT TRANSACTION:TID=" + id + ", XID=" + xid + ", xaFlags=" + TransactionState.xaFlagToString(xaFlags) + ", conn=@" + con.hashCode() + "[" + con.getConnectionUID() + ", " + con + "]");
    }
    List conlist = con.getTransactionListThreadSafe();
    TransactionHandler handler = (TransactionHandler) pr.getHandler(PacketType.START_TRANSACTION);
    TransactionList tl = null;
    if (0L == id.longValue()) {
        if (xid == null) {
            throw new BrokerException("Unexpected TransactionUID  " + id);
        }
        Object[] oo = TransactionList.mapXidToTid(xid, con);
        if (oo == null) {
            id = null;
        } else {
            tl = (TransactionList) oo[0];
            id = (TransactionUID) oo[1];
        }
        if (id == null) {
            throw new BrokerException("Unknown XID " + xid, Status.NOT_FOUND);
        }
    }
    TransactionState ts = null;
    if (tl == null) {
        Object[] oo = TransactionList.getTransListAndState(id, con, false, false);
        if (oo != null) {
            tl = (TransactionList) oo[0];
            ts = (TransactionState) oo[1];
        }
    }
    if (tl == null) {
        throw new BrokerException("Unknown transaction " + id + (xid == null ? "" : " XID=" + xid), Status.NOT_FOUND);
    }
    if (ts == null) {
        ts = tl.retrieveState(id);
        if (ts == null) {
            throw new BrokerException("Unknown transaction " + id + (xid == null ? "" : " XID=" + xid), Status.NOT_FOUND);
        }
    }
    if (xid != null) {
        if (ts.getXid() == null || !xid.equals(ts.getXid())) {
            throw new BrokerException("Transaction XID mismatch " + xid + ", expected " + ts.getXid() + " for transaction " + id);
        }
    }
    handler.doCommit(tl, id, xid, xaFlags, ts, conlist, false, con, null);
}
Also used : TransactionState(com.sun.messaging.jmq.jmsserver.data.TransactionState) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) TransactionHandler(com.sun.messaging.jmq.jmsserver.data.handlers.TransactionHandler) DestinationList(com.sun.messaging.jmq.jmsserver.core.DestinationList) List(java.util.List) ArrayList(java.util.ArrayList) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList) TransactionList(com.sun.messaging.jmq.jmsserver.data.TransactionList)

Example 19 with BrokerException

use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.

the class Agent method getPlatformMBeanServer.

private MBeanServer getPlatformMBeanServer() throws BrokerException {
    MBeanServer mbeanServer = null;
    try {
        Class c = Class.forName("java.lang.management.ManagementFactory");
        Method m = c.getMethod("getPlatformMBeanServer", (java.lang.Class[]) null);
        mbeanServer = (MBeanServer) m.invoke("getPlatformMBeanServer", (java.lang.Object[]) null);
    } catch (Exception e) {
        throw new BrokerException(rb.getString(rb.W_JMX_GET_PLATFORM_MBEANSERVER_EXCEPTION, e.toString()));
    }
    return (mbeanServer);
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) Method(java.lang.reflect.Method) MalformedURLException(java.net.MalformedURLException) RemoteException(java.rmi.RemoteException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Example 20 with BrokerException

use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.

the class Agent method startRMIRegistry.

private void startRMIRegistry() throws BrokerException {
    Registry registry = null;
    boolean registryExists = false;
    int port;
    if (!startRmiRegistry()) {
        return;
    }
    port = getRmiRegistryPort();
    String jmxHostname = Globals.getJMXHostname();
    try {
        if (jmxHostname != null && !jmxHostname.equals(Globals.HOSTNAME_ALL)) {
            registry = LocateRegistry.getRegistry(jmxHostname, port);
        } else {
            registry = LocateRegistry.getRegistry(port);
        }
        /*
             * Call list() to force a remote call - this confirms if the registry is up and running
             */
        registry.list();
        registryExists = true;
    } catch (RemoteException re) {
    /*
             * An exception will be caught if there is no registry running at the specified port. Not a problem since we are about
             * to create a registry.
             */
    }
    if (registryExists) {
        throw new BrokerException(rb.getString(rb.W_JMX_RMI_REGISTRY_EXISTS, Integer.toString(port)));
    }
    try {
        if (jmxHostname != null && !jmxHostname.equals(Globals.HOSTNAME_ALL)) {
            MQRMIServerSocketFactory ssf = new MQRMIServerSocketFactory(jmxHostname, 0, false);
            registry = LocateRegistry.createRegistry(port, null, ssf);
        } else {
            registry = LocateRegistry.createRegistry(port);
        }
        /*
             * Call list() to force a remote call - this confirms if the registry is up and running
             */
        registry.list();
        logger.log(Logger.INFO, rb.getString(rb.I_JMX_RMI_REGISTRY_STARTED, Integer.toString(port)));
    } catch (RemoteException re) {
        throw new BrokerException(rb.getString(rb.W_JMX_RMI_REGISTRY_STARTED_EXCEPTION, Integer.toString(port), re.toString()));
    }
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) Registry(java.rmi.registry.Registry) LocateRegistry(java.rmi.registry.LocateRegistry) RemoteException(java.rmi.RemoteException)

Aggregations

BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)290 IOException (java.io.IOException)72 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)33 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)31 SizeString (com.sun.messaging.jmq.util.SizeString)31 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)29 Iterator (java.util.Iterator)26 ArrayList (java.util.ArrayList)25 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)24 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)23 HashMap (java.util.HashMap)22 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)21 TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)21 LoadException (com.sun.messaging.jmq.jmsserver.persist.api.LoadException)21 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)18 List (java.util.List)18 Packet (com.sun.messaging.jmq.io.Packet)16 BrokerAddress (com.sun.messaging.jmq.jmsserver.core.BrokerAddress)16 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)16 ConsumerAlreadyAddedException (com.sun.messaging.jmq.jmsserver.util.ConsumerAlreadyAddedException)15