Search in sources :

Example 1 with InputStreamBackedDecoder

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

the class SystemApplicationClassLoaderWorker method call.

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();
    LoggingManagerInternal loggingManager = createLoggingManager();
    loggingManager.setLevelInternal(LogLevel.values()[logLevel]).start();
    // Read whether process info should be published
    boolean shouldPublishJvmMemoryInfo = decoder.readBoolean();
    // Read server address and start connecting
    MultiChoiceAddress serverAddress = new MultiChoiceAddressSerializer().read(decoder);
    MessagingServices messagingServices = new MessagingServices();
    WorkerServices workerServices = new WorkerServices(messagingServices);
    WorkerLogEventListener workerLogEventListener = null;
    try {
        // Read serialized worker
        byte[] serializedWorker = decoder.readBinary();
        // Deserialize the worker action
        Action<WorkerContext> action;
        try {
            ObjectInputStream instr = new ClassLoaderObjectInputStream(new ByteArrayInputStream(serializedWorker), getClass().getClassLoader());
            action = (Action<WorkerContext>) instr.readObject();
        } catch (Exception e) {
            throw UncheckedException.throwAsUncheckedException(e);
        }
        final ObjectConnection connection = messagingServices.get(MessagingClient.class).getConnection(serverAddress);
        workerLogEventListener = configureLogging(loggingManager, connection);
        if (shouldPublishJvmMemoryInfo) {
            configureWorkerJvmMemoryInfoEvents(workerServices, connection);
        }
        try {
            action.execute(new WorkerContext() {

                public ClassLoader getApplicationClassLoader() {
                    return ClassLoader.getSystemClassLoader();
                }

                @Override
                public ObjectConnection getServerConnection() {
                    return connection;
                }
            });
        } finally {
            connection.stop();
        }
    } finally {
        if (workerLogEventListener != null) {
            loggingManager.removeOutputEventListener(workerLogEventListener);
        }
        messagingServices.close();
        loggingManager.stop();
    }
    return null;
}
Also used : InputStreamBackedDecoder(org.gradle.internal.serialize.InputStreamBackedDecoder) LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) MessagingClient(org.gradle.internal.remote.MessagingClient) MessagingServices(org.gradle.internal.remote.services.MessagingServices) ClassLoaderObjectInputStream(org.gradle.internal.io.ClassLoaderObjectInputStream) Decoder(org.gradle.internal.serialize.Decoder) InputStreamBackedDecoder(org.gradle.internal.serialize.InputStreamBackedDecoder) UncheckedException(org.gradle.internal.UncheckedException) ObjectConnection(org.gradle.internal.remote.ObjectConnection) ByteArrayInputStream(java.io.ByteArrayInputStream) MultiChoiceAddress(org.gradle.internal.remote.internal.inet.MultiChoiceAddress) MultiChoiceAddressSerializer(org.gradle.internal.remote.internal.inet.MultiChoiceAddressSerializer) ObjectInputStream(java.io.ObjectInputStream) ClassLoaderObjectInputStream(org.gradle.internal.io.ClassLoaderObjectInputStream)

Example 2 with InputStreamBackedDecoder

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

the class InMemoryIndexedCache method get.

@Override
public V get(K key) {
    byte[] serialised = entries.get(key);
    if (serialised == null) {
        return null;
    }
    try {
        ByteArrayInputStream instr = new ByteArrayInputStream(serialised);
        InputStreamBackedDecoder decoder = new InputStreamBackedDecoder(instr);
        return valueSerializer.read(decoder);
    } catch (Exception e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
Also used : InputStreamBackedDecoder(org.gradle.internal.serialize.InputStreamBackedDecoder) ByteArrayInputStream(java.io.ByteArrayInputStream) UncheckedException(org.gradle.internal.UncheckedException)

Example 3 with InputStreamBackedDecoder

use of org.gradle.internal.serialize.InputStreamBackedDecoder 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.valueOf(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) UncheckedIOException(org.gradle.api.UncheckedIOException) UncheckedIOException(org.gradle.api.UncheckedIOException) Decoder(org.gradle.internal.serialize.Decoder) InputStreamBackedDecoder(org.gradle.internal.serialize.InputStreamBackedDecoder) DaemonStartupInfo(org.gradle.launcher.daemon.diagnostics.DaemonStartupInfo) DaemonDiagnostics(org.gradle.launcher.daemon.diagnostics.DaemonDiagnostics) MultiChoiceAddressSerializer(org.gradle.internal.remote.internal.inet.MultiChoiceAddressSerializer)

Aggregations

InputStreamBackedDecoder (org.gradle.internal.serialize.InputStreamBackedDecoder)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 UncheckedException (org.gradle.internal.UncheckedException)2 MultiChoiceAddress (org.gradle.internal.remote.internal.inet.MultiChoiceAddress)2 MultiChoiceAddressSerializer (org.gradle.internal.remote.internal.inet.MultiChoiceAddressSerializer)2 Decoder (org.gradle.internal.serialize.Decoder)2 ObjectInputStream (java.io.ObjectInputStream)1 UncheckedIOException (org.gradle.api.UncheckedIOException)1 ClassLoaderObjectInputStream (org.gradle.internal.io.ClassLoaderObjectInputStream)1 LoggingManagerInternal (org.gradle.internal.logging.LoggingManagerInternal)1 Address (org.gradle.internal.remote.Address)1 MessagingClient (org.gradle.internal.remote.MessagingClient)1 ObjectConnection (org.gradle.internal.remote.ObjectConnection)1 MessagingServices (org.gradle.internal.remote.services.MessagingServices)1 DaemonDiagnostics (org.gradle.launcher.daemon.diagnostics.DaemonDiagnostics)1 DaemonStartupInfo (org.gradle.launcher.daemon.diagnostics.DaemonStartupInfo)1