Search in sources :

Example 1 with SubJobMonitor

use of org.phoebus.framework.jobs.SubJobMonitor in project phoebus by ControlSystemStudio.

the class PhoebusApplication method backgroundStartup.

/**
 * Perform potentially slow startup task off the UI thread
 *
 * @param monitor
 * @param splash
 * @throws Exception
 */
private void backgroundStartup(final JobMonitor monitor, final Splash splash) throws Exception {
    // Assume there's 100 percent of work do to,
    // not knowing, yet, how many applications to start etc.
    monitor.beginTask(Messages.MonitorTaskApps, 100);
    // Locate registered applications and start them, allocating 30% to that
    startApplications(new SubJobMonitor(monitor, 30));
    // Load saved state (slow file access) off UI thread, allocating 30% to that
    monitor.beginTask(Messages.MonitorTaskSave);
    final MementoTree memento = loadDefaultMemento(application_parameters, new SubJobMonitor(monitor, 30));
    // Trigger initialization of authentication service
    AuthorizationService.init();
    // Back to UI thread
    Platform.runLater(() -> {
        try {
            // Leaving remaining 40% to the UI startup
            startUI(memento, new SubJobMonitor(monitor, 40));
        } catch (Throwable ex) {
            logger.log(Level.SEVERE, "Application cannot start up", ex);
        }
        monitor.done();
        if (splash != null)
            splash.close();
    });
}
Also used : SubJobMonitor(org.phoebus.framework.jobs.SubJobMonitor) MementoTree(org.phoebus.framework.persistence.MementoTree) XMLMementoTree(org.phoebus.framework.persistence.XMLMementoTree)

Example 2 with SubJobMonitor

use of org.phoebus.framework.jobs.SubJobMonitor in project phoebus by ControlSystemStudio.

the class Update method update.

/**
 * Update installation
 *  @param monitor {@link JobMonitor}
 *  @param install_location Existing {@link Locations#install()}
 *  @param update_zip ZIP file with distribution
 *  @throws Exception on error
 */
public static void update(final JobMonitor monitor, final File install_location, final File update_zip) throws Exception {
    if (monitor.isCanceled())
        return;
    if (!update_zip.canRead())
        throw new Exception("Cannot read " + update_zip);
    if (install_location.exists()) {
        monitor.updateTaskName("Delete " + install_location);
        monitor.worked(10);
        logger.info("Deleting " + install_location);
        FileHelper.delete(install_location);
    }
    // Un-zip new distribution
    final SubJobMonitor sub = new SubJobMonitor(monitor, 80);
    try (ZipFile zip = new ZipFile(update_zip)) {
        final long num_entries = zip.stream().count();
        sub.beginTask("Unpack " + update_zip, (int) num_entries);
        int counter = 0;
        final Enumeration<? extends ZipEntry> entries = zip.entries();
        while (entries.hasMoreElements() && !monitor.isCanceled()) {
            final ZipEntry entry = entries.nextElement();
            ++counter;
            // Adjust path
            String wrangled = wrangler.wrangle(entry.getName());
            if (wrangled.isEmpty()) {
                logger.info(counter + "/" + num_entries + ": " + "Skip " + entry.getName());
                continue;
            }
            final File outfile = new File(install_location, wrangled);
            // instead create any missing folders as needed.
            if (entry.isDirectory())
                continue;
            final File folder = outfile.getParentFile();
            if (folder.exists())
                logger.info(counter + "/" + num_entries + ": " + entry.getName() + " => " + outfile);
            else {
                logger.info(counter + "/" + num_entries + ": " + entry.getName() + " => " + outfile + " (new folder)");
                folder.mkdirs();
            }
            try (BufferedInputStream in = new BufferedInputStream(zip.getInputStream(entry))) {
                Files.copy(in, outfile.toPath(), StandardCopyOption.REPLACE_EXISTING);
                // For now just make shell scripts executable
                if (outfile.getName().endsWith(".sh"))
                    outfile.setExecutable(true);
            }
            sub.worked(1);
        }
    }
}
Also used : ZipFile(java.util.zip.ZipFile) BufferedInputStream(java.io.BufferedInputStream) SubJobMonitor(org.phoebus.framework.jobs.SubJobMonitor) ZipEntry(java.util.zip.ZipEntry) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Aggregations

SubJobMonitor (org.phoebus.framework.jobs.SubJobMonitor)2 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1 MementoTree (org.phoebus.framework.persistence.MementoTree)1 XMLMementoTree (org.phoebus.framework.persistence.XMLMementoTree)1