Search in sources :

Example 1 with ConnectionAcceptor

use of org.gradle.internal.remote.ConnectionAcceptor in project gradle by gradle.

the class DefaultWorkerProcessBuilder method build.

@Override
public WorkerProcess build() {
    final WorkerJvmMemoryStatus memoryStatus = shouldPublishJvmMemoryInfo ? new WorkerJvmMemoryStatus() : null;
    final DefaultWorkerProcess workerProcess = new DefaultWorkerProcess(connectTimeoutSeconds, TimeUnit.SECONDS, memoryStatus);
    ConnectionAcceptor acceptor = server.accept(new Action<ObjectConnection>() {

        public void execute(final ObjectConnection connection) {
            workerProcess.onConnect(connection, new Runnable() {

                @Override
                public void run() {
                    DefaultWorkerLoggingProtocol defaultWorkerLoggingProtocol = new DefaultWorkerLoggingProtocol(outputEventListener);
                    connection.useParameterSerializers(WorkerLoggingSerializer.create());
                    connection.addIncoming(WorkerLoggingProtocol.class, defaultWorkerLoggingProtocol);
                    if (shouldPublishJvmMemoryInfo) {
                        connection.useParameterSerializers(WorkerJvmMemoryInfoSerializer.create());
                        connection.addIncoming(WorkerJvmMemoryInfoProtocol.class, memoryStatus);
                    }
                }
            });
        }
    });
    workerProcess.startAccepting(acceptor);
    Address localAddress = acceptor.getAddress();
    // Build configuration for GradleWorkerMain
    Object id = idGenerator.generateId();
    String displayName = getBaseName() + " " + id;
    LOGGER.debug("Creating {}", displayName);
    LOGGER.debug("Using application classpath {}", applicationClasspath);
    LOGGER.debug("Using implementation classpath {}", implementationClassPath);
    JavaExecHandleBuilder javaCommand = getJavaCommand();
    javaCommand.setDisplayName(displayName);
    workerImplementationFactory.prepareJavaCommand(id, displayName, this, implementationClassPath, localAddress, javaCommand, shouldPublishJvmMemoryInfo);
    javaCommand.args("'" + displayName + "'");
    ExecHandle execHandle = javaCommand.build();
    workerProcess.setExecHandle(execHandle);
    return new MemoryRequestingWorkerProcess(workerProcess, memoryManager, MemoryAmount.parseNotation(javaCommand.getMinHeapSize()));
}
Also used : ConnectionAcceptor(org.gradle.internal.remote.ConnectionAcceptor) Address(org.gradle.internal.remote.Address) JavaExecHandleBuilder(org.gradle.process.internal.JavaExecHandleBuilder) ObjectConnection(org.gradle.internal.remote.ObjectConnection) ExecHandle(org.gradle.process.internal.ExecHandle)

Example 2 with ConnectionAcceptor

use of org.gradle.internal.remote.ConnectionAcceptor in project gradle by gradle.

the class TcpIncomingConnector method accept.

public ConnectionAcceptor accept(Action<ConnectCompletion> action, boolean allowRemote) {
    final ServerSocketChannel serverSocket;
    int localPort;
    try {
        serverSocket = ServerSocketChannel.open();
        serverSocket.socket().bind(new InetSocketAddress(addressFactory.getLocalBindingAddress(), 0));
        localPort = serverSocket.socket().getLocalPort();
    } catch (Exception e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
    UUID id = idGenerator.generateId();
    List<InetAddress> addresses = addressFactory.getCommunicationAddresses();
    final Address address = new MultiChoiceAddress(id, localPort, addresses);
    LOGGER.debug("Listening on {}.", address);
    final StoppableExecutor executor = executorFactory.create("Incoming " + (allowRemote ? "remote" : "local") + " TCP Connector on port " + localPort);
    executor.execute(new Receiver(serverSocket, action, allowRemote));
    return new ConnectionAcceptor() {

        public Address getAddress() {
            return address;
        }

        public void requestStop() {
            CompositeStoppable.stoppable(serverSocket).stop();
        }

        public void stop() {
            requestStop();
            executor.stop();
        }
    };
}
Also used : ConnectionAcceptor(org.gradle.internal.remote.ConnectionAcceptor) InetSocketAddress(java.net.InetSocketAddress) Address(org.gradle.internal.remote.Address) InetAddress(java.net.InetAddress) InetSocketAddress(java.net.InetSocketAddress) StoppableExecutor(org.gradle.internal.concurrent.StoppableExecutor) UUID(java.util.UUID) InetAddress(java.net.InetAddress) ServerSocketChannel(java.nio.channels.ServerSocketChannel) ClosedChannelException(java.nio.channels.ClosedChannelException) UncheckedException(org.gradle.internal.UncheckedException)

Aggregations

Address (org.gradle.internal.remote.Address)2 ConnectionAcceptor (org.gradle.internal.remote.ConnectionAcceptor)2 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1 ServerSocketChannel (java.nio.channels.ServerSocketChannel)1 UUID (java.util.UUID)1 UncheckedException (org.gradle.internal.UncheckedException)1 StoppableExecutor (org.gradle.internal.concurrent.StoppableExecutor)1 ObjectConnection (org.gradle.internal.remote.ObjectConnection)1 ExecHandle (org.gradle.process.internal.ExecHandle)1 JavaExecHandleBuilder (org.gradle.process.internal.JavaExecHandleBuilder)1