use of com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAClusteredBroker in project openmq by eclipse-ee4j.
the class BrokerStateHandler method takeoverBroker.
public void takeoverBroker(String brokerID, Object extraInfo, boolean force) throws BrokerException {
ClusterManager cm = Globals.getClusterManager();
if (!cm.isHA()) {
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_NO_ADMIN_TAKEOVER_SUPPORT));
} else {
Object extraInfo2 = null;
HAClusteredBroker hcb = null;
if (Globals.getJDBCHAEnabled()) {
hcb = (HAClusteredBroker) cm.getBroker(brokerID);
}
if (hcb == null) {
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_UNKNOWN_BROKERID, brokerID));
}
if (hcb.isLocalBroker()) {
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_CANNOT_TAKEOVER_SELF));
}
Globals.getHAMonitorService().takeoverBroker(hcb, extraInfo, extraInfo2, force);
}
}
use of com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAClusteredBroker in project openmq by eclipse-ee4j.
the class HeartbeatService method brokerStatusChanged.
/**
* Called when the status of a broker has changed. The status may not be accurate if a previous listener updated the
* status for this specific broker.
*
* @param brokerid the name of the broker updated.
* @param brokerSession uid associated with the changed broker
* @param userData data associated with the state change
* @param oldStatus the previous status.
* @param newStatus the new status.
*/
@Override
public void brokerStatusChanged(String brokerid, int oldStatus, int newStatus, UID brokerSession, Object userData) {
HAClusteredBroker cb = (HAClusteredBroker) clsmgr.getBroker(brokerid);
if (cb.isLocalBroker()) {
return;
}
if (BrokerStatus.getBrokerIsDown(oldStatus) || BrokerStatus.getBrokerLinkIsDown(oldStatus)) {
if (BrokerStatus.getBrokerIsUp(newStatus) && BrokerStatus.getBrokerLinkIsUp(newStatus)) {
logger.log(logger.INFO, br.getKString(br.I_CLUSTER_HB_START_HEARTBEAT, brokerid));
addBroker(cb, brokerSession, (BrokerInfo) userData);
}
}
if (BrokerStatus.getBrokerInDoubt(oldStatus)) {
if (BrokerStatus.getBrokerNotInDoubt(newStatus)) {
logger.log(logger.INFO, br.getKString(br.I_CLUSTER_HB_UNSUSPECT, brokerid));
unsuspect(cb, brokerSession);
}
}
if (BrokerStatus.getBrokerIsDown(newStatus)) {
logger.log(logger.INFO, br.getKString(br.I_CLUSTER_HB_STOP_HEARTBEAT, brokerid + "[BrokerSession:" + brokerSession + "]"));
removeBroker(cb, brokerSession);
}
}
use of com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAClusteredBroker in project openmq by eclipse-ee4j.
the class HeartbeatService method heartbeatReceived.
/**
*************************************************************************
***************** Implement HeartbeatCallback Interface *******************
**************************************************************************
*/
/**
* The implementation of this method could check the validity of the received data and throw IOException to indicate the
* data should be discarded - that is it should not be counted in calculating timeout
*
* @param sender The remote address where the data received from
* @param data The data received
*
* @throws IOException if the data should be discarded
*/
@Override
public void heartbeatReceived(InetSocketAddress sender, byte[] data) throws IOException {
if (data == null) {
if (DEBUG) {
logger.log(logger.INFO, "HEARTBEAT: Ignore null data from " + sender);
}
throw new IOException("No data");
}
HeartbeatInfo hbi = null;
HeartbeatEntry hbe = new HeartbeatEntry();
try {
hbi = HeartbeatInfo.newInstance(data);
} catch (Exception e) {
if (DEBUG) {
logger.logStack(logger.INFO, "HEARTBEAT: Ignore data from " + sender + " because " + e.getMessage(), e);
}
if (e instanceof IOException) {
throw (IOException) e;
}
throw new IOException(e.getMessage());
}
hbe.brokerID = hbi.getBrokerID();
hbe.sessionUID = hbi.getBrokerSession();
hbe.lastSequence = hbi.getSequence();
HeartbeatEntry assigned = brokers.get(hbe);
if (assigned == null) {
if (DEBUG) {
logger.log(logger.INFO, "HEARTBEAT: Ignore heartbeat from " + sender + " " + hbe.toStringKS());
}
throw new IOException("Ignore heartbeat because of not found " + hbe.toStringK());
}
HAClusteredBroker lcb = (HAClusteredBroker) clsmgr.getLocalBroker();
if (!hbi.getToBrokerID().equals(lcb.getBrokerName()) || hbi.getToBrokerSession() != lcb.getBrokerSessionUID().longValue()) {
if (DEBUG) {
logger.log(logger.INFO, "HEARTBEAT: Ignore heartbeat not for me. " + hbi);
}
throw new IOException("Ignore heartbeat not for me. " + hbi);
}
boolean order = false;
synchronized (assigned) {
order = hbe.lastSequence > assigned.lastSequence;
}
if (!order) {
if (DEBUG) {
logger.log(logger.INFO, "HEARTBEAT: Ignore duplicate or out-of-order heartbeat " + hbe.toStringKS() + "[" + assigned + "] from " + sender);
}
throw new IOException("Ignore duplicate or out-of-order heartbeat " + hbe.toStringKS());
}
if (DEBUG) {
logger.log(logger.INFO, "HEARTBEAT: Received heartbeat #" + hbe.lastSequence + " from " + assigned);
}
if (fi.FAULT_INJECTION) {
HashMap fips = new HashMap();
fips.put(FaultInjection.BROKERID_PROP, hbi.getBrokerID());
if (fi.checkFault(FaultInjection.FAULT_HB_RECV, null) || fi.checkFault(FaultInjection.FAULT_HB_RECV_BROKERID, fips)) {
logger.log(logger.INFO, "DISCARD heartbeat from " + assigned + " because of FAULT");
return;
}
}
synchronized (assigned) {
assigned.lastTimestamp = System.currentTimeMillis();
assigned.lastSequence = hbi.getSequence();
}
assigned.sender = sender;
}
use of com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAClusteredBroker in project openmq by eclipse-ee4j.
the class HeartbeatService method heartbeatTimeout.
@Override
public void heartbeatTimeout(Object key, InetSocketAddress endpoint, IOException reason) {
HeartbeatEntry hbe = (HeartbeatEntry) key;
assert (endpoint.equals(hbe.endpoint));
HeartbeatEntry entry = brokers.get(hbe);
if (entry == null) {
if (DEBUG) {
logger.logStack(logger.INFO, "HEARTBEAT: NotFound: Heart beat timeout because " + (reason == null ? "" : reason.getMessage()) + ": " + hbe + ". Ignore.", reason);
}
return;
}
// XXX check entry == hbe ?
long indoubtTimestamp = 0;
int heartbeatInterval = 0;
synchronized (entry) {
indoubtTimestamp = entry.indoubtTimestamp;
heartbeatInterval = entry.heartbeatInterval;
}
long timeout = (heartbeatInterval * hb.getTimeoutThreshold()) * 1000L;
if (indoubtTimestamp < (System.currentTimeMillis() - timeout)) {
if (DEBUG) {
logger.logStack(logger.INFO, "Heart beat timeout because " + (reason == null ? "" : reason.getMessage()) + ": " + entry, reason);
} else {
logger.log(logger.WARNING, br.getKString(br.W_CLUSTER_HB_TIMEOUT, entry) + ": " + (reason == null ? "" : reason.getMessage()), reason);
}
HAClusteredBroker cb = (HAClusteredBroker) clsmgr.getBroker(entry.brokerID);
cb.setBrokerInDoubt(true, new UID(hbe.sessionUID));
synchronized (entry) {
entry.indoubtTimestamp = System.currentTimeMillis();
}
}
}
use of com.sun.messaging.jmq.jmsserver.cluster.api.ha.HAClusteredBroker in project openmq by eclipse-ee4j.
the class HeartbeatService method addBroker.
private synchronized void addBroker(HAClusteredBroker cb, UID brokerSession, BrokerInfo brokerInfo) {
HeartbeatEntry hbe = null;
ArrayList<Long> brokerSessions = new ArrayList();
synchronized (brokers) {
Iterator<HeartbeatEntry> itr = brokers.keySet().iterator();
while (itr.hasNext()) {
hbe = itr.next();
if (cb.getBrokerName().equals(hbe.brokerID)) {
brokerSessions.add(Long.valueOf(hbe.sessionUID));
}
}
}
Iterator<Long> itr = brokerSessions.iterator();
while (itr.hasNext()) {
removeBroker(cb, new UID(itr.next().longValue()));
}
hbe = new HeartbeatEntry();
try {
hbe.brokerID = cb.getBrokerName();
hbe.sessionUID = brokerSession.longValue();
hbe.endpoint = new InetSocketAddress(InetAddress.getByName(brokerInfo.getHeartbeatHostAddress()), brokerInfo.getHeartbeatPort());
// my heartbeat pkt
HeartbeatInfo hbi = HeartbeatInfo.newInstance();
HAClusteredBroker lcb = (HAClusteredBroker) clsmgr.getLocalBroker();
hbi.setBrokerID(lcb.getBrokerName());
hbi.setBrokerSession(lcb.getBrokerSessionUID().longValue());
hbi.setBrokerAddress((BrokerMQAddress) lcb.getBrokerURL());
hbi.setToBrokerID(cb.getBrokerName());
hbi.setToBrokerSession(brokerSession.longValue());
hbi.setSequence(0);
hbe.gp = hbi.getGPacket();
// calculate length for receiving
hbi = HeartbeatInfo.newInstance();
hbi.setBrokerID(cb.getBrokerName());
hbi.setBrokerSession(brokerSession.longValue());
hbi.setBrokerAddress((BrokerMQAddress) cb.getBrokerURL());
hbi.setToBrokerID(lcb.getBrokerName());
hbi.setToBrokerSession(lcb.getBrokerSessionUID().longValue());
hbe.dataLength = HeartbeatInfo.toByteArray(hbi.getGPacket()).length;
hbe.heartbeatInterval = brokerInfo.getHeartbeatInterval();
hbe.lastTimestamp = System.currentTimeMillis();
hbe.lastSequence = 0;
brokers.put(hbe, hbe);
// pad some bytes for safty
hb.addEndpoint(hbe, hbe.endpoint, hbe.dataLength + 500);
logger.log(logger.INFO, br.getKString(br.I_CLUSTER_HB_ADD_ENDPOINT, hbe));
} catch (Exception e) {
logger.logStack(Logger.ERROR, br.getKString(br.E_CLUSTER_HB_ADD_ENDPOINT_FAILED, hbe), e);
}
}
Aggregations