Search in sources :

Example 1 with DefaultExecutorFactory

use of org.gradle.internal.concurrent.DefaultExecutorFactory in project gradle by gradle.

the class SystemApplicationClassLoaderWorker method call.

@Override
public Void call() throws Exception {
    if (System.getProperty("org.gradle.worker.test.stuck") != null) {
        // Simulate a stuck worker. There's probably a way to inject this failure...
        Thread.sleep(30000);
        return null;
    }
    Decoder decoder = new InputStreamBackedDecoder(configInputStream);
    // Read logging config and setup logging
    int logLevel = decoder.readSmallInt();
    LoggingServiceRegistry loggingServiceRegistry = LoggingServiceRegistry.newEmbeddableLogging();
    LoggingManagerInternal loggingManager = createLoggingManager(loggingServiceRegistry).setLevelInternal(LogLevel.values()[logLevel]);
    // Read whether process info should be published
    boolean shouldPublishJvmMemoryInfo = decoder.readBoolean();
    // Read path to Gradle user home
    String gradleUserHomeDirPath = decoder.readString();
    File gradleUserHomeDir = new File(gradleUserHomeDirPath);
    // Read server address and start connecting
    MultiChoiceAddress serverAddress = new MultiChoiceAddressSerializer().read(decoder);
    NativeServices.initializeOnWorker(gradleUserHomeDir);
    DefaultServiceRegistry basicWorkerServices = new DefaultServiceRegistry(NativeServices.getInstance(), loggingServiceRegistry);
    basicWorkerServices.add(ExecutorFactory.class, new DefaultExecutorFactory());
    basicWorkerServices.addProvider(new MessagingServices());
    final WorkerServices workerServices = new WorkerServices(basicWorkerServices, gradleUserHomeDir);
    WorkerLogEventListener workerLogEventListener = new WorkerLogEventListener();
    workerServices.add(WorkerLogEventListener.class, workerLogEventListener);
    File workingDirectory = workerServices.get(WorkerDirectoryProvider.class).getWorkingDirectory();
    File errorLog = getLastResortErrorLogFile(workingDirectory);
    PrintUnrecoverableErrorToFileHandler unrecoverableErrorHandler = new PrintUnrecoverableErrorToFileHandler(errorLog);
    ObjectConnection connection = null;
    try {
        // Read serialized worker details
        final long workerId = decoder.readSmallLong();
        final String displayName = decoder.readString();
        byte[] serializedWorker = decoder.readBinary();
        Action<WorkerProcessContext> workerAction = deserializeWorker(serializedWorker);
        connection = basicWorkerServices.get(MessagingClient.class).getConnection(serverAddress);
        connection.addUnrecoverableErrorHandler(unrecoverableErrorHandler);
        configureLogging(loggingManager, connection, workerLogEventListener);
        // start logging now that the logging manager is connected
        loggingManager.start();
        if (shouldPublishJvmMemoryInfo) {
            configureWorkerJvmMemoryInfoEvents(workerServices, connection);
        }
        ActionExecutionWorker worker = new ActionExecutionWorker(workerAction);
        worker.execute(new ContextImpl(workerId, displayName, connection, workerServices));
    } finally {
        try {
            loggingManager.removeOutputEventListener(workerLogEventListener);
            CompositeStoppable.stoppable(connection, basicWorkerServices).stop();
            loggingManager.stop();
        } catch (Throwable t) {
            // We're failing while shutting down, so log whatever might have happened.
            unrecoverableErrorHandler.execute(t);
        }
    }
    return null;
}
Also used : InputStreamBackedDecoder(org.gradle.internal.serialize.InputStreamBackedDecoder) MessagingServices(org.gradle.internal.remote.services.MessagingServices) Decoder(org.gradle.internal.serialize.Decoder) InputStreamBackedDecoder(org.gradle.internal.serialize.InputStreamBackedDecoder) DefaultServiceRegistry(org.gradle.internal.service.DefaultServiceRegistry) LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) LoggingServiceRegistry(org.gradle.internal.logging.services.LoggingServiceRegistry) DefaultExecutorFactory(org.gradle.internal.concurrent.DefaultExecutorFactory) ObjectConnection(org.gradle.internal.remote.ObjectConnection) MultiChoiceAddress(org.gradle.internal.remote.internal.inet.MultiChoiceAddress) WorkerProcessContext(org.gradle.process.internal.worker.WorkerProcessContext) File(java.io.File) MultiChoiceAddressSerializer(org.gradle.internal.remote.internal.inet.MultiChoiceAddressSerializer)

