org.gradle.internal.concurrent.CompositeStoppable Java Examples

The following examples show how to use org.gradle.internal.concurrent.CompositeStoppable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultCacheAccess.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void closeFileLock() {
    try {
        cacheClosedCount++;
        try {
            // Close the caches and then notify them of the final state, in case the caches do work on close
            new CompositeStoppable().add(caches).stop();
            FileLock.State state = fileLock.getState();
            for (MultiProcessSafePersistentIndexedCache cache : caches) {
                cache.onEndWork(state);
            }
        } finally {
            fileLock.close();
        }
    } finally {
        fileLock = null;
        stateAtOpen = null;
        contended = false;
    }
}
 
Example #2
Source File: DefaultCacheAccess.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void closeFileLock() {
    try {
        cacheClosedCount++;
        try {
            // Close the caches and then notify them of the final state, in case the caches do work on close
            new CompositeStoppable().add(caches).stop();
            FileLock.State state = fileLock.getState();
            for (MultiProcessSafePersistentIndexedCache cache : caches) {
                cache.onEndWork(state);
            }
        } finally {
            fileLock.close();
        }
    } finally {
        fileLock = null;
        stateAtOpen = null;
        contended = false;
    }
}
 
Example #3
Source File: DefaultCacheAccess.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void closeFileLock() {
    try {
        cacheClosedCount++;
        try {
            // Close the caches and then notify them of the final state, in case the caches do work on close
            new CompositeStoppable().add(caches).stop();
            FileLock.State state = fileLock.getState();
            for (MultiProcessSafePersistentIndexedCache cache : caches) {
                cache.onEndWork(state);
            }
        } finally {
            fileLock.close();
        }
    } finally {
        fileLock = null;
        stateAtOpen = null;
        contended = false;
    }
}
 
Example #4
Source File: DefaultLoggingManager.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public DefaultLoggingManager stop() {
    try {
        CompositeStoppable.stoppable(loggingSystem, stdOutLoggingSystem, stdErrLoggingSystem).stop();
        for (StandardOutputListener stdoutListener : stdoutListeners) {
            loggingOutput.removeStandardOutputListener(stdoutListener);
        }
        for (StandardOutputListener stderrListener : stderrListeners) {
            loggingOutput.removeStandardErrorListener(stderrListener);
        }
        for (OutputEventListener listener : outputEventListeners) {
            loggingOutput.removeOutputEventListener(listener);
        }
    } finally {
        started = false;
    }
    return this;
}
 
Example #5
Source File: MessageHub.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void stop() {
    requestStop();

    CompositeStoppable stoppable = new CompositeStoppable();
    lock.lock();
    try {
        stoppable.add(outgoingUnicasts.values());
        stoppable.add(outgoingBroadcasts.values());
        stoppable.add(workers);
        stoppable.add(handlers);
        stoppable.add(connections);
        stoppable.add(router);
        stoppable.add(executors);
    } finally {
        outgoingUnicasts.clear();
        outgoingBroadcasts.clear();
        workers.clear();
        handlers.clear();
        lock.unlock();
    }

    stoppable.stop();
}
 
Example #6
Source File: DefaultLoggingManager.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public DefaultLoggingManager stop() {
    try {
        CompositeStoppable.stoppable(loggingSystem, stdOutLoggingSystem, stdErrLoggingSystem).stop();
        for (StandardOutputListener stdoutListener : stdoutListeners) {
            loggingOutput.removeStandardOutputListener(stdoutListener);
        }
        for (StandardOutputListener stderrListener : stderrListeners) {
            loggingOutput.removeStandardErrorListener(stderrListener);
        }
        for (OutputEventListener listener : outputEventListeners) {
            loggingOutput.removeOutputEventListener(listener);
        }
    } finally {
        started = false;
    }
    return this;
}
 
