use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.
the class HAClusteredBrokerImpl method takeover.
/**
* attempt to take over the persistent state of the broker
*
* @throws IllegalStateException if this broker can not takeover.
* @return data associated with previous broker
*/
@Override
public TakeoverStoreInfo takeover(boolean force, Object extraInfo, TakingoverTracker tracker) throws BrokerException {
int delay = Globals.getConfig().getIntProperty(Globals.IMQ + ".cluster.takeover.delay.interval", 0);
if (delay > 0) {
try {
Thread.sleep(delay * 1000L);
} catch (InterruptedException e) {
}
}
boolean gotLock = false;
boolean sucessful = false;
BrokerState curstate = getState();
if (!force) {
checkCanTakeoverState(curstate, brokerid);
}
long newtime = System.currentTimeMillis();
BrokerState newstate = BrokerState.FAILOVER_PENDING;
Globals.getStore().getTakeOverLock(parent.getLocalBrokerName(), brokerid, tracker.getLastHeartbeat(), curstate, newtime, newstate, force, tracker);
gotLock = true;
state = newstate;
logger.log(Logger.DEBUG, "state = FAILOVER_PENDING " + brokerid);
parent.brokerChanged(ClusterReason.STATE_CHANGED, brokerid, curstate, newstate, null, null);
TakeoverStoreInfo o = null;
try {
// OK, explicitly retrieve old state from disk
logger.log(Logger.DEBUG, "state = FAILOVER_STARTED " + brokerid);
setState(BrokerState.FAILOVER_STARTED);
o = Globals.getStore().takeOverBrokerStore(parent.getLocalBrokerName(), brokerid, tracker);
logger.log(Logger.DEBUG, "state = FAILOVER_COMPLETE " + brokerid);
// fix for bug 6319711
// higher level processing needs to set
// failover complete AFTER routing is finished
// REMOTE: setState(BrokerState.FAILOVER_COMPLETE);
sucessful = true;
} catch (IllegalAccessException ex) {
throw new RuntimeException("Internal error, shouldnt happen", ex);
} finally {
if (gotLock && !sucessful) {
try {
setStateFailoverFailed(tracker.getBrokerSessionUID());
} catch (Exception ex) {
logger.log(logger.INFO, "Unable to set state to failed for broker " + this + ": " + ex.getMessage(), ex);
}
logger.log(Logger.WARNING, "Failed to takeover :" + brokerid + " state expected is " + curstate);
}
}
heartbeat = newtime;
parent.addSupportedStoreSessionUID(session);
takeoverBroker = parent.getLocalBrokerName();
return o;
}
use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.
the class HAMonitorServiceImpl method takeoverBroker.
@Override
public void takeoverBroker(HAClusteredBroker cb, Object extraInfo1, Object extraInfo2, boolean force) throws BrokerException {
DownBroker dbroker = new DownBroker();
dbroker.cb = cb;
dbroker.lastts = cb.getHeartbeat();
dbroker.brokerSession = cb.getBrokerSessionUID();
dbroker.storeSession = cb.getStoreSessionUID();
dbroker.extraInfo = extraInfo1;
if (cb instanceof RepHAClusteredBrokerImpl) {
dbroker.brokerName = ((RepHAClusteredBrokerImpl) cb).getNodeName();
dbroker.storeSession = (UID) extraInfo2;
} else {
dbroker.brokerName = cb.getBrokerName();
}
ArrayList l = new ArrayList();
l.add(dbroker);
synchronized (takeoverRunnableLock) {
while (monitorBusy || takeoverRunnable != null) {
try {
takeoverRunnableLock.wait();
} catch (InterruptedException e) {
}
}
takeoverRunnable = new TakeoverThread(l, force, true);
}
try {
((TakeoverThread) takeoverRunnable).doTakeover();
} catch (Exception e) {
if (e instanceof BrokerException) {
throw (BrokerException) e;
}
throw new BrokerException(e.getMessage(), e, Status.ERROR);
}
}
use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.
the class RepHAClusterManagerImpl method initAllBrokers.
/**
*************************************************
* override super class methods for auto-clustering
**************************************************
*/
@Override
protected Map initAllBrokers(MQAddress myaddr) throws BrokerException {
String cstr = Globals.getConfig().getProperty(Globals.AUTOCLUSTER_BROKERMAP_CLASS_PROP);
if (cstr == null) {
return super.initAllBrokers(myaddr);
}
try {
Class c = Class.forName(cstr);
Class[] paramTypes = { ClusterManagerImpl.class, MQAddress.class };
Constructor cons = c.getConstructor(paramTypes);
Object[] paramArgs = { this, myaddr };
return (Map) cons.newInstance(paramArgs);
} catch (Exception e) {
throw new BrokerException(e.getMessage(), e);
}
}
use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.
the class ClusterMessageInfo method getGPacket.
public GPacket getGPacket() throws Exception {
assert (ref != null);
assert (consumers != null);
GPacket gp = GPacket.getInstance();
gp.setType(ProtocolGlobals.G_MESSAGE_DATA);
gp.putProp("D", Boolean.valueOf(sendMessageDeliveredAck));
gp.putProp("C", Integer.valueOf(consumers.size()));
if (Globals.getDestinationList().isPartitionMode()) {
gp.putProp("partitionID", Long.valueOf(ref.getPartitionedStore().getPartitionID().longValue()));
}
c.marshalBrokerAddress(c.getSelfAddress(), gp);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
Packet roPkt = null;
try {
for (int i = 0; i < consumers.size(); i++) {
ConsumerUID intid = consumers.get(i).getConsumerUID();
ClusterConsumerInfo.writeConsumerUID(intid, dos);
gp.putProp(PROP_PREFIX_CUID_DCT + intid.longValue(), deliveryCnts.get(i));
}
if (redelivered) {
gp.putProp(PROP_REDELIVERED, Boolean.valueOf(redelivered));
}
roPkt = ref.getPacket();
if (roPkt == null) {
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_NULL_PACKET_FROM_REF, ref.toString()));
}
roPkt.generateTimestamp(false);
roPkt.generateSequenceNumber(false);
roPkt.writePacket(dos);
dos.flush();
bos.flush();
} catch (Exception e) {
String emsg = Globals.getBrokerResources().getKString(BrokerResources.X_EXCEPTION_WRITE_PKT_ON_SEND_MSG_REMOTE, ref.toString(), e.getMessage());
if (e instanceof BrokerException) {
logger.log(Logger.WARNING, emsg);
throw e;
}
logger.logStack(Logger.WARNING, emsg, e);
throw e;
}
byte[] buf = bos.toByteArray();
gp.setPayload(ByteBuffer.wrap(buf));
return gp;
}
use of com.sun.messaging.jmq.jmsserver.util.BrokerException 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);
}
Aggregations