use of com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAClusteredBroker in project openmq by eclipse-ee4j.
the class ClusterTakeoverInfo method getGPacket.
public GPacket getGPacket(short protocol) throws BrokerException {
// protocol == ProtocolGlobals.G_TAKEOVER_ABORT );
if (!Globals.getHAEnabled()) {
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.E_INTERNAL_BROKER_ERROR, "Broker is not running in HA mode"));
}
if (pkt != null) {
assert (pkt.getType() == protocol);
return pkt;
}
GPacket gp = GPacket.getInstance();
gp.putProp("brokerID", brokerID);
gp.putProp("storeSession", Long.valueOf(storeSession.longValue()));
if (protocol == ProtocolGlobals.G_TAKEOVER_COMPLETE) {
gp.setType(protocol);
gp.setBit(gp.A_BIT, false);
return gp;
}
HAClusteredBroker cb = (HAClusteredBroker) Globals.getClusterManager().getLocalBroker();
if (protocol == ProtocolGlobals.G_TAKEOVER_PENDING) {
gp.setType(ProtocolGlobals.G_TAKEOVER_PENDING);
gp.setBit(gp.A_BIT, false);
gp.putProp("brokerSession", Long.valueOf(brokerSession.longValue()));
gp.putProp("brokerHost", brokerHost);
if (fromTaker) {
taker = cb.getBrokerName();
gp.putProp("taker", taker);
gp.putProp("timestamp", Long.valueOf(cb.getHeartbeat()));
gp.setBit(gp.A_BIT, true);
} else if (timedout) {
gp.putProp("timestamp", Long.valueOf(0));
}
gp.putProp("X", xid);
return gp;
}
if (protocol == ProtocolGlobals.G_TAKEOVER_ABORT) {
gp.setType(ProtocolGlobals.G_TAKEOVER_ABORT);
if (fromTaker) {
gp.putProp("taker", cb.getBrokerName());
}
gp.setBit(gp.A_BIT, false);
gp.putProp("X", xid);
return gp;
}
throw new BrokerException("Unknown protocol: " + protocol);
}
use of com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAClusteredBroker in project openmq by eclipse-ee4j.
the class SFSHABrokerInfoMap method get.
/**
* Retrieves the HAClusteredBroker associated with the passed in broker id. If the id is not found in the hashtable, the
* store 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) {
// always check against the backing store
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 SFSHAClusteredBrokerImpl((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.cluster.api.ha.HAClusteredBroker in project openmq by eclipse-ee4j.
the class JDBCHABrokerInfoMap method updateHAMapForState.
private void updateHAMapForState(BrokerState state) throws BrokerException {
// OK, load everything in the store that is the right state
Map map;
if (state == null) {
// Load everything if state is not specified
map = Globals.getStore().getAllBrokerInfos();
} else {
map = Globals.getStore().getAllBrokerInfoByState(state);
}
Iterator itr = map.entrySet().iterator();
while (itr.hasNext()) {
Map.Entry entry = (Map.Entry) itr.next();
String key = (String) entry.getKey();
HABrokerInfo bi = (HABrokerInfo) entry.getValue();
HAClusteredBrokerImpl impl = (HAClusteredBrokerImpl) get(key);
if (impl == null) {
HAClusteredBroker cb = new HAClusteredBrokerImpl(bi.getId(), bi, parent);
put(key, cb);
parent.brokerChanged(ClusterReason.ADDED, cb.getBrokerName(), null, cb, cb.getBrokerSessionUID(), null);
} else {
// update
// already exists
impl.update(bi);
}
}
// memory if any broker has been removed from the broker table
if (state == null) {
itr = entrySet().iterator();
while (itr.hasNext()) {
Map.Entry entry = (Map.Entry) itr.next();
String key = (String) entry.getKey();
if (!map.containsKey(key)) {
itr.remove();
HAClusteredBrokerImpl impl = (HAClusteredBrokerImpl) entry.getValue();
parent.brokerChanged(ClusterReason.REMOVED, impl.getBrokerName(), impl, null, impl.getBrokerSessionUID(), null);
}
}
}
}
use of com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAClusteredBroker in project openmq by eclipse-ee4j.
the class JDBCHABrokerInfoMap method init.
@Override
public void init(ClusterManager mgr, MQAddress addr) throws BrokerException {
this.parent = (HAClusterManagerImpl) mgr;
// OK, load everything in the store that is OPERATING
Map map = Globals.getStore().getAllBrokerInfos();
Iterator itr = map.entrySet().iterator();
while (itr.hasNext()) {
Map.Entry entry = (Map.Entry) itr.next();
String key = (String) entry.getKey();
HABrokerInfo bi = (HABrokerInfo) entry.getValue();
HAClusteredBroker cb = new HAClusteredBrokerImpl(bi.getId(), bi, parent);
put(key, cb);
parent.brokerChanged(ClusterReason.ADDED, cb.getBrokerName(), null, cb, cb.getBrokerSessionUID(), null);
}
}
use of com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAClusteredBroker in project openmq by eclipse-ee4j.
the class SFSHABrokerInfoMap method init.
@Override
public void init(ClusterManager mgr, MQAddress addr) throws BrokerException {
this.parent = (SFSHAClusterManagerImpl) mgr;
Map map = Globals.getStore().getAllBrokerInfos();
Iterator itr = map.entrySet().iterator();
while (itr.hasNext()) {
Map.Entry entry = (Map.Entry) itr.next();
String key = (String) entry.getKey();
HABrokerInfo bi = (HABrokerInfo) entry.getValue();
HAClusteredBroker cb = new SFSHAClusteredBrokerImpl(bi.getId(), bi, parent);
put(key, cb);
parent.brokerChanged(ClusterReason.ADDED, cb.getBrokerName(), null, cb, cb.getBrokerSessionUID(), null);
}
}
Aggregations