Search in sources :

Example 1 with MultiChoiceAddress

use of org.gradle.internal.remote.internal.inet.MultiChoiceAddress 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 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);
    MessagingServices messagingServices = new MessagingServices();
    final WorkerServices workerServices = new WorkerServices(messagingServices, gradleUserHomeDir);
    ObjectConnection connection = null;
    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);
        }
        connection = messagingServices.get(MessagingClient.class).getConnection(serverAddress);
        workerLogEventListener = configureLogging(loggingManager, connection);
        if (shouldPublishJvmMemoryInfo) {
            configureWorkerJvmMemoryInfoEvents(workerServices, connection);
        }
        final ObjectConnection serverConnection = connection;
        action.execute(new WorkerContext() {

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

            @Override
            public ObjectConnection getServerConnection() {
                return serverConnection;
            }

            @Override
            public ServiceRegistry getServiceRegistry() {
                return workerServices;
            }
        });
    } finally {
        if (workerLogEventListener != null) {
            loggingManager.removeOutputEventListener(workerLogEventListener);
        }
        if (connection != null) {
            connection.stop();
        }
        messagingServices.close();
        loggingManager.stop();
    }
    return null;
}
Also used : InputStreamBackedDecoder(org.gradle.internal.serialize.InputStreamBackedDecoder) LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) 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) ObjectConnection(org.gradle.internal.remote.ObjectConnection) UncheckedException(org.gradle.internal.UncheckedException) ByteArrayInputStream(java.io.ByteArrayInputStream) MultiChoiceAddress(org.gradle.internal.remote.internal.inet.MultiChoiceAddress) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) DefaultServiceRegistry(org.gradle.internal.service.DefaultServiceRegistry) LoggingServiceRegistry(org.gradle.internal.logging.services.LoggingServiceRegistry) File(java.io.File) MultiChoiceAddressSerializer(org.gradle.internal.remote.internal.inet.MultiChoiceAddressSerializer) ObjectInputStream(java.io.ObjectInputStream) ClassLoaderObjectInputStream(org.gradle.internal.io.ClassLoaderObjectInputStream)

Example 2 with MultiChoiceAddress

use of org.gradle.internal.remote.internal.inet.MultiChoiceAddress in project gradle by gradle.

the class DaemonStartupCommunication method printDaemonStarted.

public void printDaemonStarted(PrintStream target, Long pid, String uid, Address address, File daemonLog) {
    target.print(daemonGreeting());
    // Encode as ascii
    try {
        OutputStream outputStream = new EncodedStream.EncodedOutput(target);
        FlushableEncoder encoder = new OutputStreamBackedEncoder(outputStream);
        encoder.writeNullableString(pid == null ? null : pid.toString());
        encoder.writeString(uid);
        MultiChoiceAddress multiChoiceAddress = (MultiChoiceAddress) address;
        new MultiChoiceAddressSerializer().write(encoder, multiChoiceAddress);
        encoder.writeString(daemonLog.getPath());
        encoder.flush();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    target.println();
    // ibm vm 1.6 + windows XP gotchas:
    // we need to print something else to the stream after we print the daemon greeting.
    // without it, the parent hangs without receiving the message above (flushing does not help).
    LOGGER.debug("Completed writing the daemon greeting. Closing streams...");
// btw. the ibm vm+winXP also has some issues detecting closed streams by the child but we handle this problem differently.
}
Also used : FlushableEncoder(org.gradle.internal.serialize.FlushableEncoder) MultiChoiceAddress(org.gradle.internal.remote.internal.inet.MultiChoiceAddress) OutputStreamBackedEncoder(org.gradle.internal.serialize.OutputStreamBackedEncoder) UncheckedIOException(org.gradle.api.UncheckedIOException) UncheckedIOException(org.gradle.api.UncheckedIOException) MultiChoiceAddressSerializer(org.gradle.internal.remote.internal.inet.MultiChoiceAddressSerializer)

Aggregations

MultiChoiceAddress (org.gradle.internal.remote.internal.inet.MultiChoiceAddress)2 MultiChoiceAddressSerializer (org.gradle.internal.remote.internal.inet.MultiChoiceAddressSerializer)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 ObjectInputStream (java.io.ObjectInputStream)1 UncheckedIOException (org.gradle.api.UncheckedIOException)1 UncheckedException (org.gradle.internal.UncheckedException)1 ClassLoaderObjectInputStream (org.gradle.internal.io.ClassLoaderObjectInputStream)1 LoggingManagerInternal (org.gradle.internal.logging.LoggingManagerInternal)1 LoggingServiceRegistry (org.gradle.internal.logging.services.LoggingServiceRegistry)1 ObjectConnection (org.gradle.internal.remote.ObjectConnection)1 MessagingServices (org.gradle.internal.remote.services.MessagingServices)1 Decoder (org.gradle.internal.serialize.Decoder)1 FlushableEncoder (org.gradle.internal.serialize.FlushableEncoder)1 InputStreamBackedDecoder (org.gradle.internal.serialize.InputStreamBackedDecoder)1 OutputStreamBackedEncoder (org.gradle.internal.serialize.OutputStreamBackedEncoder)1 DefaultServiceRegistry (org.gradle.internal.service.DefaultServiceRegistry)1 ServiceRegistry (org.gradle.internal.service.ServiceRegistry)1