use of org.gradle.internal.remote.ObjectConnection 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;
}
use of org.gradle.internal.remote.ObjectConnection in project gradle by gradle.
the class WorkerAction method execute.
@Override
public void execute(WorkerProcessContext workerProcessContext) {
completed = new CountDownLatch(1);
try {
workerImplementation = Class.forName(workerImplementationName);
implementation = workerImplementation.newInstance();
} catch (Throwable e) {
failure = e;
}
ObjectConnection connection = workerProcessContext.getServerConnection();
connection.addIncoming(RequestProtocol.class, this);
responder = connection.addOutgoing(ResponseProtocol.class);
connection.connect();
try {
completed.await();
} catch (InterruptedException e) {
throw UncheckedException.throwAsUncheckedException(e);
}
}
use of org.gradle.internal.remote.ObjectConnection in project gradle by gradle.
the class DefaultSingleRequestWorkerProcessBuilder method build.
@Override
public PROTOCOL build() {
return protocolType.cast(Proxy.newProxyInstance(protocolType.getClassLoader(), new Class[] { protocolType }, new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Receiver receiver = new Receiver(getBaseName());
try {
WorkerProcess workerProcess = builder.build();
workerProcess.start();
ObjectConnection connection = workerProcess.getConnection();
RequestProtocol requestProtocol = connection.addOutgoing(RequestProtocol.class);
connection.addIncoming(ResponseProtocol.class, receiver);
connection.useJavaSerializationForParameters(workerImplementation.getClassLoader());
connection.connect();
requestProtocol.runThenStop(method.getName(), method.getParameterTypes(), args);
boolean hasResult = receiver.awaitNextResult();
workerProcess.waitForStop();
if (!hasResult) {
// Reached the end of input, worker has exited without failing
throw new IllegalStateException(String.format("No response was received from %s but the worker process has finished.", getBaseName()));
}
} catch (Exception e) {
throw WorkerProcessException.runFailed(getBaseName(), e);
}
return receiver.getNextResult();
}
}));
}
use of org.gradle.internal.remote.ObjectConnection 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.ObjectConnection in project gradle by gradle.
the class ActionExecutionWorker method execute.
public void execute(final WorkerContext workerContext) {
final ObjectConnection clientConnection = workerContext.getServerConnection();
LOGGER.debug("Starting {}.", displayName);
WorkerProcessContext context = new WorkerProcessContext() {
public ObjectConnection getServerConnection() {
return clientConnection;
}
public ClassLoader getApplicationClassLoader() {
return workerContext.getApplicationClassLoader();
}
public Object getWorkerId() {
return workerId;
}
public String getDisplayName() {
return displayName;
}
};
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(action.getClass().getClassLoader());
NativeServices.initialize(gradleUserHomeDir, false);
try {
action.execute(context);
} finally {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
LOGGER.debug("Completed {}.", displayName);
}
Aggregations