* create a Message from the input state
* @param state
* @param isResponse is the created message a response
*/
public static Message createMessage(ReplicationState state, boolean isResponse) {
Message msg = new Message();
String mode = state.getMode();
String id = (String)state.getId();
String appid = state.getAppId();
String command = state.getCommand();
Long version = new Long(state.getVersion());
Long lastAccess = new Long(state.getLastAccess());
Long maxInactive = new Long(state.getMaxInactiveInterval());
String extraParam = state.getExtraParam();
//FIXME for now assuming this is a Long
//for generality will have to serialize and use bytearray
Integer queryResult = (Integer)state.getQueryResult();
String instanceName = state.getInstanceName();
if(instanceName == null) {
//put existing instanceName for source if it is missing here
instanceName = lookupInstanceName();
}
byte[] data = state.getState();
byte[] trunkData = state.getTrunkState();
byte[] containerExtraParamData = state.getContainerExtraParamsState();
boolean ackRequired = state.isAckRequired();
HashMap properties = (HashMap)state.getProperties();
byte[] propertiesState = null;
try {
propertiesState = ReplicationUtil.getByteArray(properties);
} catch (Exception ex) {}
long sendStartTime = state.getSendStartTime();
//String data = "Message #" + i;
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_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,
version.toString(),
null));
String theCommand = command;
if(isResponse) {
theCommand = RETURN_MSG_COMMAND;
}
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));
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.toString(),
null));
}
if(instanceName != null) {
msg.addMessageElement(MESSAGE_INSTANCE_NAME,
new StringMessageElement(MESSAGE_INSTANCE_NAME,
instanceName,
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));
}
//is ack required
String ackRequiredString = "N";
if(ackRequired) {
ackRequiredString = "Y";
}
msg.addMessageElement(MESSAGE_ACK_REQUIRED,
new StringMessageElement(MESSAGE_ACK_REQUIRED,
ackRequiredString,
null));
//a property not sent but available for quick-ack case
msg.setMessageProperty(MESSAGE_ACK_REQUIRED, ackRequiredString);
List ackIdsList = state.getAckIdsList();
if(state.getAckIdsList() != null) {
msg.setMessageProperty(MESSAGE_ACK_LIST_PROPERTY, ackIdsList);
}
//send start time for measurements
if(sendStartTime != -1) {
msg.addMessageElement(MESSAGE_SEND_START_TIME,
new StringMessageElement(MESSAGE_SEND_START_TIME,
"" + sendStartTime,
null));
msg.setMessageProperty(MESSAGE_SEND_START_TIME, ""+sendStartTime);
}
msg.addMessageElement(MESSAGE_BIDI_STYLE,
new StringMessageElement(MESSAGE_BIDI_STYLE,
"" + state.isBiDiStyle(),
null));
if(_logger.isLoggable(Level.FINE)) {