XBSession session = this.publisher.getJmsSession();
// XBMessageProducer producer = new XBMessageProducer(session, new XBDestination(topic, null));
XBDestination dest = new XBDestination(this.initialDataTopic, SpecificDefault.toString(slaveSessionNames));
XBMessageProducer producer = new XBMessageProducer(session, dest);
producer.setPriority(PriorityEnum.HIGH_PRIORITY.getInt());
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
String dumpId = "" + new Timestamp().getTimestamp();
// now read the file which has been generated
String filename = null;
if (shortFilename != null) {
log.info("sending initial file '" + shortFilename + "' for user '" + SpecificDefault.toString(slaveSessionNames) + "'");
if (this.initialCmdPath != null)
filename = this.initialCmdPath + File.separator + shortFilename;
else
filename = shortFilename;
File file = new File(filename);
FileInputStream fis = new FileInputStream(file);
XBStreamingMessage msg = session.createStreamingMessage(this);
msg.setIntProperty(XBConnectionMetaData.JMSX_MAX_CHUNK_SIZE, this.initialDumpMaxSize);
msg.setStringProperty(FILENAME_ATTR, shortFilename);
msg.setLongProperty(REPL_KEY_ATTR, minKey);
msg.setStringProperty(DUMP_ACTION, "true");
if (initialFilesLocation != null) {
msg.setStringProperty(INITIAL_FILES_LOCATION, initialFilesLocation);
msg.setStringProperty(INITIAL_DATA_ID, dumpId);
}
msg.setInputStream(fis);
producer.send(msg);
// make a version copy if none exists yet
boolean doDelete = true;
if (currentVersion != null) {
String backupFileName = this.initialCmdPath + File.separator + VersionTransformerCache.buildFilename(this.replPrefix, currentVersion);
File backupFile = new File(backupFileName);
if (!backupFile.exists()) {
final boolean copy = true;
if (copy) {
BufferedInputStream bis = new BufferedInputStream(file.toURL().openStream());
FileOutputStream os = new FileOutputStream(backupFileName);
long length = file.length();
long remaining = length;
byte[] buf = new byte[this.initialDumpMaxSize];
while (remaining > 0) {
int tot = bis.read(buf);
remaining -= tot;
os.write(buf, 0, tot);
}
bis.close();
os.close();
}
else {
boolean ret = file.renameTo(backupFile);
if (!ret)
log.severe("could not move the file '" + filename + "' to '" + backupFileName + "' reason: could it be that the destination is not a local file system ? try the flag 'copyOnMove='true' (see http://www.xmlblaster.org/xmlBlaster/doc/requirements/client.filepoller.html");
else
doDelete = false;
}
}
}
else
log.severe("The version is not set. Can not make a backup copy of the version file");
boolean isRequestingCurrentVersion = currentVersion.equalsIgnoreCase(requestedVersion);
if (!this.keepDumpFiles && doDelete && isRequestingCurrentVersion) {
if (file.exists()) {
boolean ret = file.delete();
if (!ret)
log.warning("could not delete the file '" + filename + "'");
}
}
fis.close();
}
else
log.info("initial update requested with no real initial data for '" + SpecificDefault.toString(slaveSessionNames) + "' and for replication '" + this.replPrefix + "'");
// send the message for the status change
if (initialFilesLocation != null) {
// then we save it in a file but we must tell it is finished now
TextMessage endMsg = session.createTextMessage();
endMsg.setText("INITIAL UPDATE WILL BE STORED UNDER '" + initialFilesLocation + "'");
endMsg.setBooleanProperty(INITIAL_DATA_END, true);
endMsg.setStringProperty(INITIAL_DATA_ID, dumpId);
endMsg.setStringProperty(INITIAL_FILES_LOCATION, initialFilesLocation);
producer.send(endMsg);
endMsg = session.createTextMessage();
endMsg.setText("INITIAL UPDATE WILL BE STORED UNDER '" + initialFilesLocation + "' (going to remote)");
endMsg.setBooleanProperty(INITIAL_DATA_END_TO_REMOTE, true);
endMsg.setStringProperty(INITIAL_DATA_ID, dumpId);
endMsg.setStringProperty(INITIAL_FILES_LOCATION, initialFilesLocation);
producer.send(endMsg);
}
sendInitialDataResponseOnly(slaveSessionNames, replManagerAddress, minKey, maxKey);
if (replSourceEngine != null)
replSourceEngine.sendEndOfTransitionMessage(info, session, initialFilesLocation, shortFilename, dumpId, producer);
}