Search in sources :

Example 6 with AgentFileData

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();
}
Also used : ConsoleJobCallingServerJob(org.netxms.ui.eclipse.jobs.ConsoleJobCallingServerJob) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressListener(org.netxms.client.ProgressListener) AgentFileData(org.netxms.client.AgentFileData)

Aggregations

AgentFileData (org.netxms.client.AgentFileData)6 ProgressListener (org.netxms.client.ProgressListener)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 ConsoleJobCallingServerJob (org.netxms.ui.eclipse.jobs.ConsoleJobCallingServerJob)4 AgentFile (org.netxms.client.server.AgentFile)3 FileInputStream (java.io.FileInputStream)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 PartInitException (org.eclipse.ui.PartInitException)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ZipEntry (java.util.zip.ZipEntry)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 NXCException (org.netxms.client.NXCException)1 NXCSession (org.netxms.client.NXCSession)1