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;
}
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;
}
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;
}
Aggregations