in sdk/host/src/main/java/org/apache/teaclave/javasdk/host/AbstractEnclave.java [145:167]
void unloadService(ServiceHandler service) throws ServicesUnloadingException {
if (!getEnclaveContext().getEnclaveToken().tryAcquireToken()) {
throw new ServicesUnloadingException("enclave was destroyed.");
}
try (MetricTraceContext trace = new MetricTraceContext(
this.getEnclaveInfo(),
MetricTraceContext.LogPrefix.METRIC_LOG_ENCLAVE_SERVICE_UNLOADING_PATTERN,
service.getServiceImplClassName())) {
EnclaveInvocationResult resultWrapper;
resultWrapper = (EnclaveInvocationResult) SerializationHelper.deserialize(unloadServiceNative(service));
trace.setCostInnerEnclave(resultWrapper.getCost());
Throwable exception = resultWrapper.getException();
if (exception != null) {
throw new ServicesUnloadingException("service unload exception happened in enclave.", exception);
}
} catch (IOException | ClassNotFoundException e) {
throw new ServicesUnloadingException("EnclaveInvokeResultWrapper deserialization failed.", e);
} catch (MetricTraceLogWriteException e) {
throw new ServicesUnloadingException(e);
} finally {
getEnclaveContext().getEnclaveToken().restoreToken();
}
}