public GPacket getGPacket(short protocol) throws BrokerException {
assert ( protocol == ProtocolGlobals.G_TAKEOVER_COMPLETE ||
protocol == ProtocolGlobals.G_TAKEOVER_PENDING ||
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", new Long(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", new Long(brokerSession.longValue()));
gp.putProp("brokerHost", brokerHost);
if (fromTaker) {
taker = cb.getBrokerName();
gp.putProp("taker", taker);
gp.putProp("timestamp", new Long(cb.getHeartbeat()));
gp.setBit(gp.A_BIT, true);
} else if (timedout) {
gp.putProp("timestamp", new Long(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);
}