public void initialize(TwillContext context) {
Map<String, String> runnableArgs = context.getSpecification().getConfigs();
String serviceClassName = runnableArgs.get("service.class.name");
datasets = GSON.fromJson(runnableArgs.get("service.datasets"), new TypeToken<Set<String>>() { }.getType());
InstantiatorFactory factory = new InstantiatorFactory(false);
try {
TypeToken<?> type = TypeToken.of(programClassLoader.loadClass(serviceClassName));
worker = (ServiceWorker) factory.get(type).create();
Reflections.visit(worker, type, new MetricsFieldSetter(metrics),
new PropertyFieldSetter(runnableArgs));
if (worker instanceof GuavaServiceWorker) {
String delegateClassName = runnableArgs.get("delegate.class.name");
type = TypeToken.of(programClassLoader.loadClass(delegateClassName));
((GuavaServiceWorker) worker).setDelegate((Service) factory.get(type).create());
}
int instanceId = context.getInstanceId();
worker.initialize(new BasicServiceWorkerContext(program, runId, instanceId, runnableName, programClassLoader,
cConfiguration, context.getSpecification().getConfigs(), datasets,
metricsCollectionService, datasetFramework,