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", new Integer(consumers.size()));
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 = ((Consumer) consumers.get(i)).getConsumerUID();
ClusterConsumerInfo.writeConsumerUID(intid, dos);
}
if (roPkt == null) 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;
}