Search in sources :

Example 1 with DaemonServices

use of org.gradle.launcher.daemon.server.DaemonServices in project gradle by gradle.

the class ForegroundDaemonAction method run.

@Override
public void run() {
    LoggingManagerInternal loggingManager = loggingRegistry.newInstance(LoggingManagerInternal.class);
    loggingManager.start();
    DaemonServices daemonServices = new DaemonServices(configuration, loggingRegistry, loggingManager, DefaultClassPath.of());
    Daemon daemon = daemonServices.get(Daemon.class);
    DaemonRegistry daemonRegistry = daemonServices.get(DaemonRegistry.class);
    DaemonExpirationStrategy expirationStrategy = daemonServices.get(MasterExpirationStrategy.class);
    daemon.start();
    try {
        daemonRegistry.markState(daemon.getAddress(), Idle);
        daemon.stopOnExpiration(expirationStrategy, configuration.getPeriodicCheckIntervalMs());
    } finally {
        daemon.stop();
    }
}
Also used : LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) Daemon(org.gradle.launcher.daemon.server.Daemon) DaemonServices(org.gradle.launcher.daemon.server.DaemonServices) DaemonRegistry(org.gradle.launcher.daemon.registry.DaemonRegistry) DaemonExpirationStrategy(org.gradle.launcher.daemon.server.expiry.DaemonExpirationStrategy)

Example 2 with DaemonServices

use of org.gradle.launcher.daemon.server.DaemonServices in project gradle by gradle.

the class DaemonMain method doAction.

