use of org.gradle.internal.serialize.InputStreamBackedDecoder 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.serialize.InputStreamBackedDecoder in project gradle by gradle.
the class InMemoryIndexedCache method get.
@Override
public V get(K key) {
byte[] serialised = entries.get(key);
if (serialised == null) {
return null;
}
try {
ByteArrayInputStream instr = new ByteArrayInputStream(serialised);
InputStreamBackedDecoder decoder = new InputStreamBackedDecoder(instr);
return valueSerializer.read(decoder);
} catch (Exception e) {
throw UncheckedException.throwAsUncheckedException(e);
}
}
use of org.gradle.internal.serialize.InputStreamBackedDecoder 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);
}
}
Aggregations