use of org.netxms.client.AgentFileData in project netxms by netxms.
the class DynamicFileViewer method restartTracking.
/**
* Restart tracking after failure
*/
private void restartTracking() {
if (monitoringJob != null) {
monitoringJob.cancel();
monitoringJob = null;
}
if (restartJob != null)
restartJob.cancel();
text.append(// $NON-NLS-1$
"\n\n" + // $NON-NLS-1$
"----------------------------------------------------------------------\n" + Messages.get().FileViewer_NotifyFollowConnectionLost + // $NON-NLS-1$
"\n----------------------------------------------------------------------\n");
showMessage(ERROR, Messages.get().FileViewer_NotifyFollowConnectionLost);
restartJob = new ConsoleJobCallingServerJob(Messages.get().DynamicFileViewer_RestartFileTracking, null, Activator.PLUGIN_ID, null) {
private boolean running = true;
@Override
protected void canceling() {
running = false;
}
@Override
protected void runInternal(final IProgressMonitor monitor) throws Exception {
// Try to reconnect in every 20 seconds
while (running) {
try {
final AgentFileData file = session.downloadFileFromAgent(nodeId, remoteFileName, 1024, true, new ProgressListener() {
@Override
public void setTotalWorkAmount(long workTotal) {
monitor.beginTask("Track file " + remoteFileName, (int) workTotal);
}
@Override
public void markProgress(long workDone) {
monitor.worked((int) workDone);
}
}, this);
// When successfully connected - display notification to client.
runInUIThread(new Runnable() {
@Override
public void run() {
if (text.isDisposed()) {
running = false;
return;
}
hideMessage();
text.append(// $NON-NLS-1$
"-------------------------------------------------------------------------------\n" + Messages.get().FileViewer_NotifyFollowConnectionEnabed + // $NON-NLS-1$
"\n-------------------------------------------------------------------------------\n\n");
append(loadFile(file.getFile()));
startTracking(nodeId, fileId, remoteFileName);
}
});
break;
} catch (Exception e) {
}
Thread.sleep(20000);
}
}
@Override
protected String getErrorMessage() {
return Messages.get().DynamicFileViewer_CannotRestartFileTracking;
}
};
restartJob.setUser(false);
restartJob.setSystem(true);
restartJob.start();
}
Aggregations