You are viewing a plain text version of this content. The canonical link for it is here.
Posted to yoko-commits@incubator.apache.org by br...@apache.org on 2006/09/14 13:01:39 UTC

svn commit: r443336 - /incubator/yoko/trunk/core/src/test/java/org/apache/yoko/processmanager/internal/ProcessAgentImpl.java

Author: bravi
Date: Thu Sep 14 06:01:39 2006
New Revision: 443336

URL: http://svn.apache.org/viewvc?view=rev&rev=443336
Log:
[YOKO-129] - Changed the ProcessAgent to add the shutdown hook before calling init.

Modified:
    incubator/yoko/trunk/core/src/test/java/org/apache/yoko/processmanager/internal/ProcessAgentImpl.java

Modified: incubator/yoko/trunk/core/src/test/java/org/apache/yoko/processmanager/internal/ProcessAgentImpl.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/core/src/test/java/org/apache/yoko/processmanager/internal/ProcessAgentImpl.java?view=diff&rev=443336&r1=443335&r2=443336
==============================================================================
--- incubator/yoko/trunk/core/src/test/java/org/apache/yoko/processmanager/internal/ProcessAgentImpl.java (original)
+++ incubator/yoko/trunk/core/src/test/java/org/apache/yoko/processmanager/internal/ProcessAgentImpl.java Thu Sep 14 06:01:39 2006
@@ -28,29 +28,29 @@
 
 public class ProcessAgentImpl extends UnicastRemoteObject implements ProcessAgent {
 
-	private String name;
-	private ProcessManagerRemoteIF processManager;
-	protected ProcessAgentImpl() throws RemoteException {
-		super();
-	}
-
-	private CountDown shutdownCountDown = new CountDown(1);
-	private boolean agentExited = false;
-	private boolean exitedFromParent = false;
-	private int exitCode = 0;
-	private Thread shutdownHook, mainThread;
-	public String getName() { return name; }
-	private void init(String name, ProcessManagerRemoteIF processManager) {
-		this.name = name;
-		this.processManager = processManager;
-		this.mainThread = Thread.currentThread();
-		try {
-			processManager.agentReady(this);
-		} catch (RemoteException e) {
-			e.printStackTrace();
-			System.exit(1);
-		}
-	}
+    private String name;
+    private ProcessManagerRemoteIF processManager;
+    protected ProcessAgentImpl() throws RemoteException {
+        super();
+    }
+
+    private CountDown shutdownCountDown = new CountDown(1);
+    private boolean agentExited = false;
+    private boolean exitedFromParent = false;
+    private int exitCode = 0;
+    private Thread shutdownHook, mainThread;
+    public String getName() { return name; }
+    private void init(String name, ProcessManagerRemoteIF processManager) {
+        this.name = name;
+        this.processManager = processManager;
+        this.mainThread = Thread.currentThread();
+        try {
+            processManager.agentReady(this);
+        } catch (RemoteException e) {
+            e.printStackTrace();
+            System.exit(1);
+        }
+    }
 
     /** this is the main routine run in test agents */
     public static void main(String[] args) throws Exception {
@@ -63,25 +63,26 @@
 
         final ProcessAgentImpl agent = new ProcessAgentImpl();
 
-        ProcessManagerRemoteIF manager = (ProcessManagerRemoteIF) reg.lookup(processManagerName);
-        agent.init(agentName,manager);
-
         agent.shutdownHook = new Thread(new Runnable() {
-        	public void run() {
-        		agent.shutdownCountDown.release();
-        		try {
-					agent.mainThread.join();
-				} catch (InterruptedException e) {
-					e.printStackTrace();
-				}
-        	}
+                public void run() {
+                    agent.shutdownCountDown.release();
+                    try {
+                        agent.mainThread.join();
+                    } catch (InterruptedException e) {
+                        e.printStackTrace();
+                    }
+                }
         });
         Runtime.getRuntime().addShutdownHook(agent.shutdownHook);
+
+        ProcessManagerRemoteIF manager = (ProcessManagerRemoteIF) reg.lookup(processManagerName);
+        agent.init(agentName,manager);
+
         agent.waitForShutdown();
         agent.notifyManagerOnExit();
         if(agent.exitedFromParent) {
-        	Runtime.getRuntime().removeShutdownHook(agent.shutdownHook);
-        	System.exit(agent.exitCode);
+            Runtime.getRuntime().removeShutdownHook(agent.shutdownHook);
+            System.exit(agent.exitCode);
         }
     }
 
@@ -98,63 +99,63 @@
         agent.init(agentName,manager);
     }
 
-	private void waitForShutdown() {
-		try {
-			while(true) {
-				if(shutdownCountDown.attempt(1000)) {
-					break;
-				}
-				// Throws RemoteException if processManager is gone.
-				processManager.isAlive();
-			}
-		}
-		catch(Exception e) {
-			// Parent process died.
-			Runtime.getRuntime().removeShutdownHook(shutdownHook);
-			System.exit(1);
-		}
-	}
-
-	private void notifyManagerOnExit() {
-		try {
-			if(!agentExited) {
-				processManager.agentExited(this);
-				agentExited = true;
-			}
-		}
-		catch(Exception e) {
-			e.printStackTrace();
-		}
-
-	}
-
-	public void exit(int exitCode) throws RemoteException {
-		this.exitedFromParent = true;
-		this.exitCode = exitCode;
-		shutdownCountDown.release();
-	}
-
-	public Object invokeStatic(String className, String methodName, Object[] args) {
-		try {
-			Class[] parameters = new Class[args.length];
-			for(int i = 0; i < parameters.length; i++) {
-				parameters[i] = args[i].getClass();
-			}
+    private void waitForShutdown() {
+        try {
+            while(true) {
+                if(shutdownCountDown.attempt(1000)) {
+                    break;
+                }
+                // Throws RemoteException if processManager is gone.
+                processManager.isAlive();
+            }
+        }
+        catch(Exception e) {
+            // Parent process died.
+            Runtime.getRuntime().removeShutdownHook(shutdownHook);
+            System.exit(1);
+        }
+    }
+
+    private void notifyManagerOnExit() {
+        try {
+            if(!agentExited) {
+                processManager.agentExited(this);
+                agentExited = true;
+            }
+        }
+        catch(Exception e) {
+            e.printStackTrace();
+        }
+        
+    }
+    
+    public void exit(int exitCode) throws RemoteException {
+        this.exitedFromParent = true;
+        this.exitCode = exitCode;
+        shutdownCountDown.release();
+    }
+
+    public Object invokeStatic(String className, String methodName, Object[] args) {
+        try {
+            Class[] parameters = new Class[args.length];
+            for(int i = 0; i < parameters.length; i++) {
+                parameters[i] = args[i].getClass();
+            }
             // get the appropriate class for the loading.
             ClassLoader loader = Thread.currentThread().getContextClassLoader();
             if (loader == null) {
                 loader = this.getClass().getClassLoader();
             }
 
-			Class cl = loader.loadClass(className);
-			Method method = cl.getMethod(methodName, parameters);
-			return method.invoke(null, args);
-		}
-		catch(InvocationTargetException e) {
-			return e;
-		}
-		catch(Exception e) {
-			throw new Error(e);
-		}
-	}
+            Class cl = loader.loadClass(className);
+            Method method = cl.getMethod(methodName, parameters);
+            return method.invoke(null, args);
+        }
+        catch(InvocationTargetException e) {
+            return e;
+        }
+        catch(Exception e) {
+            throw new Error(e);
+        }
+    }
 }