LOG.log(Level.WARNING, "A task with dn: "+dn+" already existed.");
}
catch (NamingException ne)
{
LOG.log(Level.SEVERE, "Error creating task "+attrs, ne);
throw new ApplicationException(
ReturnCode.APPLICATION_ERROR,
getThrowableMsg(INFO_ERROR_LAUNCHING_INITIALIZATION.get(
sourceServerDisplay
), ne), ne);
}
i++;
}
// Wait until it is over
SearchControls searchControls = new SearchControls();
searchControls.setSearchScope(
SearchControls. OBJECT_SCOPE);
String filter = "objectclass=*";
searchControls.setReturningAttributes(
new String[] {
"ds-task-unprocessed-entry-count",
"ds-task-processed-entry-count",
"ds-task-log-message",
"ds-task-state"
});
Message lastDisplayedMsg = null;
String lastLogMsg = null;
long lastTimeMsgDisplayed = -1;
long lastTimeMsgLogged = -1;
int totalEntries = 0;
while (!isOver)
{
if (canceled)
{
// TODO: we should try to cleanly abort the initialize. As we have
// aborted the install, the server will be stopped and the remote
// server will receive a connect error.
checkAbort();
}
try
{
Thread.sleep(500);
}
catch (Throwable t)
{
}
if (canceled)
{
// TODO: we should try to cleanly abort the initialize. As we have
// aborted the install, the server will be stopped and the remote
// server will receive a connect error.
checkAbort();
}
try
{
NamingEnumeration<SearchResult> res =
ctx.search(dn, filter, searchControls);
SearchResult sr = null;
try
{
while (res.hasMore())
{
sr = res.next();
}
}
finally
{
res.close();
}
// Get the number of entries that have been handled and
// a percentage...
Message msg;
String sProcessed = getFirstValue(sr,
"ds-task-processed-entry-count");
String sUnprocessed = getFirstValue(sr,
"ds-task-unprocessed-entry-count");
int processed = -1;
int unprocessed = -1;
if (sProcessed != null)
{
processed = Integer.parseInt(sProcessed);
}
if (sUnprocessed != null)
{
unprocessed = Integer.parseInt(sUnprocessed);
}
totalEntries = Math.max(totalEntries, processed+unprocessed);
if ((processed != -1) && (unprocessed != -1))
{
if (processed + unprocessed > 0)
{
int perc = (100 * processed) / (processed + unprocessed);
msg = INFO_INITIALIZE_PROGRESS_WITH_PERCENTAGE.get(sProcessed,
String.valueOf(perc));
}
else
{
//msg = INFO_NO_ENTRIES_TO_INITIALIZE.get();
msg = null;
}
}
else if (processed != -1)
{
msg = INFO_INITIALIZE_PROGRESS_WITH_PROCESSED.get(sProcessed);
}
else if (unprocessed != -1)
{
msg = INFO_INITIALIZE_PROGRESS_WITH_UNPROCESSED.get(sUnprocessed);
}
else
{
msg = lastDisplayedMsg;
}
if (msg != null)
{
long currentTime = System.currentTimeMillis();
/* Refresh period: to avoid having too many lines in the log */
long minRefreshPeriod;
if (totalEntries < 100)
{
minRefreshPeriod = 0;
}
else if (totalEntries < 1000)
{
minRefreshPeriod = 1000;
}
else if (totalEntries < 10000)
{
minRefreshPeriod = 5000;
}
else
{
minRefreshPeriod = 10000;
}
if (((currentTime - minRefreshPeriod) > lastTimeMsgLogged))
{
lastTimeMsgLogged = currentTime;
LOG.log(Level.INFO, "Progress msg: "+msg);
}
if (displayProgress)
{
if (((currentTime - minRefreshPeriod) > lastTimeMsgDisplayed) &&
!msg.equals(lastDisplayedMsg))
{
notifyListeners(getFormattedProgress(msg));
lastDisplayedMsg = msg;
notifyListeners(getLineBreak());
lastTimeMsgDisplayed = currentTime;
}
}
}
String logMsg = getFirstValue(sr, "ds-task-log-message");
if (logMsg != null)
{
if (!logMsg.equals(lastLogMsg))
{
LOG.log(Level.INFO, logMsg);
lastLogMsg = logMsg;
}
}
InstallerHelper helper = new InstallerHelper();
String state = getFirstValue(sr, "ds-task-state");
if (helper.isDone(state) || helper.isStoppedByError(state))
{
isOver = true;
Message errorMsg;
LOG.log(Level.INFO, "Last task entry: "+sr);
if (displayProgress && (msg != null) && !msg.equals(lastDisplayedMsg))
{
notifyListeners(getFormattedProgress(msg));
lastDisplayedMsg = msg;
notifyListeners(getLineBreak());
}
if (lastLogMsg == null)
{
errorMsg = INFO_ERROR_DURING_INITIALIZATION_NO_LOG.get(
sourceServerDisplay, state, sourceServerDisplay);
}
else
{
errorMsg = INFO_ERROR_DURING_INITIALIZATION_LOG.get(
sourceServerDisplay, lastLogMsg, state,
sourceServerDisplay);
}
LOG.log(Level.WARNING, "Processed errorMsg: "+errorMsg);
if (helper.isCompletedWithErrors(state))
{
if (displayProgress)
{
notifyListeners(getFormattedWarning(errorMsg));
}
}
else if (!helper.isSuccessful(state) ||
helper.isStoppedByError(state))
{
ApplicationException ae = new ApplicationException(
ReturnCode.APPLICATION_ERROR, errorMsg,
null);
if ((lastLogMsg == null) ||
helper.isPeersNotFoundError(lastLogMsg))
{
LOG.log(Level.WARNING, "Throwing peer not found error. "+
"Last Log Msg: "+lastLogMsg);
// Assume that this is a peer not found error.
throw new PeerNotFoundException(errorMsg);
}
else
{
LOG.log(Level.SEVERE, "Throwing ApplicationException.");
throw ae;
}
}
else if (displayProgress)
{
LOG.log(Level.INFO, "Initialization completed successfully.");
notifyListeners(getFormattedProgress(
INFO_SUFFIX_INITIALIZED_SUCCESSFULLY.get()));
notifyListeners(getLineBreak());
}
}
}
catch (NameNotFoundException x)
{
isOver = true;
LOG.log(Level.INFO, "Initialization entry not found.");
if (displayProgress)
{
notifyListeners(getFormattedProgress(
INFO_SUFFIX_INITIALIZED_SUCCESSFULLY.get()));
notifyListeners(getLineBreak());
}
}
catch (NamingException ne)
{
throw new ApplicationException(
ReturnCode.APPLICATION_ERROR,
getThrowableMsg(INFO_ERROR_POOLING_INITIALIZATION.get(
sourceServerDisplay),
ne), ne);
}