use of com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo in project openmq by eclipse-ee4j.
the class RaptorProtocol method sendNewMasterBrokerPrepareAndWaitReply.
private String sendNewMasterBrokerPrepareAndWaitReply(BrokerAddress newmaster) throws Exception {
if (DEBUG) {
logger.log(logger.INFO, "RaptorProtocol.sendNewMasterBrokerPrepare, to = " + newmaster);
}
String uuid = null;
List<ChangeRecordInfo> records = store.getConfigChangeRecordsSince(-1);
// long now = System.currentTimeMillis();
ArrayList<ChangeRecord> recordList = ChangeRecord.compressRecords(records);
records.clear();
records = new ArrayList<>();
records.add(ChangeRecord.makeResetRecord(false));
ChangeRecord cr = null;
ChangeRecordInfo cri = null;
for (int i = 0; i < recordList.size(); i++) {
cr = recordList.get(i);
if (!cr.isDiscard()) {
cri = new ChangeRecordInfo();
cri.setRecord(cr.getBytes());
records.add(cri);
}
}
Long xid = newMasterBrokerReplyTracker.addWaiter(new UnicastReplyWaiter(newmaster, ProtocolGlobals.G_NEW_MASTER_BROKER_PREPARE_REPLY));
try {
ClusterNewMasterBrokerPrepareInfo nmpi = ClusterNewMasterBrokerPrepareInfo.newInstance(newmaster, records, xid, c);
GPacket gp = nmpi.getGPacket();
logger.log(logger.INFO, br.getKString(br.I_CLUSTER_UNICAST, ProtocolGlobals.getPacketTypeDisplayString(gp.getType()) + "[" + nmpi + "]", newmaster.toString()));
uuid = nmpi.getUUID();
c.unicast(newmaster, gp);
ReplyStatus reply = null;
try {
reply = newMasterBrokerReplyTracker.waitForReply(xid, changeMasterBrokerWaitTimeout);
} catch (BrokerException e) {
BrokerException e1 = e;
if (e.getStatusCode() == Status.GONE) {
e1 = new BrokerException(br.getKString(br.X_CLUSTER_BROKER_LINK_DOWN, newmaster.toString()), Status.GONE);
} else if (e.getStatusCode() == Status.TIMEOUT) {
String[] args = new String[] { String.valueOf(changeMasterBrokerWaitTimeout), ProtocolGlobals.getPacketTypeDisplayString(ProtocolGlobals.G_NEW_MASTER_BROKER_PREPARE_REPLY), newmaster.toString() };
e1 = new BrokerException(br.getKString(br.X_CLUSTER_WAIT_REPLY_TIMEOUT, args), Status.TIMEOUT);
}
throw e1;
}
if (reply.getStatus() != Status.OK) {
String[] args = new String[] { reply.getReason(), ProtocolGlobals.getPacketTypeDisplayString(ProtocolGlobals.G_NEW_MASTER_BROKER_PREPARE), newmaster.toString() };
String emsg = br.getKString(br.E_CLUSTER_RECEIVED_ERROR_REPLY_FROM_BROKER, args);
throw new BrokerException(emsg, reply.getStatus());
}
} finally {
newMasterBrokerReplyTracker.removeWaiter(xid);
}
return uuid;
}
use of com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo in project openmq by eclipse-ee4j.
the class ClusterImpl method processFirstInfoPacket.
protected void processFirstInfoPacket(GPacket gp, BrokerLink link) {
try {
if (!Globals.useSharedConfigRecord()) {
// should never happen
throw new BrokerException("Unexpected " + ProtocolGlobals.getPacketTypeDisplayString(gp.getType()) + " packet from " + link.getRemote());
}
ClusterFirstInfoInfo cii = ClusterFirstInfoInfo.newInstance(gp);
ChangeRecordInfo cri = cii.getLastStoredChangeRecord();
if (cri == null) {
return;
}
logger.log(logger.INFO, br.getKString(br.I_CLUSTER_RECEIVED_FIRST_INFO, ProtocolGlobals.getPacketTypeDisplayString(gp.getType()) + "[(sharecc)" + cri.toString() + "]", link.getRemote()));
cb.syncChangeRecordOnJoin(link.getRemote(), cri);
} catch (Exception e) {
logger.logStack(logger.ERROR, e.getMessage(), e);
if (e instanceof BrokerException) {
if (((BrokerException) e).getStatusCode() == Status.PRECONDITION_FAILED) {
link.shutdown();
return;
}
}
link.closeConn();
}
}
use of com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo in project openmq by eclipse-ee4j.
the class ClusterConsumerInfo method getShareccInfo.
public ChangeRecordInfo getShareccInfo(int i) {
if (pkt.getProp("shareccSeq" + i) == null) {
return null;
}
ChangeRecordInfo cri = new ChangeRecordInfo();
cri.setSeq((Long) pkt.getProp("shareccSeq" + i));
cri.setUUID((String) pkt.getProp("shareccUUID" + i));
cri.setResetUUID((String) pkt.getProp("shareccResetUUID" + i));
cri.setType(pkt.getType());
return cri;
}
use of com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo in project openmq by eclipse-ee4j.
the class ClusterDestInfo method getGPacket.
public GPacket getGPacket(short protocol, boolean changeRecord) {
assert (d != null);
assert (protocol == ProtocolGlobals.G_REM_DESTINATION || protocol == ProtocolGlobals.G_UPDATE_DESTINATION);
GPacket gp = GPacket.getInstance();
gp.setType(protocol);
gp.putProp("N", d.getDestinationName());
gp.putProp("DT", Integer.valueOf(d.getType()));
switch(protocol) {
case ProtocolGlobals.G_REM_DESTINATION:
ChangeRecordInfo cri = d.getCurrentChangeRecordInfo(ProtocolGlobals.G_REM_DESTINATION);
if (cri != null) {
gp.putProp("shareccSeq", cri.getSeq());
gp.putProp("shareccUUID", cri.getUUID());
gp.putProp("shareccResetUUID", cri.getResetUUID());
}
break;
case ProtocolGlobals.G_UPDATE_DESTINATION:
cri = d.getCurrentChangeRecordInfo(ProtocolGlobals.G_UPDATE_DESTINATION);
if (cri != null) {
gp.putProp("shareccSeq", cri.getSeq());
gp.putProp("shareccUUID", cri.getUUID());
gp.putProp("shareccResetUUID", cri.getResetUUID());
}
if (DestType.isTemporary(d.getType())) {
ConnectionUID cuid = d.getConnectionUID();
if (cuid != null) {
gp.putProp("connectionUID", Long.valueOf(cuid.longValue()));
}
}
HashMap props = d.getDestinationProperties();
if (props == null) {
props = new HashMap();
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
PacketProperties.write(props, bos);
bos.flush();
} catch (IOException e) {
/* Ignore */
}
byte[] buf = bos.toByteArray();
gp.setPayload(ByteBuffer.wrap(buf));
break;
}
if (changeRecord) {
gp.putProp("M", Boolean.TRUE);
}
return gp;
}
use of com.sun.messaging.jmq.jmsserver.persist.api.ChangeRecordInfo in project openmq by eclipse-ee4j.
the class ClusterBroadcaster method syncChangeRecordOnJoin.
@Override
public void syncChangeRecordOnJoin(BrokerAddress remote, ChangeRecordInfo cri) throws BrokerException {
String resetUUID = null;
if (lastSyncedChangeRecord != null) {
resetUUID = lastSyncedChangeRecord.getResetUUID();
}
if (resetUUID == null) {
resetUUID = (lastStoredChangeRecord == null ? null : lastStoredChangeRecord.getResetUUID());
}
if (resetUUID != null && !resetUUID.equals(cri.getResetUUID())) {
throw new BrokerException(br.getKString(br.X_SHARECC_RESETUID_MISMATCH_ON_JOIN, "[" + resetUUID + ", " + cri.getResetUUID() + "]", remote.toString()), Status.PRECONDITION_FAILED);
}
ChangeRecordInfo lastr = lastReceivedChangeRecord.get(remote);
if (lastr == null || lastr.getSeq().longValue() < cri.getSeq().longValue() || !lastr.getResetUUID().equals(cri.getResetUUID())) {
if (lastSyncedChangeRecord == null || lastSyncedChangeRecord.getSeq().longValue() < cri.getSeq().longValue()) {
logger.log(logger.INFO, br.getKString(br.I_SHARECC_SYNC_ON_JOIN, remote + "[" + cri + "]"));
ChangeRecord.syncChangeRecord(this, this, ((CommonProtocol) protocol).getRealProtocol(), false);
}
}
}
Aggregations