Example #7
Source File: DefaultCacheAccess.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void closeFileLock() {
    try {
        cacheClosedCount++;
        try {
            // Close the caches and then notify them of the final state, in case the caches do work on close
            new CompositeStoppable().add(caches).stop();
            FileLock.State state = fileLock.getState();
            for (MultiProcessSafePersistentIndexedCache cache : caches) {
                cache.onEndWork(state);
            }
        } finally {
            fileLock.close();
        }
    } finally {
        fileLock = null;
        stateAtOpen = null;
        contended = false;
    }
}
 
Example #8
Source File: ExecOutputHandleRunner.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void run() {
    byte[] buffer = new byte[2048];
    try {
        while (true) {
            int nread = inputStream.read(buffer);
            if (nread < 0) {
                break;
            }
            outputStream.write(buffer, 0, nread);
            outputStream.flush();
        }
        CompositeStoppable.stoppable(inputStream, outputStream).stop();
    } catch (Throwable t) {
        LOGGER.error(String.format("Could not %s.", displayName), t);
    }
}
 
Example #9
Source File: ExecOutputHandleRunner.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void run() {
    byte[] buffer = new byte[2048];
    try {
        while (true) {
            int nread = inputStream.read(buffer);
            if (nread < 0) {
                break;
            }
            outputStream.write(buffer, 0, nread);
            outputStream.flush();
        }
        CompositeStoppable.stoppable(inputStream, outputStream).stop();
    } catch (Throwable t) {
        LOGGER.error(String.format("Could not %s.", displayName), t);
    }
}
 
Example #10
Source File: DaemonClient.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Object monitorBuild(Build build, DaemonDiagnostics diagnostics, Connection<Object> connection, BuildCancellationToken cancellationToken) {
    DaemonClientInputForwarder inputForwarder = new DaemonClientInputForwarder(buildStandardInput, connection, executorFactory, idGenerator);
    DaemonCancelForwarder cancelForwarder = new DaemonCancelForwarder(connection, cancellationToken, idGenerator);
    try {
        cancelForwarder.start();
        inputForwarder.start();
        int objectsReceived = 0;

        while (true) {
            Object object = connection.receive();
            LOGGER.trace("Received object #{}, type: {}", objectsReceived++, object == null ? null : object.getClass().getName());

            if (object == null) {
                return handleDaemonDisappearance(build, diagnostics, cancellationToken);
            } else if (object instanceof OutputEvent) {
                outputEventListener.onOutput((OutputEvent) object);
            } else {
                return object;
            }
        }
    } finally {
        // Stop cancelling before sending end-of-input
        CompositeStoppable.stoppable(cancelForwarder, inputForwarder).stop();
    }
}
 
Example #11
Source File: Daemon.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Stops the daemon, blocking until any current requests/connections have been satisfied.
 * <p>
 * This is the semantically the same as sending the daemon the Stop command.
 * <p>
 * This method does not quite conform to the semantics of the Stoppable contract in that it will NOT
 * wait for any executing builds to stop before returning. This is by design as we currently have no way of
 * gracefully stopping a build process and blocking until it's done would not allow us to tear down the jvm
 * like we need to. This may change in the future if we create a way to interrupt a build.
 * <p>
 * What will happen though is that the daemon will immediately disconnect from any clients and remove itself
 * from the registry.
 */
public void stop() {
    LOGGER.debug("stop() called on daemon");
    lifecyleLock.lock();
    try {
        if (stateCoordinator == null) {
            throw new IllegalStateException("cannot stop daemon as it has not been started.");
        }

        LOGGER.info(DaemonMessages.REMOVING_PRESENCE_DUE_TO_STOP);

        // Stop the pipeline:
        // 1. mark daemon as stopped, so that any incoming requests will be rejected with 'daemon unavailable'
        // 2. remove presence from registry
        // 3. stop accepting new connections
        // 4. wait for commands in progress to finish (except for abandoned long running commands, like running a build)

        CompositeStoppable.stoppable(stateCoordinator, registryUpdater, connector, connectionHandler).stop();
    } finally {
        lifecyleLock.unlock();
    }
}
 
