use of com.sun.messaging.jmq.jmsserver.cluster.api.ClusterManager in project openmq by eclipse-ee4j.
the class ClusterConsumerInfo method getGPacket.
public GPacket getGPacket(short protocol, int subtype, BrokerAddress broker) {
assert (consumers != null);
assert (protocol == ProtocolGlobals.G_NEW_INTEREST || protocol == ProtocolGlobals.G_INTEREST_UPDATE);
if (protocol == ProtocolGlobals.G_INTEREST_UPDATE) {
assert (// not effectively used ?
subtype == ProtocolGlobals.G_NEW_PRIMARY_INTEREST || subtype == ProtocolGlobals.G_REM_INTEREST || subtype == ProtocolGlobals.G_DURABLE_DETACH);
}
GPacket gp = GPacket.getInstance();
gp.setType(protocol);
gp.putProp("C", Integer.valueOf(consumers.size()));
if (broker != null && pendingMsgs != null && pendingMsgs.size() > 0) {
TransactionUID tid = null;
LinkedHashMap mm = null;
SysMessageID sysid = null;
StringBuilder sb = null;
StringBuilder sb45 = null;
StringBuilder oldsb = null;
Map m = (Map) pendingMsgs.get(broker);
if (m != null) {
oldsb = new StringBuilder();
Map.Entry pair = null;
Iterator itr0 = m.entrySet().iterator();
while (itr0.hasNext()) {
pair = (Map.Entry) itr0.next();
tid = (TransactionUID) pair.getKey();
mm = (LinkedHashMap) pair.getValue();
sb = new StringBuilder();
sb45 = new StringBuilder();
Map.Entry entry = null;
Iterator itr = mm.entrySet().iterator();
while (itr.hasNext()) {
entry = (Map.Entry) itr.next();
sysid = (SysMessageID) entry.getKey();
Integer deliverCnt = (Integer) entry.getValue();
sb.append(sysid).append(MID_DCT_SEPARATOR).append(deliverCnt == null ? 0 : deliverCnt).append(' ');
sb45.append(sysid).append(' ');
oldsb.append(sysid).append(' ');
}
if (sb.length() > 0) {
gp.putProp(PROP_PREFIX_PENDING_TID_MID_DCT + (tid == null ? "" : tid), String.valueOf(sb.toString()));
gp.putProp(PROP_PREFIX_PENDING_TID + (tid == null ? "" : tid), String.valueOf(sb45.toString()));
}
}
// To be removed when clustering the old protocol (< 500) broker no longer supported
gp.putProp(PROP_PENDING_MESSAGES, oldsb.toString());
}
}
if (cleanup) {
gp.putProp("cleanup", Boolean.TRUE);
}
if (c != null) {
c.marshalBrokerAddress(c.getSelfAddress(), gp);
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
switch(protocol) {
case ProtocolGlobals.G_NEW_INTEREST:
try {
ClusterManager cm = Globals.getClusterManager();
int csize = 1;
if (cm != null) {
csize = cm.getConfigBrokerCount();
if (csize <= 0) {
csize = 1;
}
}
int i = 0;
Iterator itr = consumers.iterator();
while (itr.hasNext()) {
i++;
Consumer c = (Consumer) itr.next();
int prefetch = c.getPrefetchForRemote() / csize;
if (prefetch <= 0) {
prefetch = 1;
}
gp.putProp(c.getConsumerUID().longValue() + ":" + Consumer.PREFETCH, Integer.valueOf(prefetch));
writeConsumer(c, dos);
if (!(c instanceof Subscription)) {
continue;
}
ChangeRecordInfo cri = ((Subscription) c).getCurrentChangeRecordInfo(ProtocolGlobals.G_NEW_INTEREST);
if (cri == null) {
continue;
}
gp.putProp("shareccSeq" + i, cri.getSeq());
gp.putProp("shareccUUID" + i, cri.getUUID());
gp.putProp("shareccResetUUID" + i, cri.getResetUUID());
}
dos.flush();
bos.flush();
} catch (IOException e) {
/* Ignore */
}
gp.setPayload(ByteBuffer.wrap(bos.toByteArray()));
break;
case ProtocolGlobals.G_INTEREST_UPDATE:
gp.putProp("T", Integer.valueOf(subtype));
try {
Iterator itr = consumers.iterator();
while (itr.hasNext()) {
Consumer c = (Consumer) itr.next();
writeConsumerUID(c.getConsumerUID(), dos);
}
dos.flush();
bos.flush();
} catch (IOException e) {
/* Ignore */
}
gp.setPayload(ByteBuffer.wrap(bos.toByteArray()));
break;
}
return gp;
}
Aggregations