int instanceCount = Integer.parseInt(options.getArguments().getOption(ProgramOptionConstants.INSTANCES, "0"));
Preconditions.checkArgument(instanceCount > 0, "Invalid or missing instance count");
String runIdOption = options.getArguments().getOption(ProgramOptionConstants.RUN_ID);
Preconditions.checkNotNull(runIdOption, "Missing runId");
RunId runId = RunIds.fromString(runIdOption);
ApplicationSpecification appSpec = program.getSpecification();
Preconditions.checkNotNull(appSpec, "Missing application specification.");
ProgramType processorType = program.getType();
Preconditions.checkNotNull(processorType, "Missing processor type.");
Preconditions.checkArgument(processorType == ProgramType.SERVICE, "Only Service process type is supported.");
String processorName = program.getName();
Preconditions.checkNotNull(processorName, "Missing processor name.");
ServiceSpecification serviceSpec = appSpec.getServices().get(processorName);
RuntimeSpecification runnableSpec = serviceSpec.getRunnables().get(runnableName);
Preconditions.checkNotNull(runnableSpec, "RuntimeSpecification missing for Runnable \"%s\"", runnableName);
Class<?> clz = null;
String classStr = runnableSpec.getRunnableSpecification().getClassName();
// special case for handling http service
if (classStr.equals(HttpServiceTwillRunnable.class.getName())) {
clz = HttpServiceTwillRunnable.class;
} else {
clz = Class.forName(runnableSpec.getRunnableSpecification().getClassName(),
true, program.getClassLoader());
}
Preconditions.checkArgument(TwillRunnable.class.isAssignableFrom(clz), "%s is not a TwillRunnable.", clz);
Class<? extends TwillRunnable> runnableClass = (Class<? extends TwillRunnable>) clz;
RunId twillRunId = RunIds.generate();
final String[] argArray = RuntimeArguments.toPosixArray(options.getUserArguments());
DiscoveryService dService = new DiscoveryService() {
@Override
public Cancellable register(final Discoverable discoverable) {