Example #12
Source File: Daemon.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Stops the daemon, blocking until any current requests/connections have been satisfied.
 * <p>
 * This is the semantically the same as sending the daemon the Stop command.
 * <p>
 * This method does not quite conform to the semantics of the Stoppable contract in that it will NOT
 * wait for any executing builds to stop before returning. This is by design as we currently have no way of
 * gracefully stopping a build process and blocking until it's done would not allow us to tear down the jvm
 * like we need to. This may change in the future if we create a way to interrupt a build.
 * <p>
 * What will happen though is that the daemon will immediately disconnect from any clients and remove itself
 * from the registry.
 */
public void stop() {
    LOGGER.debug("stop() called on daemon");
    lifecyleLock.lock();
    try {
        if (stateCoordinator == null) {
            throw new IllegalStateException("cannot stop daemon as it has not been started.");
        }

        LOGGER.info(DaemonMessages.REMOVING_PRESENCE_DUE_TO_STOP);

        // Stop the pipeline:
        // 1. mark daemon as stopped, so that any incoming requests will be rejected with 'daemon unavailable'
        // 2. remove presence from registry
        // 3. stop accepting new connections
        // 4. wait for commands in progress to finish (except for abandoned long running commands, like running a build)

        CompositeStoppable.stoppable(stateCoordinator, registryUpdater, connector, connectionHandler).stop();
    } finally {
        lifecyleLock.unlock();
    }
}
 
Example #13
Source File: ExecOutputHandleRunner.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void run() {
    byte[] buffer = new byte[2048];
    try {
        while (true) {
            int nread = inputStream.read(buffer);
            if (nread < 0) {
                break;
            }
            outputStream.write(buffer, 0, nread);
            outputStream.flush();
        }
        CompositeStoppable.stoppable(inputStream, outputStream).stop();
    } catch (Throwable t) {
        LOGGER.error(String.format("Could not %s.", displayName), t);
    }
}
 
Example #14
Source File: DefaultLoggingManager.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public DefaultLoggingManager stop() {
    try {
        CompositeStoppable.stoppable(loggingSystem, stdOutLoggingSystem, stdErrLoggingSystem).stop();
        for (StandardOutputListener stdoutListener : stdoutListeners) {
            loggingOutput.removeStandardOutputListener(stdoutListener);
        }
        for (StandardOutputListener stderrListener : stderrListeners) {
            loggingOutput.removeStandardErrorListener(stderrListener);
        }
        for (OutputEventListener listener : outputEventListeners) {
            loggingOutput.removeOutputEventListener(listener);
        }
    } finally {
        started = false;
    }
    return this;
}
 
Example #15
Source File: CompilerClientsManager.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void stop() {
    synchronized (lock) {
        LOGGER.debug("Stopping {} compiler daemon(s).", allClients.size());
        CompositeStoppable.stoppable(allClients).stop();
        LOGGER.info("Stopped {} compiler daemon(s).", allClients.size());
        allClients.clear();
    }
}
 
Example #16
Source File: DefaultActorFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Stops all actors.
 */
public void stop() {
    synchronized (lock) {
        try {
            CompositeStoppable.stoppable(nonBlockingActors.values()).add(blockingActors.values()).stop();
        } finally {
            nonBlockingActors.clear();
        }
    }
}
 