Example 2 with DefaultExecutorFactory

use of org.gradle.internal.concurrent.DefaultExecutorFactory in project gradle by gradle.

the class DefaultExecActionFactory method root.

// Do not use this. It's here because some of the services this type needs are not easily accessed in certain cases and will be removed ay some point. Use one of the other methods instead
@Deprecated
public static DefaultExecActionFactory root(File gradleUserHome) {
    requireNonNull(gradleUserHome, "gradleUserHome");
    Factory<PatternSet> patternSetFactory = PatternSets.getNonCachingPatternSetFactory();
    FileResolver resolver = new DefaultFileLookup().getFileResolver();
    DefaultFileCollectionFactory fileCollectionFactory = new DefaultFileCollectionFactory(resolver, DefaultTaskDependencyFactory.withNoAssociatedProject(), new DefaultDirectoryFileTreeFactory(), patternSetFactory, PropertyHost.NO_OP, FileSystems.getDefault());
    GradleUserHomeDirProvider userHomeDirProvider = () -> gradleUserHome;
    TemporaryFileProvider temporaryFileProvider = new GradleUserHomeTemporaryFileProvider(userHomeDirProvider);
    return of(resolver, fileCollectionFactory, new InstantiatorBackedObjectFactory(DirectInstantiator.INSTANCE), new DefaultExecutorFactory(), new DefaultBuildCancellationToken(), temporaryFileProvider);
}
Also used : InstantiatorBackedObjectFactory(org.gradle.api.internal.model.InstantiatorBackedObjectFactory) DefaultFileLookup(org.gradle.api.internal.file.DefaultFileLookup) GradleUserHomeDirProvider(org.gradle.initialization.GradleUserHomeDirProvider) DefaultBuildCancellationToken(org.gradle.initialization.DefaultBuildCancellationToken) DefaultDirectoryFileTreeFactory(org.gradle.api.internal.file.collections.DefaultDirectoryFileTreeFactory) GradleUserHomeTemporaryFileProvider(org.gradle.api.internal.file.temp.GradleUserHomeTemporaryFileProvider) TemporaryFileProvider(org.gradle.api.internal.file.temp.TemporaryFileProvider) GradleUserHomeTemporaryFileProvider(org.gradle.api.internal.file.temp.GradleUserHomeTemporaryFileProvider) FileResolver(org.gradle.api.internal.file.FileResolver) PatternSet(org.gradle.api.tasks.util.PatternSet) DefaultFileCollectionFactory(org.gradle.api.internal.file.DefaultFileCollectionFactory) DefaultExecutorFactory(org.gradle.internal.concurrent.DefaultExecutorFactory)

Aggregations

DefaultExecutorFactory (org.gradle.internal.concurrent.DefaultExecutorFactory)2 File (java.io.File)1 DefaultFileCollectionFactory (org.gradle.api.internal.file.DefaultFileCollectionFactory)1 DefaultFileLookup (org.gradle.api.internal.file.DefaultFileLookup)1 FileResolver (org.gradle.api.internal.file.FileResolver)1 DefaultDirectoryFileTreeFactory (org.gradle.api.internal.file.collections.DefaultDirectoryFileTreeFactory)1 GradleUserHomeTemporaryFileProvider (org.gradle.api.internal.file.temp.GradleUserHomeTemporaryFileProvider)1 TemporaryFileProvider (org.gradle.api.internal.file.temp.TemporaryFileProvider)1 InstantiatorBackedObjectFactory (org.gradle.api.internal.model.InstantiatorBackedObjectFactory)1 PatternSet (org.gradle.api.tasks.util.PatternSet)1 DefaultBuildCancellationToken (org.gradle.initialization.DefaultBuildCancellationToken)1 GradleUserHomeDirProvider (org.gradle.initialization.GradleUserHomeDirProvider)1 LoggingManagerInternal (org.gradle.internal.logging.LoggingManagerInternal)1 LoggingServiceRegistry (org.gradle.internal.logging.services.LoggingServiceRegistry)1 ObjectConnection (org.gradle.internal.remote.ObjectConnection)1 MultiChoiceAddress (org.gradle.internal.remote.internal.inet.MultiChoiceAddress)1 MultiChoiceAddressSerializer (org.gradle.internal.remote.internal.inet.MultiChoiceAddressSerializer)1 MessagingServices (org.gradle.internal.remote.services.MessagingServices)1 Decoder (org.gradle.internal.serialize.Decoder)1 InputStreamBackedDecoder (org.gradle.internal.serialize.InputStreamBackedDecoder)1