Search in sources :

Example 1 with Decoder

use of org.gradle.internal.serialize.Decoder 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 Decoder

use of org.gradle.internal.serialize.Decoder in project gradle by gradle.

the class TestResultSerializer method read.

public void read(Action<? super TestClassResult> visitor) {
    if (!isHasResults()) {
        return;
    }
    try {
        InputStream inputStream = new FileInputStream(resultsFile);
        try {
            Decoder decoder = new KryoBackedDecoder(inputStream);
            int version = decoder.readSmallInt();
            if (version != RESULT_VERSION) {
                throw new IllegalArgumentException(String.format("Unexpected result file version %d found in %s.", version, resultsFile));
            }
            readResults(decoder, visitor);
        } finally {
            inputStream.close();
        }
    } catch (Exception e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
Also used : KryoBackedDecoder(org.gradle.internal.serialize.kryo.KryoBackedDecoder) Decoder(org.gradle.internal.serialize.Decoder) KryoBackedDecoder(org.gradle.internal.serialize.kryo.KryoBackedDecoder) UncheckedException(org.gradle.internal.UncheckedException) UncheckedIOException(org.gradle.api.UncheckedIOException)

Example 3 with Decoder

use of org.gradle.internal.serialize.Decoder in project gradle by gradle.

the class DaemonStartupCommunication method readDiagnostics.

public DaemonStartupInfo readDiagnostics(String message) {
    // Assuming the message has correct format. Not bullet proof, but seems to work ok for now.
    if (!message.startsWith(daemonGreeting())) {
        throw new IllegalArgumentException(String.format("Unexpected daemon startup message: %s", message));
    }
    try {
        String encoded = message.substring(daemonGreeting().length()).trim();
        InputStream inputStream = new EncodedStream.EncodedInput(new ByteArrayInputStream(encoded.getBytes()));
        Decoder decoder = new InputStreamBackedDecoder(inputStream);
        String pidString = decoder.readNullableString();
        String uid = decoder.readString();
        Long pid = pidString == null ? null : Long.parseLong(pidString);
        Address address = new MultiChoiceAddressSerializer().read(decoder);
        File daemonLog = new File(decoder.readString());
        return new DaemonStartupInfo(uid, address, new DaemonDiagnostics(daemonLog, pid));
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : InputStreamBackedDecoder(org.gradle.internal.serialize.InputStreamBackedDecoder) Address(org.gradle.internal.remote.Address) MultiChoiceAddress(org.gradle.internal.remote.internal.inet.MultiChoiceAddress) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) Decoder(org.gradle.internal.serialize.Decoder) InputStreamBackedDecoder(org.gradle.internal.serialize.InputStreamBackedDecoder) ByteArrayInputStream(java.io.ByteArrayInputStream) DaemonStartupInfo(org.gradle.launcher.daemon.diagnostics.DaemonStartupInfo) DaemonDiagnostics(org.gradle.launcher.daemon.diagnostics.DaemonDiagnostics) File(java.io.File) MultiChoiceAddressSerializer(org.gradle.internal.remote.internal.inet.MultiChoiceAddressSerializer)

Aggregations

Decoder (org.gradle.internal.serialize.Decoder)3 File (java.io.File)2 UncheckedIOException (org.gradle.api.UncheckedIOException)2 MultiChoiceAddress (org.gradle.internal.remote.internal.inet.MultiChoiceAddress)2 MultiChoiceAddressSerializer (org.gradle.internal.remote.internal.inet.MultiChoiceAddressSerializer)2 InputStreamBackedDecoder (org.gradle.internal.serialize.InputStreamBackedDecoder)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UncheckedException (org.gradle.internal.UncheckedException)1 DefaultExecutorFactory (org.gradle.internal.concurrent.DefaultExecutorFactory)1 LoggingManagerInternal (org.gradle.internal.logging.LoggingManagerInternal)1 LoggingServiceRegistry (org.gradle.internal.logging.services.LoggingServiceRegistry)1 Address (org.gradle.internal.remote.Address)1 ObjectConnection (org.gradle.internal.remote.ObjectConnection)1 MessagingServices (org.gradle.internal.remote.services.MessagingServices)1 KryoBackedDecoder (org.gradle.internal.serialize.kryo.KryoBackedDecoder)1 DefaultServiceRegistry (org.gradle.internal.service.DefaultServiceRegistry)1 DaemonDiagnostics (org.gradle.launcher.daemon.diagnostics.DaemonDiagnostics)1 DaemonStartupInfo (org.gradle.launcher.daemon.diagnostics.DaemonStartupInfo)1