Example #17
Source File: ProtocolStack.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void stop() {
    requestStop();
    try {
        protocolsStopped.await();
    } catch (InterruptedException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
    callbackQueue.clear();
    CompositeStoppable.stoppable(callbackQueue, receiver, workQueue, incomingQueue, outgoingQueue).stop();
}
 
Example #18
Source File: DefaultWorkerProcess.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void cleanup() {
    CompositeStoppable stoppable;
    lock.lock();
    try {
        stoppable = CompositeStoppable.stoppable(acceptor, connection);
    } finally {
        this.connection = null;
        this.acceptor = null;
        this.execHandle = null;
        lock.unlock();
    }
    stoppable.stop();
}
 
Example #19
Source File: DefaultDaemonConnection.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void stop() {
    // 1. Stop handling disconnects. Blocks until the handler has finished.
    // 2. Stop the connection. This means that the thread receiving from the connection will receive a null and finish up.
    // 3. Stop receiving incoming messages. Blocks until the receive thread has finished. This will notify the stdin and receive queues to signal end of input.
    // 4. Stop the receive queue, to unblock any threads blocked in receive().
    // 5. Stop handling stdin. Blocks until the handler has finished. Discards any queued input.
    CompositeStoppable.stoppable(disconnectQueue, connection, executor, receiveQueue, stdinQueue).stop();
}
 
Example #20
Source File: DefaultWorkerProcess.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void cleanup() {
    CompositeStoppable stoppable;
    lock.lock();
    try {
        stoppable = CompositeStoppable.stoppable(acceptor, connection);
    } finally {
        this.connection = null;
        this.acceptor = null;
        this.execHandle = null;
        lock.unlock();
    }
    stoppable.stop();
}
 
Example #21
Source File: DefaultCacheFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void close() {
    lock.lock();
    try {
        CompositeStoppable.stoppable(dirCaches.values()).stop();
    } finally {
        dirCaches.clear();
        lock.unlock();
    }
}
 
Example #22
Source File: DefaultServiceRegistry.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void stop() {
    try {
        CompositeStoppable.stoppable(providers).stop();
    } finally {
        providers.clear();
    }
}
 
Example #23
Source File: TextReportRenderer.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
private void cleanupWriter() {
    try {
        if (close) {
            CompositeStoppable.stoppable(textOutput).stop();
        }
    } finally {
        textOutput = null;
    }
}
 
Example #24
Source File: DefaultServiceRegistry.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Closes all services for this registry. For each service, if the service has a public void close() or stop() method, that method is called to close the service.
 */
public void close() {
    synchronized (lock) {
        try {
            CompositeStoppable.stoppable(allServices).stop();
        } finally {
            closed = true;
        }
    }
}
 
Example #25
Source File: DefaultBinaryStore.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public <T> T read(BinaryStore.ReadAction<T> readAction) {
    try {
        if (decoder == null) {
            RandomAccessFile randomAccess = new RandomAccessFile(inputFile, "r");
            randomAccess.seek(offset);
            decoder = new KryoBackedDecoder(new RandomAccessFileInputStream(randomAccess));
            resources = new CompositeStoppable().add(randomAccess, decoder);
        }
        return readAction.read(decoder);
    } catch (Exception e) {
        throw new RuntimeException("Problems reading data from " + sourceDescription, e);
    }
}
 
Example #26
Source File: DefaultServiceRegistry.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Closes all services for this registry. For each service, if the service has a public void close() or stop() method, that method is called to close the service.
 */
public void close() {
    synchronized (lock) {
        try {
            CompositeStoppable.stoppable(allServices).stop();
        } finally {
            closed = true;
        }
    }
}
 
Example #27
Source File: DefaultActorFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Stops all actors.
 */
public void stop() {
    synchronized (lock) {
        try {
            CompositeStoppable.stoppable(nonBlockingActors.values()).add(blockingActors.values()).stop();
        } finally {
            nonBlockingActors.clear();
        }
    }
}
 
Example #28
Source File: DefaultWorkerProcess.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void cleanup() {
    CompositeStoppable stoppable;
    lock.lock();
    try {
        stoppable = CompositeStoppable.stoppable(acceptor, connection);
    } finally {
        this.connection = null;
        this.acceptor = null;
        this.execHandle = null;
        lock.unlock();
    }
    stoppable.stop();
}
 
Example #29
Source File: CachingToolingImplementationLoader.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void close() {
    try {
        CompositeStoppable.stoppable(connections.values()).stop();
    } finally {
        connections.clear();
    }
}
 
Example #30
Source File: DefaultCacheFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void close() {
    lock.lock();
    try {
        CompositeStoppable.stoppable(dirCaches.values()).stop();
    } finally {
        dirCaches.clear();
        lock.unlock();
    }
}