Search in sources :

Example 1 with NamedThreadFactory

use of org.exist.util.NamedThreadFactory in project exist by eXist-db.

the class Main method restoreWithGui.

private static void restoreWithGui(final String username, final String password, final Optional<String> dbaPassword, final Path f, final XmldbURI uri, boolean overwriteApps) {
    final GuiRestoreServiceTaskListener listener = new GuiRestoreServiceTaskListener();
    listener.info("Connecting ...");
    final Callable<Void> callable = () -> {
        try {
            final Collection collection = DatabaseManager.getCollection(uri.toString(), username, password);
            final EXistRestoreService service = (EXistRestoreService) collection.getService("RestoreService", "1.0");
            service.restore(f.toAbsolutePath().toString(), dbaPassword.orElse(null), listener, overwriteApps);
            listener.enableDismissDialogButton();
            if (JOptionPane.showConfirmDialog(null, "Would you like to rebuild the application repository?\nThis is only necessary if application packages were restored.", "Rebuild App Repository?", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                System.out.println("Rebuilding application repository ...");
                try {
                    final Collection root = DatabaseManager.getCollection(uri.toString(), username, dbaPassword.orElse(password));
                    ClientFrame.repairRepository(root);
                    listener.info("Application repository rebuilt successfully.");
                } catch (final XMLDBException e) {
                    reportError(e);
                    listener.info("Rebuilding application repository failed!");
                }
            }
        } catch (final Exception e) {
            // $NON-NLS-1$
            ClientFrame.showErrorMessage(e.getMessage(), null);
        } finally {
            if (listener.hasProblems()) {
                ClientFrame.showErrorMessage(listener.getAllProblems(), null);
            }
        }
        return null;
    };
    final ExecutorService executor = Executors.newSingleThreadExecutor(new NamedThreadFactory(null, null, "backup.restore-with-gui"));
    final Future<Void> future = executor.submit(callable);
    while (!future.isDone() && !future.isCancelled()) {
        try {
            future.get(100, TimeUnit.MILLISECONDS);
        } catch (final InterruptedException | TimeoutException ie) {
        } catch (final ExecutionException ee) {
            break;
        }
    }
}
Also used : NamedThreadFactory(org.exist.util.NamedThreadFactory) XMLDBException(org.xmldb.api.base.XMLDBException) StartException(org.exist.start.StartException) XMLDBException(org.xmldb.api.base.XMLDBException) IOException(java.io.IOException) Collection(org.xmldb.api.base.Collection)

Example 2 with NamedThreadFactory

use of org.exist.util.NamedThreadFactory in project exist by eXist-db.

the class JMXtoXML method ping.

/**
 * Ping the database to see if it is still responsive. This will first try to get a database broker object and if it
 * succeeds, run a simple query. If the server does not respond within the given timeout, the method will return an
 * error code -99 ({@link JMXtoXML#PING_TIMEOUT}). If there's an error on the server, the return value will be less
 * than 0. Otherwise the return value is the response time in milliseconds.
 *
 * @param instance the name of the database instance (default instance is "exist")
 * @param timeout  a timeout in milliseconds
 * @return Response time in msec, less than 0 in case of an error on server or PING_TIMEOUT when server does not
 * respond in time
 */
public long ping(final String instance, final long timeout) {
    final long start = System.currentTimeMillis();
    final ThreadFactory jmxPingFactory = new NamedThreadFactory(instance, "jmx.ping");
    final ExecutorService executorService = Executors.newSingleThreadExecutor(jmxPingFactory);
    final Future<Long> futurePing = executorService.submit(new Ping(instance, connection));
    while (true) {
        try {
            return futurePing.get(timeout, TimeUnit.MILLISECONDS);
        } catch (final ExecutionException e) {
            LOG.error(e);
            return PING_TIMEOUT;
        } catch (final TimeoutException e) {
            return PING_TIMEOUT;
        } catch (final InterruptedException e) {
            if ((System.currentTimeMillis() - start) >= timeout) {
                return PING_TIMEOUT;
            }
        // else will retry in loop
        }
    }
}
Also used : NamedThreadFactory(org.exist.util.NamedThreadFactory) NamedThreadFactory(org.exist.util.NamedThreadFactory)

Example 3 with NamedThreadFactory

use of org.exist.util.NamedThreadFactory in project exist by eXist-db.

the class ShutdownTask method execute.

@Override
public void execute(final DBBroker broker, final Txn transaction) throws EXistException {
    // NOTE - shutdown must be executed asynchronously from the scheduler, to avoid a deadlock with shutting down the scheduler
    final Callable shutdownCallable = new AsyncShutdown(broker.getBrokerPool());
    Executors.newSingleThreadExecutor(new NamedThreadFactory(broker.getBrokerPool(), "shutdown-task-async-shutdown")).submit(shutdownCallable);
}
Also used : NamedThreadFactory(org.exist.util.NamedThreadFactory) Callable(java.util.concurrent.Callable)

Aggregations

NamedThreadFactory (org.exist.util.NamedThreadFactory)3 IOException (java.io.IOException)1 Callable (java.util.concurrent.Callable)1 StartException (org.exist.start.StartException)1 Collection (org.xmldb.api.base.Collection)1 XMLDBException (org.xmldb.api.base.XMLDBException)1