if (Constants.OID_DEAD_LETTER.equals(updateKey.getOid()))
return processDeadLetter(updateQos);
InputStream is = MomEventEngine.decompress(new ByteArrayInputStream(content), updateQos.getClientProperties());
content = getContent(is);
SessionName senderSession = updateQos.getSender();
String request = updateQos.getClientProperty("_command", "");
log.info("The master Replicator with session '" + senderSession.getRelativeName() + "' is sending '" + request + "'");
if ("broadcastSql".equalsIgnoreCase(request)) {
try {
final boolean highPrio = true;
String requestId = updateQos.getClientProperty("requestId", (String)null);
if (requestId == null)
throw new Exception("The requestId has not been defined");
String repl = updateQos.getClientProperty(REPL_PREFIX_KEY, REPL_PREFIX_DEFAULT);
String sql = new String(content);
sendBroadcastRequest(repl, sql, highPrio, requestId);
return "OK";
}
catch (Throwable ex) {
ex.printStackTrace();
log.severe("An exception occured during an sql broadcast message:" + ex.getMessage() + "' will continue anyway to avoid stopping dispatcher");
return "OK"; // we don't want to stop the dispatcher
}
}
else if ("removeBroadcast".equalsIgnoreCase(request)) {
try {
removeSqlStatement(new String(content));
return "OK";
}
catch (Throwable ex) {
ex.printStackTrace();
log.severe("An exception occured when removing an sql broadcast:" + ex.getMessage() + "' will continue anyway to avoid stopping dispatcher");
return "OK"; // we don't want to stop the dispatcher
}
}
// 1. This is a response from an sql statement which has been previously sent to the slaves.
else if (this.sqlTopic != null && updateKey.getOid().equals(this.sqlTopic)) {
ClientProperty prop = (ClientProperty)updateQos.getClientProperties().get(STATEMENT_ID_ATTR);
if (prop == null) {
log.severe("The statement id is not specified, can not process it");
return "OK"; // we don't want to stop the dispatcher
}
String reqId = prop.getStringValue();
SqlStatement sqlStatement = (SqlStatement)this.sqlStatementMap.get(reqId);
if (sqlStatement == null) {
log.severe("The statement with id '" + reqId + "' has not been found");
return "OK"; // we don't want to stop the dispatcher
}
prop = (ClientProperty)updateQos.getClientProperties().get(EXCEPTION_ATTR);
String response = null;
boolean isException = false;
if (prop != null) {
response = prop.getStringValue();
isException = true;
}
prop = (ClientProperty)updateQos.getClientProperties().get(MASTER_ATTR);
if (prop != null) { // then it is the response from the master
String replPrefix = prop.getStringValue();
if (response == null)
response = new String(content);
sqlStatement.setResponse(replPrefix, response, isException);
}
else {
if (response == null)
response = new String(content);
sqlStatement.setResponse(senderSession.getRelativeName(), response, isException);
}
}
// 2. This is the response coming from a DbWatcher on a request for initial update which one of the ReplSlaves has previously requested.
else if ("INITIAL_DATA_RESPONSE".equals(request)) {
long minReplKey = updateQos.getClientProperty("_minReplKey", 0L);