use of org.gradle.internal.remote.Address 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()));
}
use of org.gradle.internal.remote.Address 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();
}
};
}
use of org.gradle.internal.remote.Address 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);
}
}
use of org.gradle.internal.remote.Address in project gradle by gradle.
the class PersistentDaemonRegistry method store.
public void store(final DaemonInfo info) {
final Address address = info.getAddress();
final DaemonContext daemonContext = info.getContext();
final byte[] token = info.getToken();
final State state = info.getState();
lock.lock();
LOGGER.debug("Storing daemon address: {}, context: {}", address, daemonContext);
try {
cache.update(new PersistentStateCache.UpdateAction<DaemonRegistryContent>() {
public DaemonRegistryContent update(DaemonRegistryContent oldValue) {
if (oldValue == null) {
//it means the registry didn't exist yet
oldValue = new DaemonRegistryContent();
}
DaemonInfo daemonInfo = new DaemonInfo(address, daemonContext, token, state);
oldValue.setStatus(address, daemonInfo);
return oldValue;
}
});
} finally {
lock.unlock();
}
}
Aggregations