use of org.gradle.internal.remote.internal.inet.MultiChoiceAddressSerializer 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.internal.inet.MultiChoiceAddressSerializer in project gradle by gradle.
the class ApplicationClassesInSystemClassLoaderWorkerImplementationFactory method prepareJavaCommand.
@Override
public void prepareJavaCommand(Object workerId, String displayName, DefaultWorkerProcessBuilder processBuilder, List<URL> implementationClassPath, Address serverAddress, JavaExecHandleBuilder execSpec, boolean publishProcessInfo) {
Collection<File> applicationClasspath = processBuilder.getApplicationClasspath();
LogLevel logLevel = processBuilder.getLogLevel();
Set<String> sharedPackages = processBuilder.getSharedPackages();
Object requestedSecurityManager = execSpec.getSystemProperties().get("java.security.manager");
ClassPath workerMainClassPath = classPathRegistry.getClassPath("WORKER_MAIN");
execSpec.setMain("worker." + GradleWorkerMain.class.getName());
boolean useOptionsFile = shouldUseOptionsFile(execSpec);
if (useOptionsFile) {
// Use an options file to pass across application classpath
File optionsFile = temporaryFileProvider.createTemporaryFile("gradle-worker-classpath", "txt");
List<String> jvmArgs = writeOptionsFile(workerMainClassPath.getAsFiles(), applicationClasspath, optionsFile);
execSpec.jvmArgs(jvmArgs);
} else {
// Use a dummy security manager, which hacks the application classpath into the system ClassLoader
execSpec.classpath(workerMainClassPath.getAsFiles());
execSpec.systemProperty("java.security.manager", "worker." + BootstrapSecurityManager.class.getName());
}
// Serialize configuration for the worker process to it stdin
StreamByteBuffer buffer = new StreamByteBuffer();
try {
DataOutputStream outstr = new DataOutputStream(new EncodedStream.EncodedOutput(buffer.getOutputStream()));
if (!useOptionsFile) {
// Serialize the application classpath, this is consumed by BootstrapSecurityManager
outstr.writeInt(applicationClasspath.size());
for (File file : applicationClasspath) {
outstr.writeUTF(file.getAbsolutePath());
}
// Serialize the actual security manager type, this is consumed by BootstrapSecurityManager
outstr.writeUTF(requestedSecurityManager == null ? "" : requestedSecurityManager.toString());
}
// Serialize the shared packages, this is consumed by GradleWorkerMain
outstr.writeInt(sharedPackages.size());
for (String str : sharedPackages) {
outstr.writeUTF(str);
}
// Serialize the worker implementation classpath, this is consumed by GradleWorkerMain
outstr.writeInt(implementationClassPath.size());
for (URL entry : implementationClassPath) {
outstr.writeUTF(entry.toString());
}
// Serialize the worker config, this is consumed by SystemApplicationClassLoaderWorker
OutputStreamBackedEncoder encoder = new OutputStreamBackedEncoder(outstr);
encoder.writeSmallInt(logLevel.ordinal());
encoder.writeBoolean(publishProcessInfo);
new MultiChoiceAddressSerializer().write(encoder, (MultiChoiceAddress) serverAddress);
// Serialize the worker, this is consumed by SystemApplicationClassLoaderWorker
ActionExecutionWorker worker = new ActionExecutionWorker(processBuilder.getWorker(), workerId, displayName, processBuilder.getGradleUserHomeDir());
byte[] serializedWorker = GUtil.serialize(worker);
encoder.writeBinary(serializedWorker);
encoder.flush();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
execSpec.setStandardInput(buffer.getInputStream());
}
use of org.gradle.internal.remote.internal.inet.MultiChoiceAddressSerializer 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.internal.inet.MultiChoiceAddressSerializer 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.
}
Aggregations