Search in sources :

Example 26 with HABrokerInfo

use of com.sun.messaging.jmq.jmsserver.persist.api.HABrokerInfo in project openmq by eclipse-ee4j.

the class JDBCHABrokerInfoMap method get.

/**
 * Retrieves the HAClusteredBroker associated with the passed in broker id. If the id is not found in the hashtable, the
 * database will be checked.
 *
 * @param key the brokerid to lookup
 * @param update update against store
 * @return the HAClusteredBroker object (or null if one can't be found)
 */
@Override
public Object get(Object key, boolean update) {
    Object o = super.get(key);
    if (o == null || update) {
        try {
            HABrokerInfo m = Globals.getStore().getBrokerInfo((String) key);
            if (m != null && o == null) {
                HAClusteredBroker cb = new HAClusteredBrokerImpl((String) key, m, parent);
                put(key, cb);
                parent.brokerChanged(ClusterReason.ADDED, cb.getBrokerName(), null, cb, cb.getBrokerSessionUID(), null);
                o = cb;
            }
            if (m != null && update) {
                ((HAClusteredBrokerImpl) o).update(m);
            }
        } catch (BrokerException ex) {
            Globals.getLogger().logStack(Logger.WARNING, "Exception while creating broker entry " + key, ex);
        }
    }
    return o;
}
Also used : HABrokerInfo(com.sun.messaging.jmq.jmsserver.persist.api.HABrokerInfo) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) HAClusteredBroker(com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAClusteredBroker)

Example 27 with HABrokerInfo

use of com.sun.messaging.jmq.jmsserver.persist.api.HABrokerInfo in project openmq by eclipse-ee4j.

the class BrokerDAOImpl method getBrokerInfo.

/**
 * Get broker information.
 *
 * @param conn database connection
 * @param id the broker ID.
 * @return a HABrokerInfo object
 */
@Override
public HABrokerInfo getBrokerInfo(Connection conn, String id) throws BrokerException {
    HABrokerInfo bkrInfo = null;
    boolean myConn = false;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    Exception myex = null;
    try {
        // Get a connection
        DBManager dbMgr = DBManager.getDBManager();
        if (conn == null) {
            conn = dbMgr.getConnection(true);
            myConn = true;
        }
        pstmt = dbMgr.createPreparedStatement(conn, selectSQL);
        pstmt.setString(1, id);
        rs = pstmt.executeQuery();
        if (rs.next()) {
            bkrInfo = loadData(rs);
        }
    } catch (Exception e) {
        myex = e;
        try {
            if ((conn != null) && !conn.getAutoCommit()) {
                conn.rollback();
            }
        } catch (SQLException rbe) {
            logger.log(Logger.ERROR, BrokerResources.X_DB_ROLLBACK_FAILED + "[" + selectSQL + "]", rbe);
        }
        Exception ex;
        if (e instanceof BrokerException) {
            throw (BrokerException) e;
        } else if (e instanceof SQLException) {
            ex = DBManager.wrapSQLException("[" + selectSQL + "]", (SQLException) e);
        } else {
            ex = e;
        }
        throw new BrokerException(br.getKString(BrokerResources.X_LOAD_BROKERINFO_FAILED, id), ex);
    } finally {
        if (myConn) {
            Util.close(rs, pstmt, conn, myex);
        } else {
            Util.close(rs, pstmt, null, myex);
        }
    }
    return bkrInfo;
}
Also used : HABrokerInfo(com.sun.messaging.jmq.jmsserver.persist.api.HABrokerInfo) TakeoverLockException(com.sun.messaging.jmq.jmsserver.persist.api.TakeoverLockException)

Example 28 with HABrokerInfo

use of com.sun.messaging.jmq.jmsserver.persist.api.HABrokerInfo in project openmq by eclipse-ee4j.

the class BrokerDAOImpl method getAllBrokerInfos.

/**
 * Get broker information for all brokers.
 *
 * @param conn database connection
 * @param loadSession specify if store sessions should be loaded
 * @return a HashMap object containing HABrokerInfo for all brokers
 */
@Override
public HashMap getAllBrokerInfos(Connection conn, boolean loadSession) throws BrokerException {
    HashMap data = new HashMap();
    boolean myConn = false;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    Exception myex = null;
    try {
        // Get a connection
        DBManager dbMgr = DBManager.getDBManager();
        if (conn == null) {
            conn = dbMgr.getConnection(true);
            myConn = true;
        }
        pstmt = dbMgr.createPreparedStatement(conn, selectAllSQL);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            HABrokerInfo bkrInfo = loadData(rs);
            data.put(bkrInfo.getId(), bkrInfo);
        }
        if (loadSession) {
            rs.close();
            pstmt.close();
            Map sessionMap = dbMgr.getDAOFactory().getStoreSessionDAO().getAllStoreSessions(conn);
            Iterator itr = sessionMap.entrySet().iterator();
            while (itr.hasNext()) {
                Map.Entry entry = (Map.Entry) itr.next();
                String brokerID = (String) entry.getKey();
                HABrokerInfo bkrInfo = (HABrokerInfo) data.get(brokerID);
                if (bkrInfo != null) {
                    bkrInfo.setSessionList((List) entry.getValue());
                }
            }
        }
    } catch (Exception e) {
        myex = e;
        try {
            if ((conn != null) && !conn.getAutoCommit()) {
                conn.rollback();
            }
        } catch (SQLException rbe) {
            logger.log(Logger.ERROR, BrokerResources.X_DB_ROLLBACK_FAILED, rbe);
        }
        Exception ex;
        if (e instanceof BrokerException) {
            throw (BrokerException) e;
        } else if (e instanceof SQLException) {
            ex = DBManager.wrapSQLException("[" + selectAllSQL + "]", (SQLException) e);
        } else {
            ex = e;
        }
        throw new BrokerException(br.getKString(BrokerResources.X_LOAD_ALL_BROKERINFO_FAILED), ex);
    } finally {
        if (myConn) {
            Util.close(rs, pstmt, conn, myex);
        } else {
            Util.close(rs, pstmt, null, myex);
        }
    }
    return data;
}
Also used : TakeoverLockException(com.sun.messaging.jmq.jmsserver.persist.api.TakeoverLockException) HABrokerInfo(com.sun.messaging.jmq.jmsserver.persist.api.HABrokerInfo)

Aggregations

HABrokerInfo (com.sun.messaging.jmq.jmsserver.persist.api.HABrokerInfo)28 HAClusteredBroker (com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAClusteredBroker)6 TakeoverLockException (com.sun.messaging.jmq.jmsserver.persist.api.TakeoverLockException)6 HashMap (java.util.HashMap)5 AutoClusterBrokerMap (com.sun.messaging.jmq.jmsserver.cluster.manager.AutoClusterBrokerMap)4 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)4 Iterator (java.util.Iterator)4 Map (java.util.Map)4 TransactionState (com.sun.messaging.jmq.jmsserver.data.TransactionState)3 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)3 IOException (java.io.IOException)3 JMSBridgeStore (com.sun.messaging.bridge.api.JMSBridgeStore)2 InvalidPacketException (com.sun.messaging.jmq.io.InvalidPacketException)2 Packet (com.sun.messaging.jmq.io.Packet)2 PacketReadEOFException (com.sun.messaging.jmq.io.PacketReadEOFException)2 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)2 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)2 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)2 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)2 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)2