@Override
protected void doAction(String[] args, ExecutionListener listener) {
    // The first argument is not really used but it is very useful in diagnosing, i.e. running 'jps -m'
    if (args.length != 1) {
        invalidArgs("Following arguments are required: <gradle-version>");
    }
    // Read configuration from stdin
    List<String> startupOpts;
    File gradleHomeDir;
    File daemonBaseDir;
    int idleTimeoutMs;
    int periodicCheckIntervalMs;
    boolean singleUse;
    String daemonUid;
    DaemonParameters.Priority priority;
    List<File> additionalClassPath;
    KryoBackedDecoder decoder = new KryoBackedDecoder(new EncodedStream.EncodedInput(System.in));
    try {
        gradleHomeDir = new File(decoder.readString());
        daemonBaseDir = new File(decoder.readString());
        idleTimeoutMs = decoder.readSmallInt();
        periodicCheckIntervalMs = decoder.readSmallInt();
        singleUse = decoder.readBoolean();
        daemonUid = decoder.readString();
        priority = DaemonParameters.Priority.values()[decoder.readSmallInt()];
        int argCount = decoder.readSmallInt();
        startupOpts = new ArrayList<String>(argCount);
        for (int i = 0; i < argCount; i++) {
            startupOpts.add(decoder.readString());
        }
        int additionalClassPathLength = decoder.readSmallInt();
        additionalClassPath = new ArrayList<File>(additionalClassPathLength);
        for (int i = 0; i < additionalClassPathLength; i++) {
            additionalClassPath.add(new File(decoder.readString()));
        }
    } catch (EOFException e) {
        throw new UncheckedIOException(e);
    }
    NativeServices.initializeOnDaemon(gradleHomeDir);
    DaemonServerConfiguration parameters = new DefaultDaemonServerConfiguration(daemonUid, daemonBaseDir, idleTimeoutMs, periodicCheckIntervalMs, singleUse, priority, startupOpts);
    LoggingServiceRegistry loggingRegistry = LoggingServiceRegistry.newCommandLineProcessLogging();
    LoggingManagerInternal loggingManager = loggingRegistry.newInstance(LoggingManagerInternal.class);
    DaemonServices daemonServices = new DaemonServices(parameters, loggingRegistry, loggingManager, DefaultClassPath.of(additionalClassPath));
    File daemonLog = daemonServices.getDaemonLogFile();
    // Any logging prior to this point will not end up in the daemon log file.
    initialiseLogging(loggingManager, daemonLog);
    // Detach the process from the parent terminal/console
    ProcessEnvironment processEnvironment = daemonServices.get(ProcessEnvironment.class);
    processEnvironment.maybeDetachProcess();
    LOGGER.debug("Assuming the daemon was started with following jvm opts: {}", startupOpts);
    Daemon daemon = daemonServices.get(Daemon.class);
    daemon.start();
    try {
        DaemonContext daemonContext = daemonServices.get(DaemonContext.class);
        Long pid = daemonContext.getPid();
        daemonStarted(pid, daemon.getUid(), daemon.getAddress(), daemonLog);
        DaemonExpirationStrategy expirationStrategy = daemonServices.get(MasterExpirationStrategy.class);
        daemon.stopOnExpiration(expirationStrategy, parameters.getPeriodicCheckIntervalMs());
    } finally {
        daemon.stop();
        // TODO: Stop all daemon services
        CompositeStoppable.stoppable(daemonServices.get(GradleUserHomeScopeServiceRegistry.class)).stop();
    }
}
Also used : UncheckedIOException(org.gradle.api.UncheckedIOException) ProcessEnvironment(org.gradle.internal.nativeintegration.ProcessEnvironment) DaemonParameters(org.gradle.launcher.daemon.configuration.DaemonParameters) DaemonContext(org.gradle.launcher.daemon.context.DaemonContext) EOFException(java.io.EOFException) DaemonExpirationStrategy(org.gradle.launcher.daemon.server.expiry.DaemonExpirationStrategy) LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) DefaultDaemonServerConfiguration(org.gradle.launcher.daemon.configuration.DefaultDaemonServerConfiguration) EncodedStream(org.gradle.internal.stream.EncodedStream) EntryPoint(org.gradle.launcher.bootstrap.EntryPoint) LoggingServiceRegistry(org.gradle.internal.logging.services.LoggingServiceRegistry) KryoBackedDecoder(org.gradle.internal.serialize.kryo.KryoBackedDecoder) DaemonServerConfiguration(org.gradle.launcher.daemon.configuration.DaemonServerConfiguration) DefaultDaemonServerConfiguration(org.gradle.launcher.daemon.configuration.DefaultDaemonServerConfiguration) Daemon(org.gradle.launcher.daemon.server.Daemon) DaemonServices(org.gradle.launcher.daemon.server.DaemonServices) File(java.io.File)

Aggregations

LoggingManagerInternal (org.gradle.internal.logging.LoggingManagerInternal)2 Daemon (org.gradle.launcher.daemon.server.Daemon)2 DaemonServices (org.gradle.launcher.daemon.server.DaemonServices)2 DaemonExpirationStrategy (org.gradle.launcher.daemon.server.expiry.DaemonExpirationStrategy)2 EOFException (java.io.EOFException)1 File (java.io.File)1 UncheckedIOException (org.gradle.api.UncheckedIOException)1 LoggingServiceRegistry (org.gradle.internal.logging.services.LoggingServiceRegistry)1 ProcessEnvironment (org.gradle.internal.nativeintegration.ProcessEnvironment)1 KryoBackedDecoder (org.gradle.internal.serialize.kryo.KryoBackedDecoder)1 EncodedStream (org.gradle.internal.stream.EncodedStream)1 EntryPoint (org.gradle.launcher.bootstrap.EntryPoint)1 DaemonParameters (org.gradle.launcher.daemon.configuration.DaemonParameters)1 DaemonServerConfiguration (org.gradle.launcher.daemon.configuration.DaemonServerConfiguration)1 DefaultDaemonServerConfiguration (org.gradle.launcher.daemon.configuration.DefaultDaemonServerConfiguration)1 DaemonContext (org.gradle.launcher.daemon.context.DaemonContext)1 DaemonRegistry (org.gradle.launcher.daemon.registry.DaemonRegistry)1