private Registry makeRegistry()

in taverna-server-webapp/src/main/java/org/apache/taverna/server/master/localworker/AbstractRemoteRunFactory.java [171:205]


	private Registry makeRegistry(int port) throws RemoteException {
		ProcessBuilder p = new ProcessBuilder(getJavaBinary());
		p.command().add("-jar");
		p.command().add(getRmiRegistryJar());
		p.command().add(Integer.toString(port));
		p.command().add(Boolean.toString(rmiLocalhostOnly));
		try {
			Process proc = launchSubprocess(p);
			Thread.sleep(getSleepTime());
			try {
				if (proc.exitValue() == 0)
					return null;
				String error = IOUtils.toString(proc.getErrorStream());
				throw new RemoteException(error);
			} catch (IllegalThreadStateException ise) {
				// Still running!
			}
			try (ObjectInputStream ois = new ObjectInputStream(
					proc.getInputStream())) {
				@SuppressWarnings("unchecked")
				Registry r = ((MarshalledObject<Registry>) ois.readObject())
						.get();
				registryProcess = proc;
				return r;
			}
		} catch (RemoteException e) {
			throw e;
		} catch (ClassNotFoundException e) {
			throw new RemoteException("unexpected registry type", e);
		} catch (IOException e) {
			throw new RemoteException("unexpected IO problem with registry", e);
		} catch (InterruptedException e) {
			throw new RemoteException("unexpected interrupt");
		}
	}