From 7b452bfddc50ca6aa3bc187fa56ab03304eae27e Mon Sep 17 00:00:00 2001 From: Jess Sightler Date: Tue, 6 Dec 2016 20:30:32 -0500 Subject: [PATCH 1/2] Weird way to do it... needs cleanup --- bootstrap/pom.xml | 4 - .../commands/windup/ServerModeCommand.java | 18 +---- .../windup/tooling/ToolingRMIServer.java | 79 +++++++++++++++++++ 3 files changed, 82 insertions(+), 19 deletions(-) create mode 100644 tooling/api/src/main/java/org/jboss/windup/tooling/ToolingRMIServer.java diff --git a/bootstrap/pom.xml b/bootstrap/pom.xml index f548635ec8..276a55a9cb 100644 --- a/bootstrap/pom.xml +++ b/bootstrap/pom.xml @@ -16,10 +16,6 @@ dom4j 1.6.1 - - org.jboss.windup - windup-tooling-api - org.jboss.windup.config windup-config-api diff --git a/bootstrap/src/main/java/org/jboss/windup/bootstrap/commands/windup/ServerModeCommand.java b/bootstrap/src/main/java/org/jboss/windup/bootstrap/commands/windup/ServerModeCommand.java index f633752dca..065ba71ce6 100644 --- a/bootstrap/src/main/java/org/jboss/windup/bootstrap/commands/windup/ServerModeCommand.java +++ b/bootstrap/src/main/java/org/jboss/windup/bootstrap/commands/windup/ServerModeCommand.java @@ -13,7 +13,6 @@ import org.jboss.windup.bootstrap.commands.CommandPhase; import org.jboss.windup.bootstrap.commands.CommandResult; import org.jboss.windup.bootstrap.commands.addons.AddImmutableAddonDirectoryCommand; -import org.jboss.windup.tooling.ExecutionBuilder; public class ServerModeCommand implements Command { @@ -87,21 +86,10 @@ private int getServerPort() { return Integer.valueOf(serverPortString); } - private void startServer() + private void startServer() { - try - { - System.setProperty("java.rmi.server.hostname","192.168.1.2"); - //System.setProperty("java.security.policy", "all.policy"); - ExecutionBuilder executionBuilder = furnace.getAddonRegistry().getServices(ExecutionBuilder.class).get(); - ExecutionBuilder proxy = (ExecutionBuilder)UnicastRemoteObject.exportObject(executionBuilder, 0); - Registry registry = LocateRegistry.createRegistry(port); - registry.rebind(ExecutionBuilder.LOOKUP_NAME, proxy); - System.out.println("Registered ExecutionBuilder at: " + registry); - } catch (RemoteException e) { - System.out.println("Bootstrap error while registering ExecutionBuilder..."); - e.printStackTrace(); - } + //System.out.println("") + //furnace.getAddonRegistry().getServices(ToolingRMIServer.class); } // TODO: Not sure if this is necessary, or if killing the processes is sufficient. diff --git a/tooling/api/src/main/java/org/jboss/windup/tooling/ToolingRMIServer.java b/tooling/api/src/main/java/org/jboss/windup/tooling/ToolingRMIServer.java new file mode 100644 index 0000000000..ba7f1baa0f --- /dev/null +++ b/tooling/api/src/main/java/org/jboss/windup/tooling/ToolingRMIServer.java @@ -0,0 +1,79 @@ +package org.jboss.windup.tooling; + +import java.rmi.RemoteException; +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; +import java.rmi.server.UnicastRemoteObject; +import java.util.Arrays; + +import javax.enterprise.event.Observes; +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jboss.forge.furnace.Furnace; +import org.jboss.forge.furnace.event.PostStartup; + +/** + * @author Jesse Sightler + */ +@Singleton +public class ToolingRMIServer +{ + @Inject + private Furnace furnace; + + @Inject + private ExecutionBuilder executionBuilder; + + public void startServer(@Observes PostStartup startup) + { + startRmi(); + } + + private void startRmi() + { + synchronized (ToolingRMIServer.class) + { + System.out.println("Registering RMI Server..."); + int port = 9874; + try + { + Registry registry = LocateRegistry.getRegistry(port); + try + { + String[] registered = registry.list(); + if (Arrays.asList(registered).contains(ExecutionBuilder.LOOKUP_NAME)) + registry.unbind(ExecutionBuilder.LOOKUP_NAME); + + try + { + UnicastRemoteObject.unexportObject(executionBuilder, true); + } + catch (Throwable t) + { + System.out.println("Could not unexport due to: " + t.getMessage()); + } + } + catch (Throwable t) + { + t.printStackTrace(); + System.out.println("Registry not already there, starting..."); + registry = LocateRegistry.createRegistry(port); + } + + // System.setProperty("java.rmi.server.hostname","192.168.1.2"); + // System.setProperty("java.security.policy", "all.policy"); + // ExecutionBuilder executionBuilder = furnace.getAddonRegistry().getServices(ExecutionBuilder.class).get(); + + ExecutionBuilder proxy = (ExecutionBuilder) UnicastRemoteObject.exportObject(executionBuilder, 0); + registry.rebind(ExecutionBuilder.LOOKUP_NAME, proxy); + System.out.println("Registered ExecutionBuilder at: " + registry); + } + catch (RemoteException e) + { + System.out.println("Bootstrap error while registering ExecutionBuilder..."); + e.printStackTrace(); + } + } + } +} From 4e352905ca0dedb5f8204a77c7942f3c163a1742 Mon Sep 17 00:00:00 2001 From: Jess Sightler Date: Wed, 7 Dec 2016 12:58:53 -0500 Subject: [PATCH 2/2] Made the startup process better --- bootstrap/pom.xml | 4 ++ .../commands/windup/ServerModeCommand.java | 5 +- .../windup/tooling/ToolingRMIServer.java | 66 ++++++++----------- 3 files changed, 34 insertions(+), 41 deletions(-) diff --git a/bootstrap/pom.xml b/bootstrap/pom.xml index 276a55a9cb..e2a8e55211 100644 --- a/bootstrap/pom.xml +++ b/bootstrap/pom.xml @@ -72,6 +72,10 @@ + + org.jboss.windup + windup-tooling-api + org.jboss.windup.utils windup-utils diff --git a/bootstrap/src/main/java/org/jboss/windup/bootstrap/commands/windup/ServerModeCommand.java b/bootstrap/src/main/java/org/jboss/windup/bootstrap/commands/windup/ServerModeCommand.java index 065ba71ce6..418523a2ca 100644 --- a/bootstrap/src/main/java/org/jboss/windup/bootstrap/commands/windup/ServerModeCommand.java +++ b/bootstrap/src/main/java/org/jboss/windup/bootstrap/commands/windup/ServerModeCommand.java @@ -13,6 +13,7 @@ import org.jboss.windup.bootstrap.commands.CommandPhase; import org.jboss.windup.bootstrap.commands.CommandResult; import org.jboss.windup.bootstrap.commands.addons.AddImmutableAddonDirectoryCommand; +import org.jboss.windup.tooling.ToolingRMIServer; public class ServerModeCommand implements Command { @@ -88,8 +89,8 @@ private int getServerPort() { private void startServer() { - //System.out.println("") - //furnace.getAddonRegistry().getServices(ToolingRMIServer.class); + System.out.println("Calling ToolingRMIServer start..."); + furnace.getAddonRegistry().getServices(ToolingRMIServer.class).get().startServer(port); } // TODO: Not sure if this is necessary, or if killing the processes is sufficient. diff --git a/tooling/api/src/main/java/org/jboss/windup/tooling/ToolingRMIServer.java b/tooling/api/src/main/java/org/jboss/windup/tooling/ToolingRMIServer.java index ba7f1baa0f..1f2f9f9053 100644 --- a/tooling/api/src/main/java/org/jboss/windup/tooling/ToolingRMIServer.java +++ b/tooling/api/src/main/java/org/jboss/windup/tooling/ToolingRMIServer.java @@ -6,17 +6,13 @@ import java.rmi.server.UnicastRemoteObject; import java.util.Arrays; -import javax.enterprise.event.Observes; import javax.inject.Inject; -import javax.inject.Singleton; import org.jboss.forge.furnace.Furnace; -import org.jboss.forge.furnace.event.PostStartup; /** * @author Jesse Sightler */ -@Singleton public class ToolingRMIServer { @Inject @@ -25,55 +21,47 @@ public class ToolingRMIServer @Inject private ExecutionBuilder executionBuilder; - public void startServer(@Observes PostStartup startup) + public void startServer(int port) { - startRmi(); - } - private void startRmi() - { - synchronized (ToolingRMIServer.class) + System.out.println("Registering RMI Server..."); + try { - System.out.println("Registering RMI Server..."); - int port = 9874; + Registry registry = LocateRegistry.getRegistry(port); try { - Registry registry = LocateRegistry.getRegistry(port); + String[] registered = registry.list(); + if (Arrays.asList(registered).contains(ExecutionBuilder.LOOKUP_NAME)) + registry.unbind(ExecutionBuilder.LOOKUP_NAME); + try { - String[] registered = registry.list(); - if (Arrays.asList(registered).contains(ExecutionBuilder.LOOKUP_NAME)) - registry.unbind(ExecutionBuilder.LOOKUP_NAME); - - try - { - UnicastRemoteObject.unexportObject(executionBuilder, true); - } - catch (Throwable t) - { - System.out.println("Could not unexport due to: " + t.getMessage()); - } + UnicastRemoteObject.unexportObject(executionBuilder, true); } catch (Throwable t) { - t.printStackTrace(); - System.out.println("Registry not already there, starting..."); - registry = LocateRegistry.createRegistry(port); + System.out.println("Could not unexport due to: " + t.getMessage()); } - - // System.setProperty("java.rmi.server.hostname","192.168.1.2"); - // System.setProperty("java.security.policy", "all.policy"); - // ExecutionBuilder executionBuilder = furnace.getAddonRegistry().getServices(ExecutionBuilder.class).get(); - - ExecutionBuilder proxy = (ExecutionBuilder) UnicastRemoteObject.exportObject(executionBuilder, 0); - registry.rebind(ExecutionBuilder.LOOKUP_NAME, proxy); - System.out.println("Registered ExecutionBuilder at: " + registry); } - catch (RemoteException e) + catch (Throwable t) { - System.out.println("Bootstrap error while registering ExecutionBuilder..."); - e.printStackTrace(); + t.printStackTrace(); + System.out.println("Registry not already there, starting..."); + registry = LocateRegistry.createRegistry(port); } + + // System.setProperty("java.rmi.server.hostname","192.168.1.2"); + // System.setProperty("java.security.policy", "all.policy"); + // ExecutionBuilder executionBuilder = furnace.getAddonRegistry().getServices(ExecutionBuilder.class).get(); + + ExecutionBuilder proxy = (ExecutionBuilder) UnicastRemoteObject.exportObject(executionBuilder, 0); + registry.rebind(ExecutionBuilder.LOOKUP_NAME, proxy); + System.out.println("Registered ExecutionBuilder at: " + registry); + } + catch (RemoteException e) + { + System.out.println("Bootstrap error while registering ExecutionBuilder..."); + e.printStackTrace(); } } }