* @param instName
*/
public static Message createBroadcastMessage(ReplicationState state, boolean isResponse, String instName) {
String instanceName = ReplicationUtil.getInstanceName();
//String instanceName = instName;
Message msg = new Message();
String mode = state.getMode();
String id = (String)state.getId();
String appid = state.getAppId();
String versionString = Long.toString(state.getVersion());
Long lastAccess = new Long(state.getLastAccess());
Long maxInactive = new Long(state.getMaxInactiveInterval());
String extraParam = state.getExtraParam();
String queryResult = (String)state.getQueryResult();
String theCommand = state.getCommand();
//String theCommand = MESSAGE_BROADCAST_QUERY;
byte[] data = state.getState();
byte[] trunkData = state.getTrunkState();
byte[] containerExtraParamData = state.getContainerExtraParamsState();
HashMap properties = (HashMap)state.getProperties();
byte[] propertiesState = null;
try {
propertiesState = ReplicationUtil.getByteArray(properties);
} catch (Exception ex) {}
/*
if(isResponse) {
theCommand = RETURN_BROADCAST_MSG_COMMAND;
}
*/
//is nack message
boolean isNack = state._isNack;
if(_logger.isLoggable(Level.FINE)) {
_logger.fine("ReplicationState>>createBroadcastMessage:instanceName=" + instanceName + " theCommand=" + theCommand);
}
msg.addMessageElement(MESSAGE_MODE,
new StringMessageElement(MESSAGE_MODE,
mode,
null));
if(mode != null && mode.equalsIgnoreCase(BULK_MESSAGE_MODE)) {
msg.addMessageElement(BULK_MESSAGE_MODE,
new StringMessageElement(BULK_MESSAGE_MODE,
"BULK",
null));
}
msg.addMessageElement(MESSAGE_ID,
new StringMessageElement(MESSAGE_ID,
id,
null));
msg.addMessageElement(MESSAGE_APPID,
new StringMessageElement(MESSAGE_APPID,
appid,
null));
msg.addMessageElement(MESSAGE_VERSION,
new StringMessageElement(MESSAGE_VERSION,
versionString,
null));
if(extraParam != null) {
msg.addMessageElement(MESSAGE_EXTRA_PARAM,
new StringMessageElement(MESSAGE_EXTRA_PARAM,
extraParam,
null));
}
if(queryResult != null) {
msg.addMessageElement(MESSAGE_QUERY_RESULT,
new StringMessageElement(MESSAGE_QUERY_RESULT,
queryResult,
null));
}
msg.addMessageElement(MESSAGE_COMMAND,
new StringMessageElement(MESSAGE_COMMAND,
theCommand,
null));
msg.addMessageElement(MESSAGE_LAST_ACCESS,
new StringMessageElement(MESSAGE_LAST_ACCESS,
lastAccess.toString(),
null));
msg.addMessageElement(MESSAGE_MAX_INACTIVE,
new StringMessageElement(MESSAGE_MAX_INACTIVE,
maxInactive.toString(),
null));
msg.addMessageElement(InstanceNameMessage,
new StringMessageElement(InstanceNameMessage,
instanceName,
null));
msg.addMessageElement(MESSAGE_INSTANCE_NAME,
new StringMessageElement(MESSAGE_INSTANCE_NAME,
instanceName,
null));
//is nack message
String isNackString = "N";
if(isNack) {
isNackString = "Y";
}
msg.addMessageElement(MESSAGE_IS_NACK,
new StringMessageElement(MESSAGE_IS_NACK,
isNackString,
null));
if(data != null) {
msg.addMessageElement(MESSAGE_DATA,
new ByteArrayMessageElement(MESSAGE_DATA,
null,
data,
null));
}
if(trunkData != null) {
msg.addMessageElement(MESSAGE_TRUNK_DATA,
new ByteArrayMessageElement(MESSAGE_TRUNK_DATA,
null,
trunkData,
null));
}
if(containerExtraParamData != null) {
msg.addMessageElement(MESSAGE_CONTAINER_EXTRA_PARAMS_DATA,
new ByteArrayMessageElement(MESSAGE_CONTAINER_EXTRA_PARAMS_DATA,
null,
containerExtraParamData,
null));
}
if(propertiesState != null) {
msg.addMessageElement(MESSAGE_PROPERTIES_DATA,
new ByteArrayMessageElement(MESSAGE_PROPERTIES_DATA,
null,
propertiesState,
null));
}
msg.addMessageElement(ORIGINATING_INSTANCE_NAME,
new StringMessageElement(ORIGINATING_INSTANCE_NAME, ReplicationUtil.getInstanceName(), null));
return msg;
}