You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by cw...@apache.org on 2009/09/02 17:22:15 UTC

svn commit: r810557 [7/7] - in /incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae: controller/ delegate/ deploymentDescriptor/

Modified: incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/UimacppServiceController.java
URL: http://svn.apache.org/viewvc/incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/UimacppServiceController.java?rev=810557&r1=810556&r2=810557&view=diff
==============================================================================
--- incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/UimacppServiceController.java (original)
+++ incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/UimacppServiceController.java Wed Sep  2 15:22:13 2009
@@ -48,19 +48,19 @@
 import org.springframework.beans.factory.DisposableBean;
 
 /**
- * This bean functions as a proxy for a Uima C++ service. It starts the Uima C++
- * service given a UIMA descriptor, the input queue name, and environment
- * settings required for the specific annotator and the Uima C++ runtime. On
- * start up a socket connection is established between this instance of the
- * proxy and the service. This connection is used for routing log message from
- * the C++ service to the UIMA framework logger and to allow the proxy to send
- * JMX and administrative requests such as shutdown.
+ * This bean functions as a proxy for a Uima C++ service. It starts the Uima C++ service given a
+ * UIMA descriptor, the input queue name, and environment settings required for the specific
+ * annotator and the Uima C++ runtime. On start up a socket connection is established between this
+ * instance of the proxy and the service. This connection is used for routing log message from the
+ * C++ service to the UIMA framework logger and to allow the proxy to send JMX and administrative
+ * requests such as shutdown.
  * 
  */
-public class UimacppServiceController extends AnalysisEngineControllerAdapter
-implements ControllerLifecycle, DisposableBean {
+public class UimacppServiceController extends AnalysisEngineControllerAdapter implements
+        ControllerLifecycle, DisposableBean {
 
   private static final String STARTING_DIRECTORY = "UIMACPP_STARTING_DIRECTORY";
+
   protected ServerSocket server;
 
   private int port;
@@ -78,7 +78,7 @@
   private StderrHandler stderrHandler;
 
   private ProcessBuilder builder;
-  
+
   private String startingDirectory;
 
   private String aeDesc;
@@ -96,48 +96,44 @@
   private org.apache.uima.util.Logger uimaLogger;
 
   private UimacppServiceManagement mbean;
-  
+
   private JmxManagement jmxMgmt;
 
   private UimacppShutdownHook shutdownHook;
 
   private int initialFsHeapSize;
-  
+
   private ArrayList<ControllerCallbackListener> listeners = new ArrayList<ControllerCallbackListener>();
-  
+
   private Boolean InitializedState = false;
-  
+
   private Exception InitializedStatus = null;
-  
-  
-    /**
-   * Configure and start a Uima C++ service that connects to an ActiveMQ
-   * queue broker. 
-   * This class  initializes the process environment and starts a process 
-   * to deploy the C++ service.
-   * Communication via sockets is established between this Controller and the
-   * C++ service through which logging, JMX and administrative messages are
-   * transmitted.
+
+  /**
+   * Configure and start a Uima C++ service that connects to an ActiveMQ queue broker. This class
+   * initializes the process environment and starts a process to deploy the C++ service.
+   * Communication via sockets is established between this Controller and the C++ service through
+   * which logging, JMX and administrative messages are transmitted.
    * 
-   * @param aeDescriptorFileName -
-   *          UIMA analysis engine descriptor file.
-   * @param queueName -
-   *          input queue name
-   * @param brokerURL -
-   *          queue broker URL
-   * @param numInstances -
-   *          number of instance of AEs to start in the service.
-   * @param prefetchSize -
-   *          number of message to prefetch
-   * @param envVarMap -
-   *          enviroment variables to be set. These settings are valid only for
-   *          the new process in which C++ service will run.
+   * @param aeDescriptorFileName
+   *          - UIMA analysis engine descriptor file.
+   * @param queueName
+   *          - input queue name
+   * @param brokerURL
+   *          - queue broker URL
+   * @param numInstances
+   *          - number of instance of AEs to start in the service.
+   * @param prefetchSize
+   *          - number of message to prefetch
+   * @param envVarMap
+   *          - enviroment variables to be set. These settings are valid only for the new process in
+   *          which C++ service will run.
    * @throws UIMAException
    */
-  public UimacppServiceController(String aeDescriptorFileName,
-      String queueName, String brokerURL, int numInstances, int prefetchSize,
-      Map<String,String> envVarMap, int processCasErrorThreshhold, int processCasErrorWindow,
-      boolean terminateOnCPCError, int initialFsHeapSize) throws ResourceInitializationException {
+  public UimacppServiceController(String aeDescriptorFileName, String queueName, String brokerURL,
+          int numInstances, int prefetchSize, Map<String, String> envVarMap,
+          int processCasErrorThreshhold, int processCasErrorWindow, boolean terminateOnCPCError,
+          int initialFsHeapSize) throws ResourceInitializationException {
 
     try {
       this.uimaLogger = UIMAFramework.getLogger(this.getClass());
@@ -149,7 +145,7 @@
       this.terminateOnCPCError = terminateOnCPCError;
       this.initialFsHeapSize = initialFsHeapSize;
       this.startingDirectory = envVarMap.get(STARTING_DIRECTORY);
-      
+
       /* start a listener */
       server = new ServerSocket(0);
       port = server.getLocalPort();
@@ -165,35 +161,35 @@
         commandArgs.add("-b");
         commandArgs.add(brokerURL);
       }
-      
+
       commandArgs.add("-p");
       commandArgs.add(Integer.toString(prefetchSize));
-      
+
       /* construct the process builder */
       builder = new ProcessBuilder(commandArgs);
       setEnvironmentVariables(envVarMap);
 
       /* setup environment variables */
 
-      //System.out.println("Uima C++ Service " + aeDesc + " configured.");
-      //System.out.println("Listener started at port " + port + ".");
+      // System.out.println("Uima C++ Service " + aeDesc + " configured.");
+      // System.out.println("Listener started at port " + port + ".");
       // System.out.println(builder.command().toString());
       /* start the C++ service */
-      //try {
-        // start threads to accept two connections from the service
+      // try {
+      // start threads to accept two connections from the service
 
-        /* start the service */
+      /* start the service */
       this.uimaLogger.log(Level.INFO, "Starting C++ service: " + commandArgs.toString());
       this.uimaLogger.log(Level.INFO, " env params: " + envVarMap.toString());
       startService();
 
-        /** register with JMX - for now register with the platform MBean server */
-        mbean = new UimacppServiceManagement("org.apache.uima:type=ee.jms.services,",commandConnection, aeDesc,
-            numInstances, brokerURL, queueName);
-        JmxMBeanAgent.registerMBean(mbean, null);
+      /** register with JMX - for now register with the platform MBean server */
+      mbean = new UimacppServiceManagement("org.apache.uima:type=ee.jms.services,",
+              commandConnection, aeDesc, numInstances, brokerURL, queueName);
+      JmxMBeanAgent.registerMBean(mbean, null);
 
-        // Initialization looks good
-        notifyInitializationStatus(null);
+      // Initialization looks good
+      notifyInitializationStatus(null);
 
     } catch (IOException e) {
       notifyInitializationStatus(e);
@@ -203,18 +199,17 @@
       throw new ResourceInitializationException(e);
     }
   }
-  
+
   private void notifyInitializationStatus(Exception e) {
     synchronized (this) {
       if (!this.InitializedState) {
         this.InitializedStatus = e;
         this.InitializedState = true;
       }
-  
-      for( int i=0; i < this.listeners.size(); i++ )
-      {
-        //  If there is an exception, notify listener with failure
-        if ( e != null ) {
+
+      for (int i = 0; i < this.listeners.size(); i++) {
+        // If there is an exception, notify listener with failure
+        if (e != null) {
           (this.listeners.get(i)).notifyOnInitializationFailure(e);
         }
         // else, Success!
@@ -224,27 +219,23 @@
       }
     }
   }
-  
-  public UimacppServiceController(String aeDescriptorFileName,
-      String queueName, String brokerURL, int numInstances, int prefetchSize,
-      Map<String,String> envVarMap, int processCasErrorThreshhold, int processCasErrorWindow,
-      boolean terminateOnCPCError) throws ResourceInitializationException {
-  
-     this(aeDescriptorFileName,
-        queueName, brokerURL, numInstances, prefetchSize,
-        envVarMap, processCasErrorThreshhold, processCasErrorWindow,
-        terminateOnCPCError,0); 
-    
+
+  public UimacppServiceController(String aeDescriptorFileName, String queueName, String brokerURL,
+          int numInstances, int prefetchSize, Map<String, String> envVarMap,
+          int processCasErrorThreshhold, int processCasErrorWindow, boolean terminateOnCPCError)
+          throws ResourceInitializationException {
+
+    this(aeDescriptorFileName, queueName, brokerURL, numInstances, prefetchSize, envVarMap,
+            processCasErrorThreshhold, processCasErrorWindow, terminateOnCPCError, 0);
+
   }
 
   /**
-   * Configure and start a Uima C++ service that connects to an WebSphereMQ
-   * queue broker. 
-   * This class  initializes the process environment and starts a process 
-   * to deploy the C++ service.
-   * Communication via sockets is established between this Controller and the
-   * C++ service through which logging, JMX and administrative messages are
-   * transmitted.
+   * Configure and start a Uima C++ service that connects to an WebSphereMQ queue broker. This class
+   * initializes the process environment and starts a process to deploy the C++ service.
+   * Communication via sockets is established between this Controller and the C++ service through
+   * which logging, JMX and administrative messages are transmitted.
+   * 
    * @param uimaLogger
    * @param aeDescriptorFileName
    * @param mqQueueName
@@ -261,12 +252,11 @@
    * @throws ResourceInitializationException
    */
   public UimacppServiceController(org.apache.uima.util.Logger uimaLogger,
-      String aeDescriptorFileName, String queueName, String mqHostName,
-      int mqPort, String mqChannel, String mqQueueMgr, int numInstances,
-      Map<String,String> envVarMap, int processCasErrorThreshhold, int processCasErrorWindow,
-      boolean terminateOnCPCError, JmxManagement jmxManagement,
-      int initialFsHeapSize)
-      throws ResourceInitializationException {
+          String aeDescriptorFileName, String queueName, String mqHostName, int mqPort,
+          String mqChannel, String mqQueueMgr, int numInstances, Map<String, String> envVarMap,
+          int processCasErrorThreshhold, int processCasErrorWindow, boolean terminateOnCPCError,
+          JmxManagement jmxManagement, int initialFsHeapSize)
+          throws ResourceInitializationException {
 
     try {
       this.uimaLogger = UIMAFramework.getLogger(this.getClass());
@@ -290,7 +280,7 @@
       ArrayList<String> commandArgs = new ArrayList<String>();
       buildCommandArgs(commandArgs, envVarMap, "deployWMQCppService");
 
-      //add MQ specific args
+      // add MQ specific args
       if (mqHostName != null && mqHostName.length() > 0) {
         commandArgs.add("-mqh");
         commandArgs.add(mqHostName);
@@ -313,48 +303,45 @@
       builder = new ProcessBuilder(commandArgs);
       setEnvironmentVariables(envVarMap);
 
-      //System.out.println("Uima C++ Service " + aeDesc + " configured.");
-      //System.out.println("Listener started at port " + port + ".");
+      // System.out.println("Uima C++ Service " + aeDesc + " configured.");
+      // System.out.println("Listener started at port " + port + ".");
       // System.out.println(builder.command().toString());
 
       /* start the service */
       this.uimaLogger.log(Level.INFO, "Starting C++ service: " + commandArgs.toString());
       this.uimaLogger.log(Level.INFO, " env params: " + envVarMap.toString());
-      startService();  
-      
-      mbean = new UimacppServiceManagement(null, commandConnection, aeDesc,
-          numInstances, mqHostName + " " + mqPort + "//" + mqQueueMgr,
-          "queue://" +/* mqChannel +*/ "/" + queueName);
-      
-      /** register with JMX  */
-     
-      if (jmxManagement == null ) {
-        throw new ResourceInitializationException( new IOException("JmxManagement object is null."));
+      startService();
+
+      mbean = new UimacppServiceManagement(null, commandConnection, aeDesc, numInstances,
+              mqHostName + " " + mqPort + "//" + mqQueueMgr, "queue://" + /* mqChannel + */"/"
+                      + queueName);
+
+      /** register with JMX */
+
+      if (jmxManagement == null) {
+        throw new ResourceInitializationException(new IOException("JmxManagement object is null."));
       }
-      
+
       mbean = new UimacppServiceManagement(jmxManagement.getJmxDomain(), commandConnection, aeDesc,
-            numInstances, mqHostName + " " + mqPort + "//" + mqQueueMgr,
-            queueName);
-      ObjectName oname = new ObjectName(mbean.getUniqueMBeanName()); 
-      jmxManagement.registerMBean(mbean, oname); 
+              numInstances, mqHostName + " " + mqPort + "//" + mqQueueMgr, queueName);
+      ObjectName oname = new ObjectName(mbean.getUniqueMBeanName());
+      jmxManagement.registerMBean(mbean, oname);
 
     } catch (IOException e) {
       throw new ResourceInitializationException(e);
     } catch (UIMAException e) {
       throw new ResourceInitializationException(e);
     } catch (MalformedObjectNameException e) {
-     throw new ResourceInitializationException(e);
+      throw new ResourceInitializationException(e);
     } catch (NullPointerException e) {
       throw new ResourceInitializationException(e);
     } catch (Exception e) {
       throw new ResourceInitializationException(e);
-    } 
+    }
   }
 
-  private void buildCommandArgs(ArrayList<String> commandArgs, 
-      Map<String,String> envVarMap,
-      String exeName)
-      throws ResourceInitializationException {
+  private void buildCommandArgs(ArrayList<String> commandArgs, Map<String, String> envVarMap,
+          String exeName) throws ResourceInitializationException {
 
     String uimacppHome = (String) envVarMap.get("UIMACPP_HOME");
     if (uimacppHome == null) {
@@ -365,13 +352,13 @@
     }
 
     if (!(new File(uimacppHome)).exists()) {
-      throw new ResourceInitializationException(new IOException(
-          "Invalid location of UIMACPP_HOME " + uimacppHome));
+      throw new ResourceInitializationException(new IOException("Invalid location of UIMACPP_HOME "
+              + uimacppHome));
     }
 
     // the Uima C++ service wrapper exe
     String cmd = uimacppHome + System.getProperty("file.separator") + "bin"
-        + System.getProperty("file.separator") + exeName; 
+            + System.getProperty("file.separator") + exeName;
 
     commandArgs.add(cmd);
 
@@ -412,11 +399,9 @@
     // logging level setting obtained from the UIMA framework
     // translated to UIMA C++ logging levels.
     commandArgs.add("-l");
-    if (uimaLogger.isLoggable(Level.FINE)
-        || uimaLogger.isLoggable(Level.CONFIG)
-        || uimaLogger.isLoggable(Level.FINER)
-        || uimaLogger.isLoggable(Level.FINEST)
-        || uimaLogger.isLoggable(Level.INFO)) {
+    if (uimaLogger.isLoggable(Level.FINE) || uimaLogger.isLoggable(Level.CONFIG)
+            || uimaLogger.isLoggable(Level.FINER) || uimaLogger.isLoggable(Level.FINEST)
+            || uimaLogger.isLoggable(Level.INFO)) {
       commandArgs.add(Integer.toString(0));
     } else if (uimaLogger.isLoggable(Level.WARNING)) {
       commandArgs.add(Integer.toString(1));
@@ -428,20 +413,19 @@
 
     // translate logger level to trace level 0-4.
     // set based Level = CONFIG, INFO, FINE, FINER, FINEST...
-    commandArgs.add("-t"); 
+    commandArgs.add("-t");
     if (uimaLogger.isLoggable(Level.FINEST)) {
       commandArgs.add(Integer.toString(3));
     } else if (uimaLogger.isLoggable(Level.FINER)) {
       commandArgs.add(Integer.toString(2));
     } else if (uimaLogger.isLoggable(Level.FINE)) {
       commandArgs.add(Integer.toString(1));
-    } else if (uimaLogger.isLoggable(Level.CONFIG) || 
-    		uimaLogger.isLoggable(Level.INFO)) {
+    } else if (uimaLogger.isLoggable(Level.CONFIG) || uimaLogger.isLoggable(Level.INFO)) {
       commandArgs.add(Integer.toString(0));
     } else {
       commandArgs.add(Integer.toString(-1));
     }
-    //   data directory used to resolve location of
+    // data directory used to resolve location of
     // files used by annotator.
     String uimacppDataPath = (String) envVarMap.get("UIMACPP_DATAPATH");
     if (uimacppDataPath != null && uimacppDataPath.length() != 0) {
@@ -462,75 +446,68 @@
       commandArgs.add("-a");
       commandArgs.add("true");
     }
-    
+
     if (initialFsHeapSize > 0) {
       commandArgs.add("-fsheapsz");
       commandArgs.add(Integer.toString(initialFsHeapSize));
     }
 
   }
-  
+
   public UimacppServiceController(org.apache.uima.util.Logger uimaLogger,
-      String aeDescriptorFileName, String queueName, String mqHostName,
-      int mqPort, String mqChannel, String mqQueueMgr, int numInstances,
-      Map<String,String> envVarMap, int processCasErrorThreshhold, int processCasErrorWindow,
-      boolean terminateOnCPCError, JmxManagement jmxManagement) throws ResourceInitializationException  {
-    
-     this(uimaLogger,
-        aeDescriptorFileName, queueName, mqHostName,
-        mqPort, mqChannel, mqQueueMgr, numInstances,
-        envVarMap, processCasErrorThreshhold, processCasErrorWindow,
-        terminateOnCPCError,  jmxManagement,0);
-    
+          String aeDescriptorFileName, String queueName, String mqHostName, int mqPort,
+          String mqChannel, String mqQueueMgr, int numInstances, Map<String, String> envVarMap,
+          int processCasErrorThreshhold, int processCasErrorWindow, boolean terminateOnCPCError,
+          JmxManagement jmxManagement) throws ResourceInitializationException {
+
+    this(uimaLogger, aeDescriptorFileName, queueName, mqHostName, mqPort, mqChannel, mqQueueMgr,
+            numInstances, envVarMap, processCasErrorThreshhold, processCasErrorWindow,
+            terminateOnCPCError, jmxManagement, 0);
+
   }
 
-  private void setEnvironmentVariables(Map<String,String> envVarMap) {
+  private void setEnvironmentVariables(Map<String, String> envVarMap) {
     /* setup environment variables */
     String uimacppHome = (String) envVarMap.get("UIMACPP_HOME");
-    String uimacppLibDir = uimacppHome + System.getProperty("file.separator")
-        + "lib" 
-        + System.getProperty("path.separator")
-        + uimacppHome + System.getProperty("file.separator")
-        + "lib" + System.getProperty("file.separator") +
-        "xms";
+    String uimacppLibDir = uimacppHome + System.getProperty("file.separator") + "lib"
+            + System.getProperty("path.separator") + uimacppHome
+            + System.getProperty("file.separator") + "lib" + System.getProperty("file.separator")
+            + "xms";
 
     Map<String, String> environment = builder.environment();
-    
-    //add uimacpp lib dir to the path
+
+    // add uimacpp lib dir to the path
     String value = environment.get("PATH");
     if (value != null && value.length() > 0) {
-    value = uimacppLibDir + System.getProperty("path.separator")+
-            value;
+      value = uimacppLibDir + System.getProperty("path.separator") + value;
     } else {
       value = uimacppLibDir;
     }
     environment.put("PATH", value);
-   
+
     value = environment.get("LD_LIBRARY_PATH");
     if (value != null && value.length() > 0) {
-      value = uimacppLibDir + System.getProperty("path.separator")+
-              value;
+      value = uimacppLibDir + System.getProperty("path.separator") + value;
     } else {
-        value = uimacppLibDir;
+      value = uimacppLibDir;
     }
     environment.put("LD_LIBRARY_PATH", value);
-    
+
     value = environment.get("DYLD_LIBRARY_PATH");
 
     value = environment.get("LD_LIBRARY_PATH");
     if (value != null && value.length() > 0) {
-      value = uimacppLibDir + System.getProperty("path.separator")+
-              value;
+      value = uimacppLibDir + System.getProperty("path.separator") + value;
     } else {
-        value = uimacppLibDir;
+      value = uimacppLibDir;
     }
     environment.put("DYLD_LIBRARY_PATH", value);
 
-    //set user specified environment variables
+    // set user specified environment variables
     Set set = envVarMap.entrySet();
-    
-    for( Iterator it = set.iterator(); it.hasNext(); ) {
-      Map.Entry entry = (Map.Entry)it.next();
+
+    for (Iterator it = set.iterator(); it.hasNext();) {
+      Map.Entry entry = (Map.Entry) it.next();
       String key = (String) entry.getKey();
       value = (String) entry.getValue();
 
@@ -539,14 +516,12 @@
         // and DYLD_LIBRARY_PATH
         // for these we prepend the values to the
         // existing values.
-        if (key.equalsIgnoreCase("PATH")
-            || key.equalsIgnoreCase("LD_LIBRARY_PATH")
-            || key.equalsIgnoreCase("DYLD_LIBRARY_PATH")) {
+        if (key.equalsIgnoreCase("PATH") || key.equalsIgnoreCase("LD_LIBRARY_PATH")
+                || key.equalsIgnoreCase("DYLD_LIBRARY_PATH")) {
           String origValue = environment.get(key);
           if (origValue != null) {
-            value = value + System.getProperty("path.separator")
-                + uimacppLibDir + System.getProperty("path.separator")
-                + origValue;
+            value = value + System.getProperty("path.separator") + uimacppLibDir
+                    + System.getProperty("path.separator") + origValue;
           }
 
         }
@@ -567,17 +542,17 @@
       ConnectionHandler handler2 = new ConnectionHandler(this);
       Thread t2 = new Thread(handler2);
       t2.start();
-    
-      //setup starting directory if specified.
+
+      // setup starting directory if specified.
       if (this.startingDirectory != null && this.startingDirectory.length() > 0) {
         File startingDir = new File(this.startingDirectory);
         if (!startingDir.exists()) {
-        	throw new ResourceInitializationException(new IOException(
-            this.startingDirectory + " Uimacpp Starting Directory not found. + ")); 	
+          throw new ResourceInitializationException(new IOException(this.startingDirectory
+                  + " Uimacpp Starting Directory not found. + "));
         }
         builder.directory(startingDir);
       }
-      
+
       uimacppProcess = builder.start();
       if (uimacppProcess == null) {
         throw new UIMAException(new Throwable("Could not fork process."));
@@ -594,51 +569,47 @@
       // wait for connection handler threads to complete
       t1.join();
       t2.join();
-      synchronized(this)
-      {
-          if (this.loggerConnection == null || 
-                  this.loggerHandler == null || 
-                  this.commandConnection == null) {
-                throw new ResourceInitializationException(new IOException(
-                "Could not establish socket connection with C++ service."));
-              }
+      synchronized (this) {
+        if (this.loggerConnection == null || this.loggerHandler == null
+                || this.commandConnection == null) {
+          throw new ResourceInitializationException(new IOException(
+                  "Could not establish socket connection with C++ service."));
+        }
       }
-     
+
       /* add the shutdown hook */
-      shutdownHook = new UimacppShutdownHook(uimacppProcess, commandConnection,
-          uimaLogger);
+      shutdownHook = new UimacppShutdownHook(uimacppProcess, commandConnection, uimaLogger);
       Runtime.getRuntime().addShutdownHook(shutdownHook);
-      
+
       if (uimacppProcess != null) {
-        //wait for C++ process to report initialization status.	  
-    	System.out.println("Waiting for Uima C++ service to report init status...");
-    	BufferedReader in = new BufferedReader(new InputStreamReader(commandConnection
-    	          .getInputStream()));
-
-    	StringBuffer sb = new StringBuffer();
-    	int c = in.read();
-    	while (c >= 0) {
-    	   sb.append((char) c);
-    	   c = in.read();
-    	   if (c == '\n') {
-    	          break;
-    	   }
-    	}  
-    	if (sb.toString().equalsIgnoreCase("0")) {
-    		System.out.println("Uima C++ service at " + queueName
-    				+ " Ready to process...");
-    		WaitThread wt = new WaitThread(uimacppProcess, uimaLogger,listeners);
-    		Thread wThread = new Thread(wt);
-    		wThread.start();
-    	} else {
-    		System.out.println("UIMA C++ service at " + queueName + " failed to initialize.");
-    		System.out.println(sb.toString());
-    		uimacppProcess.destroy();
-    		throw new IOException(sb.toString());
-    	}
+        // wait for C++ process to report initialization status.
+        System.out.println("Waiting for Uima C++ service to report init status...");
+        BufferedReader in = new BufferedReader(new InputStreamReader(commandConnection
+                .getInputStream()));
+
+        StringBuffer sb = new StringBuffer();
+        int c = in.read();
+        while (c >= 0) {
+          sb.append((char) c);
+          c = in.read();
+          if (c == '\n') {
+            break;
+          }
+        }
+        if (sb.toString().equalsIgnoreCase("0")) {
+          System.out.println("Uima C++ service at " + queueName + " Ready to process...");
+          WaitThread wt = new WaitThread(uimacppProcess, uimaLogger, listeners);
+          Thread wThread = new Thread(wt);
+          wThread.start();
+        } else {
+          System.out.println("UIMA C++ service at " + queueName + " failed to initialize.");
+          System.out.println(sb.toString());
+          uimacppProcess.destroy();
+          throw new IOException(sb.toString());
+        }
       } else {
         throw new ResourceInitializationException(new IOException(
-            "Could not start the C++ service."));
+                "Could not start the C++ service."));
       }
     } catch (IOException e) {
       throw new ResourceInitializationException(e);
@@ -651,8 +622,8 @@
   /**
    * Shuts down the UIMA C++ service process.
    * 
-   * @param force -
-   *          force or allow service to shutdown gracefully.
+   * @param force
+   *          - force or allow service to shutdown gracefully.
    * @throws IOException
    * @throws InterruptedException
    */
@@ -660,13 +631,13 @@
     mbean.shutdown();
     if (jmxMgmt != null) {
       try {
-		    this.jmxMgmt.destroy();		    
-	    } catch (Exception e) {
-		    throw new IOException(e.getMessage());
-	    }
+        this.jmxMgmt.destroy();
+      } catch (Exception e) {
+        throw new IOException(e.getMessage());
+      }
     }
     if (listeners != null) {
-      for (int i=0;i < listeners.size(); i++) {
+      for (int i = 0; i < listeners.size(); i++) {
         ControllerCallbackListener listener = (ControllerCallbackListener) listeners.get(i);
         if (listener != null) {
           listener.notifyOnTermination("Uima C++ service shutdown.");
@@ -674,14 +645,12 @@
       }
       listeners.clear();
     }
-    synchronized(this)
-    {
-        loggerConnection.close();
+    synchronized (this) {
+      loggerConnection.close();
     }
     commandConnection.close();
     server.close();
-  } 
-  
+  }
 
   public String getStatistics() throws IOException {
     return mbean.getStatisticsAsString();
@@ -704,7 +673,6 @@
     }
   }
 
- 
   /**
    * test
    * 
@@ -712,70 +680,49 @@
    */
   public static void main(String[] args) {
     HashMap<String, String> envVarMap = new HashMap<String, String>();
-    
+
     try {
-    	if (System.getProperty("os.name").startsWith("Windows")) {
+      if (System.getProperty("os.name").startsWith("Windows")) {
         envVarMap.put("UIMACPP_HOME", "c:\\uimacpp2.0\\uimacpp");
         envVarMap.put("UIMACPP_LOGFILE", "c:\\temp\\uimacppcontroller.log");
         envVarMap.put("Path", "c:\\cppExamples2.0\\src");
-      
+
         UimacppServiceController controller = new UimacppServiceController(
-          "c:/cppExamples2.0/descriptors/DaveDetector.xml", // AE descriptor
-          "davedetector", // input queue
-          "tcp://localhost:61616", // activemq broker url
-          1, // num instances
-          0, // prefetch,
-          envVarMap, 
-          0, // processCAS error threshhold
-          0, // processCAS error window
-          false,2000000);
-    	} else {
-    	    envVarMap.put("UIMACPP_HOME", "/opt/IBM/uimacpp");    
-    	    //envVarMap.put("Path", "/opt/IBM/uimacpp/bin");
-    	    envVarMap.put("UIMACPP_LOGFILE", "/tmp/bhavani.log");
-    	    //envVarMap.put("LD_LIBRARY_PATH", "/opt/IBM/uimacpp/lib:/opt/IBM/uimacpp/lib/xms");
-    	    UimacppServiceController controller = 
-    	              new UimacppServiceController(UIMAFramework.getLogger(),
-                    "/home/bsiyer/cppExamples/descriptors/DaveDetector.xml",
-                    "ORANGE.QUEUE", "sith07.watson.ibm.com", 1414,
-                    null, null, 1, envVarMap, 0, 0, false, null,0);      
-    	}
-    	
+                "c:/cppExamples2.0/descriptors/DaveDetector.xml", // AE descriptor
+                "davedetector", // input queue
+                "tcp://localhost:61616", // activemq broker url
+                1, // num instances
+                0, // prefetch,
+                envVarMap, 0, // processCAS error threshhold
+                0, // processCAS error window
+                false, 2000000);
+      } else {
+        envVarMap.put("UIMACPP_HOME", "/opt/IBM/uimacpp");
+        // envVarMap.put("Path", "/opt/IBM/uimacpp/bin");
+        envVarMap.put("UIMACPP_LOGFILE", "/tmp/bhavani.log");
+        // envVarMap.put("LD_LIBRARY_PATH", "/opt/IBM/uimacpp/lib:/opt/IBM/uimacpp/lib/xms");
+        UimacppServiceController controller = new UimacppServiceController(UIMAFramework
+                .getLogger(), "/home/bsiyer/cppExamples/descriptors/DaveDetector.xml",
+                "ORANGE.QUEUE", "sith07.watson.ibm.com", 1414, null, null, 1, envVarMap, 0, 0,
+                false, null, 0);
+      }
+
       /**
-      try {
-        Thread.sleep(2000);
-      } catch (InterruptedException e) {
-        // TODO Auto-generated catch block
-        e.printStackTrace();
-      }
-      
-      System.out.println("MAIN getStats");
-      for (int i = 0; i < 3; i++) {
-	      String stats = controller.getStatistics();
-	      if (stats == null)
-	        System.out.println("NULL stats");
-	      else
-	        System.out.println(i + " " + stats);
-	    }
-	
-	    System.out.println("MAIN RESET STATS");
-	    controller.resetStatistics();
-	    String stats = controller.getStatistics();
-	    if (stats == null)
-	      System.out.println("NULL stats");
-	    else
-	      System.out.println("AFTER RESET " + stats);
-	
-	    try { 
-	       controller.shutdown(); 
-	    } catch (InterruptedException e1) 
-	    { 
-	       e1.printStackTrace();
-	    } catch (IOException e) { // TODO Auto-generated catch block
-	       e.printStackTrace(); 
-	    }
-	 **/
-    	
+       * try { Thread.sleep(2000); } catch (InterruptedException e) { // TODO Auto-generated catch
+       * block e.printStackTrace(); }
+       * 
+       * System.out.println("MAIN getStats"); for (int i = 0; i < 3; i++) { String stats =
+       * controller.getStatistics(); if (stats == null) System.out.println("NULL stats"); else
+       * System.out.println(i + " " + stats); }
+       * 
+       * System.out.println("MAIN RESET STATS"); controller.resetStatistics(); String stats =
+       * controller.getStatistics(); if (stats == null) System.out.println("NULL stats"); else
+       * System.out.println("AFTER RESET " + stats);
+       * 
+       * try { controller.shutdown(); } catch (InterruptedException e1) { e1.printStackTrace(); }
+       * catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }
+       **/
+
     } catch (ResourceInitializationException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
@@ -787,7 +734,7 @@
    * 
    * Runs when UIMA EE client API undeploys this service.
    * 
-   */ 
+   */
   public void terminate() {
     try {
       shutdown();
@@ -802,7 +749,7 @@
    * 
    * Runs when spring undeploys this bean.
    * 
-   */ 
+   */
   public void destroy() {
     try {
       shutdown();
@@ -820,16 +767,14 @@
       if (this.InitializedState) {
         if (this.InitializedStatus == null) {
           aListener.notifyOnInitializationSuccess();
-        }
-        else {
+        } else {
           aListener.notifyOnInitializationFailure(this.InitializedStatus);
         }
       }
     }
-  } 
-  
-  public void removeControllerCallbackListener(ControllerCallbackListener aListener)
-  {
+  }
+
+  public void removeControllerCallbackListener(ControllerCallbackListener aListener) {
     this.listeners.remove(aListener);
   }
 
@@ -840,9 +785,8 @@
 }
 
 /**
- * Handles C++ service logging requests.
- *  It receives messages sent through the logger socket 
- *  connection and writes it to the UIMA logger.
+ * Handles C++ service logging requests. It receives messages sent through the logger socket
+ * connection and writes it to the UIMA logger.
  * 
  * 
  */
@@ -853,8 +797,7 @@
 
   org.apache.uima.util.Logger logger;
 
-  public LoggerHandler(Socket sock, org.apache.uima.util.Logger uimaLogger)
-      throws IOException {
+  public LoggerHandler(Socket sock, org.apache.uima.util.Logger uimaLogger) throws IOException {
 
     socket = sock;
     in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
@@ -862,10 +805,10 @@
   }
 
   public void logMessage(String logMessage) {
-    // determine the logging level of the message  
+    // determine the logging level of the message
     // translate uimacpp log level to java logger level
     Level level = Level.INFO; // default
-    
+
     if (logMessage.startsWith("0")) {
       level = Level.INFO;
     } else if (logMessage.startsWith("1")) {
@@ -873,11 +816,11 @@
     } else if (logMessage.startsWith("2")) {
       level = Level.SEVERE;
     }
-  
+
     logMessage = logMessage.trim();
     // log the message
     logger.log(level, logMessage);
-    //System.out.println(logMessage);
+    // System.out.println(logMessage);
   }
 
   public void run() {
@@ -894,7 +837,7 @@
         c = in.read();
       }
     } catch (IOException e) {
-      logger.log(Level.WARNING,e.getMessage());
+      logger.log(Level.WARNING, e.getMessage());
     }
   }
 } // log handler
@@ -937,8 +880,7 @@
 
   org.apache.uima.util.Logger logger;
 
-  public StdoutHandler(Process aprocess, org.apache.uima.util.Logger uimaLogger)
-      throws IOException {
+  public StdoutHandler(Process aprocess, org.apache.uima.util.Logger uimaLogger) throws IOException {
 
     in = new BufferedReader(new InputStreamReader(aprocess.getInputStream()));
     logger = uimaLogger;
@@ -975,8 +917,7 @@
 
   org.apache.uima.util.Logger logger;
 
-  public StderrHandler(Process aprocess, org.apache.uima.util.Logger uimaLogger)
-      throws IOException {
+  public StderrHandler(Process aprocess, org.apache.uima.util.Logger uimaLogger) throws IOException {
 
     in = new BufferedReader(new InputStreamReader(aprocess.getErrorStream()));
     logger = uimaLogger;
@@ -1011,12 +952,11 @@
   public Process uimacppProcess;
 
   private org.apache.uima.util.Logger uimaLogger;
+
   private List<ControllerCallbackListener> listeners;
 
-  public WaitThread(Process aprocess, 
-      org.apache.uima.util.Logger logger,
-      List<ControllerCallbackListener> llist)
-      throws IOException {
+  public WaitThread(Process aprocess, org.apache.uima.util.Logger logger,
+          List<ControllerCallbackListener> llist) throws IOException {
     this.uimacppProcess = aprocess;
     this.uimaLogger = logger;
     this.listeners = llist;
@@ -1029,7 +969,7 @@
       rc = uimacppProcess.waitFor();
       message += "rc=" + rc;
       if (listeners != null) {
-        for (int i=0;i < listeners.size(); i++) {
+        for (int i = 0; i < listeners.size(); i++) {
           ControllerCallbackListener listener = (ControllerCallbackListener) listeners.get(i);
           if (listener != null) {
             listener.notifyOnTermination(message);
@@ -1039,19 +979,17 @@
       }
     } catch (InterruptedException e) {
       this.uimaLogger.log(Level.INFO, e.getMessage());
-       message += e.getMessage();
-       if (listeners != null) {
-         for (int i=0;i < listeners.size(); i++) {
-           ControllerCallbackListener listener = (ControllerCallbackListener) listeners.get(i);
-           if (listener != null) {
-             listener.notifyOnTermination(message);
-           }
-         }
-         listeners.clear(); 
-       }
+      message += e.getMessage();
+      if (listeners != null) {
+        for (int i = 0; i < listeners.size(); i++) {
+          ControllerCallbackListener listener = (ControllerCallbackListener) listeners.get(i);
+          if (listener != null) {
+            listener.notifyOnTermination(message);
+          }
+        }
+        listeners.clear();
+      }
     }
-    
-    
 
   }
 } // WaitThread
@@ -1065,11 +1003,10 @@
 
   public Process uimacppProcess;
 
-
   private org.apache.uima.util.Logger uimaLogger;
 
-  public UimacppShutdownHook(Process aprocess, Socket socket,
-      org.apache.uima.util.Logger logger) throws IOException {
+  public UimacppShutdownHook(Process aprocess, Socket socket, org.apache.uima.util.Logger logger)
+          throws IOException {
     this.uimacppProcess = aprocess;
     this.uimaLogger = logger;
   }

Modified: incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/UimacppServiceManagement.java
URL: http://svn.apache.org/viewvc/incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/UimacppServiceManagement.java?rev=810557&r1=810556&r2=810557&view=diff
==============================================================================
--- incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/UimacppServiceManagement.java (original)
+++ incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/UimacppServiceManagement.java Wed Sep  2 15:22:13 2009
@@ -29,17 +29,17 @@
 import java.util.StringTokenizer;
 
 /**
- * This class implements the JMX MBean interface to provide 
- * operational statistics about the C++ service.
+ * This class implements the JMX MBean interface to provide operational statistics about the C++
+ * service.
  */
 public class UimacppServiceManagement implements UimacppServiceManagementMBean {
- 
+
   private static final long serialVersionUID = -2507413276728501209L;
-  
+
   private static final long MAX_TIME_VALID = 500;
 
   private static long lastRefreshTime;
-  
+
   HashMap<String, String> jmxInfo;
 
   private String uniqueMBeanName;
@@ -59,11 +59,10 @@
   PrintWriter writer;
 
   public UimacppServiceManagement(String domainName, Socket sock, String aeDescriptor,
-      int numInstances, String brokerURL, String queueName) throws IOException {
-   
-    if (domainName==null  || domainName.length() == 0) {
-      domainName = "org.apache.uima:type=ee.jms.services,s="+
-      queueName + " Uima EE Service,";
+          int numInstances, String brokerURL, String queueName) throws IOException {
+
+    if (domainName == null || domainName.length() == 0) {
+      domainName = "org.apache.uima:type=ee.jms.services,s=" + queueName + " Uima EE Service,";
     }
     uniqueMBeanName = domainName + "name=" + queueName + "_Service";
     socket = sock;
@@ -80,18 +79,17 @@
   synchronized public String getStatisticsAsString() throws IOException {
 
     if (socket != null) {
-      //System.out.println("UimacppServiceManagement::getStatisticsAsString() Sending GETSTATS");
+      // System.out.println("UimacppServiceManagement::getStatisticsAsString() Sending GETSTATS");
 
       writer.write("GETSTATS");
       writer.flush();
 
-      //OutputStream os = socket.getOutputStream();
-      //os.flush();
-      //os.write(getstats.getBytes());
-
-      //System.out.println("getStatistics() Sent GETSTATS Waiting for reply");
-      BufferedReader in = new BufferedReader(new InputStreamReader(socket
-          .getInputStream()));
+      // OutputStream os = socket.getOutputStream();
+      // os.flush();
+      // os.write(getstats.getBytes());
+
+      // System.out.println("getStatistics() Sent GETSTATS Waiting for reply");
+      BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
 
       StringBuffer sb = new StringBuffer();
       int c = in.read();
@@ -140,11 +138,13 @@
   }
 
   synchronized public String getQueueBrokerURL() throws IOException {
-    //System.out.println("QueueBrokerURL");
-    /* We are assuming this method gets called first by the
-     * MBeanServer. So we send a request to C++ service to get latest stats. */
-    
-    if ( System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID ) {
+    // System.out.println("QueueBrokerURL");
+    /*
+     * We are assuming this method gets called first by the MBeanServer. So we send a request to C++
+     * service to get latest stats.
+     */
+
+    if (System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID) {
       getStatistics();
     }
 
@@ -152,24 +152,24 @@
   }
 
   synchronized public String getQueueName() throws IOException {
-    //System.out.println("QueueName");
-    if ( System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID ) {
+    // System.out.println("QueueName");
+    if (System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID) {
       getStatistics();
     }
     return queueName;
   }
 
   synchronized public String getAEDescriptor() throws IOException {
-    //System.out.println("aeDescriptor");
-    if ( System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID ) {
+    // System.out.println("aeDescriptor");
+    if (System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID) {
       getStatistics();
     }
     return aeDescriptor;
   }
 
   synchronized public int getAEInstances() throws IOException {
-    //System.out.println("aeInstances");
-    if ( System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID ) {
+    // System.out.println("aeInstances");
+    if (System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID) {
       getStatistics();
     }
     return aeInstances;
@@ -177,8 +177,8 @@
   }
 
   synchronized public long getErrorsGetMeta() throws IOException {
-    //System.out.println("GETMETAERRORS");
-    if ( System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID ) {
+    // System.out.println("GETMETAERRORS");
+    if (System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID) {
       getStatistics();
     }
     String v = jmxInfo.get("GETMETAERRORS");
@@ -190,8 +190,8 @@
   }
 
   synchronized public long getErrorsProcessCas() throws IOException {
-    //System.out.println("errorsProcessCas");
-    if ( System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID ) {
+    // System.out.println("errorsProcessCas");
+    if (System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID) {
       getStatistics();
     }
     String v = jmxInfo.get("PROCESSCASERRORS");
@@ -203,8 +203,8 @@
   }
 
   synchronized public long getErrorsCPC() throws IOException {
-    //System.out.println("errorsCPC");
-    if ( System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID ) {
+    // System.out.println("errorsCPC");
+    if (System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID) {
       getStatistics();
     }
     String v = jmxInfo.get("CPCERRORS");
@@ -216,8 +216,8 @@
   }
 
   synchronized public long getTotalNumCasProcessed() throws IOException {
-    //System.out.println("TotalNumCasProcessed");
-    if ( System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID ) {
+    // System.out.println("TotalNumCasProcessed");
+    if (System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID) {
       getStatistics();
     }
     String v = jmxInfo.get("NUMCASPROCESSED");
@@ -229,8 +229,8 @@
   }
 
   synchronized public long getTimingGetMeta() throws IOException {
-    //System.out.println("getTimingGetMeta");
-    if ( System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID ) {
+    // System.out.println("getTimingGetMeta");
+    if (System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID) {
       getStatistics();
     }
     String v = jmxInfo.get("GETMETATIME");
@@ -242,8 +242,8 @@
   }
 
   synchronized public long getTimingCPC() throws IOException {
-    //System.out.println("getTimingCPC");
-    if ( System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID ) {
+    // System.out.println("getTimingCPC");
+    if (System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID) {
       getStatistics();
     }
     String v = jmxInfo.get("CPCTIME");
@@ -255,8 +255,8 @@
   }
 
   synchronized public long getTimingSerialization() throws IOException {
-    //System.out.println("getTimingSerialization");
-    if ( System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID ) {
+    // System.out.println("getTimingSerialization");
+    if (System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID) {
       getStatistics();
     }
     String v = jmxInfo.get("SERIALIZETIME");
@@ -268,8 +268,8 @@
   }
 
   synchronized public long getTimingAnnotatorProcess() throws IOException {
-    //System.out.println("getTimingAnnotatorProcess");
-    if ( System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID ) {
+    // System.out.println("getTimingAnnotatorProcess");
+    if (System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID) {
       getStatistics();
     }
     String v = jmxInfo.get("ANNOTATORTIME");
@@ -281,8 +281,8 @@
   }
 
   synchronized public long getTimingDeserialization() throws IOException {
-    //System.out.println("getTimingDeserialization");
-    if ( System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID ) {
+    // System.out.println("getTimingDeserialization");
+    if (System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID) {
       getStatistics();
     }
     String v = jmxInfo.get("DESERIALIZETIME");
@@ -294,8 +294,8 @@
   }
 
   synchronized public long getTimingMessageProcessing() throws IOException {
-    //System.out.println("getTimingMessageProcessing");
-    if ( System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID ) {
+    // System.out.println("getTimingMessageProcessing");
+    if (System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID) {
       getStatistics();
     }
     String v = jmxInfo.get("MESSAGEPROCESSTIME");
@@ -307,8 +307,8 @@
   }
 
   synchronized public long getTimingIdle() throws IOException {
-    //System.out.println("getTimingIdle");
-    if ( System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID ) {
+    // System.out.println("getTimingIdle");
+    if (System.currentTimeMillis() - this.lastRefreshTime > MAX_TIME_VALID) {
       getStatistics();
     }
     String v = jmxInfo.get("IDLETIME");
@@ -337,10 +337,10 @@
 
   synchronized public void shutdown() throws IOException {
     if (this.socket != null) {
-      //System.out.println("UimacppServiceManagement sending shutdown message");
+      // System.out.println("UimacppServiceManagement sending shutdown message");
       writer.write("SHUTDOWN");
       writer.flush();
-      //System.out.println("UimacppServiceManagement sent shutdown message");
+      // System.out.println("UimacppServiceManagement sent shutdown message");
 
       return;
     } else {

Modified: incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/UimacppServiceManagementMBean.java
URL: http://svn.apache.org/viewvc/incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/UimacppServiceManagementMBean.java?rev=810557&r1=810556&r2=810557&view=diff
==============================================================================
--- incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/UimacppServiceManagementMBean.java (original)
+++ incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/UimacppServiceManagementMBean.java Wed Sep  2 15:22:13 2009
@@ -22,34 +22,48 @@
 import java.io.IOException;
 
 import org.apache.uima.resource.ManagementObject;
+
 /**
  * Defines the JMX management interface for the C++ service.
  */
-public interface UimacppServiceManagementMBean extends ManagementObject, 
-											java.io.Serializable {
-
+public interface UimacppServiceManagementMBean extends ManagementObject, java.io.Serializable {
 
   public String getQueueBrokerURL() throws IOException;
-  public String getQueueName()  throws IOException;
+
+  public String getQueueName() throws IOException;
+
   public String getAEDescriptor() throws IOException;
+
   public int getAEInstances() throws IOException;
-  
-	public long   getErrorsGetMeta() throws IOException;
-	public long   getErrorsProcessCas() throws IOException;
-	public long   getErrorsCPC() throws IOException;
-  
-	public long   getTotalNumCasProcessed() throws IOException;
-	public long   getTimingGetMeta() throws IOException;
-	public long   getTimingCPC() throws IOException;
-  public long   getTimingSerialization() throws IOException;
-  public long   getTimingAnnotatorProcess() throws IOException;
-  public long   getTimingDeserialization() throws IOException;
-  public long   getTimingMessageProcessing() throws IOException;
-  public long   getTimingIdle() throws IOException;
-  
-  public void   resetStats() throws IOException;
-  public void   increaseAEInstances(int num);
-  public void   decreaseAEInstances(int num);
-  public void   shutdown()throws IOException;
-    
+
+  public long getErrorsGetMeta() throws IOException;
+
+  public long getErrorsProcessCas() throws IOException;
+
+  public long getErrorsCPC() throws IOException;
+
+  public long getTotalNumCasProcessed() throws IOException;
+
+  public long getTimingGetMeta() throws IOException;
+
+  public long getTimingCPC() throws IOException;
+
+  public long getTimingSerialization() throws IOException;
+
+  public long getTimingAnnotatorProcess() throws IOException;
+
+  public long getTimingDeserialization() throws IOException;
+
+  public long getTimingMessageProcessing() throws IOException;
+
+  public long getTimingIdle() throws IOException;
+
+  public void resetStats() throws IOException;
+
+  public void increaseAEInstances(int num);
+
+  public void decreaseAEInstances(int num);
+
+  public void shutdown() throws IOException;
+
 }

Modified: incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/delegate/ControllerDelegate.java
URL: http://svn.apache.org/viewvc/incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/delegate/ControllerDelegate.java?rev=810557&r1=810556&r2=810557&view=diff
==============================================================================
--- incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/delegate/ControllerDelegate.java (original)
+++ incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/delegate/ControllerDelegate.java Wed Sep  2 15:22:13 2009
@@ -35,13 +35,15 @@
     super.delegateKey = aDelegateKey;
     controller = aController;
   }
+
   public String getComponentName() {
     return controller.getComponentName();
   }
+
   public void handleError(Exception e, ErrorContext errorContext) {
-    if (controller != null &&  controller.getErrorHandlerChain() != null) {
-        // Handle Timeout
-        controller.getErrorHandlerChain().handle(e, errorContext, controller);
+    if (controller != null && controller.getErrorHandlerChain() != null) {
+      // Handle Timeout
+      controller.getErrorHandlerChain().handle(e, errorContext, controller);
     }
   }
 }

Modified: incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/delegate/Delegate.java
URL: http://svn.apache.org/viewvc/incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/delegate/Delegate.java?rev=810557&r1=810556&r2=810557&view=diff
==============================================================================
--- incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/delegate/Delegate.java (original)
+++ incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/delegate/Delegate.java Wed Sep  2 15:22:13 2009
@@ -74,13 +74,13 @@
   // CASes should be send to the delegate as soon as the getMeta (Ping) is received.
   private List<DelegateEntry> pendingDispatchList = new ArrayList<DelegateEntry>();
 
-  //  Flag that is set when getMeta reply is received
+  // Flag that is set when getMeta reply is received
   private volatile boolean awaitingPingReply;
 
   private volatile boolean concurrentConsumersOnReplyQueue;
-  
+
   private Endpoint notificationEndpoint = null;
-  
+
   public Endpoint getNotificationEndpoint() {
     return notificationEndpoint;
   }
@@ -100,6 +100,7 @@
   public void resetAwaitingPingReply() {
     this.awaitingPingReply = false;
   }
+
   /**
    * Returns delegate key
    * 
@@ -127,28 +128,29 @@
   public Endpoint getEndpoint() {
     return endpoint;
   }
+
   /**
-   * Forces Timer restart for the oldest CAS sitting in the list
-   * of CASes pending reply.  
+   * Forces Timer restart for the oldest CAS sitting in the list of CASes pending reply.
    */
   public void restartTimerForOldestCasInOutstandingList() {
     DelegateEntry entry = null;
     synchronized (outstandingCasList) {
       if (!outstandingCasList.isEmpty()) {
-        //  Get the oldest entry
+        // Get the oldest entry
         entry = outstandingCasList.get(0);
-        if ( entry != null ) {
+        if (entry != null) {
           restartTimerForCas(entry);
         }
       }
     }
   }
+
   /**
    * Restarts timer for a given CAS
    * 
    * @param entry
    */
-  private void restartTimerForCas( DelegateEntry entry ) {
+  private void restartTimerForCas(DelegateEntry entry) {
     if (getCasProcessTimeout() > 0) {
       entry.incrementRetryCount();
       // restart timer for retry
@@ -163,30 +165,32 @@
                 new Object[] { getComponentName(), delegateKey, entry.getCasReferenceId(),
                     getCasProcessTimeout() });
       }
-    }    
+    }
   }
 
   public List<DelegateEntry> getDelegateCasesPendingRepy() {
     return outstandingCasList;
   }
-  
+
   public void addNewCasToOutstandingList(String aCasReferenceId) {
     addNewCasToOutstandingList(aCasReferenceId, false);
   }
-  public void addNewCasToOutstandingList(String aCasReferenceId, boolean isCasGeneratingChildren ) {
+
+  public void addNewCasToOutstandingList(String aCasReferenceId, boolean isCasGeneratingChildren) {
     synchronized (outstandingCasList) {
       DelegateEntry entry = null;
-      if ( (entry = lookupEntry(aCasReferenceId, outstandingCasList)) == null) {
+      if ((entry = lookupEntry(aCasReferenceId, outstandingCasList)) == null) {
         entry = new DelegateEntry(aCasReferenceId);
         // Remember the command
         entry.setCommand(AsynchAEMessage.Process);
-        if ( isCasGeneratingChildren ) {
+        if (isCasGeneratingChildren) {
           entry.setGeneratingChildren(true);
         }
         outstandingCasList.add(entry);
       }
     }
   }
+
   /**
    * Adds a given Cas ID to the list of CASes pending reply. A new timer will be started to handle
    * delegate's timeout if either: 1) the list of CASes pending reply is empty AND delegate timeout
@@ -202,7 +206,8 @@
       // Check if the outstanding list already contains entry for the Cas Id. If it does, retry
       // logic
       // is calling this method. Increment number of retries and restart the timer.
-      if (!outstandingCasList.isEmpty() && (entry = lookupEntry(aCasReferenceId, outstandingCasList)) != null) {
+      if (!outstandingCasList.isEmpty()
+              && (entry = lookupEntry(aCasReferenceId, outstandingCasList)) != null) {
         restartTimerForCas(entry);
       } else {
         // Create a new entry to be stored in the list of CASes pending reply
@@ -273,39 +278,36 @@
       return pendingDispatchList.size();
     }
   }
+
   /**
-   * Logs CASes sitting in the list of CASes pending dispatch. These CASes
-   * were delayed due to a bad state of the delegate. 
+   * Logs CASes sitting in the list of CASes pending dispatch. These CASes were delayed due to a bad
+   * state of the delegate.
    */
   private void dumpDelayedList() {
     if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.FINE)) {
-      for( DelegateEntry entry: pendingDispatchList) {
-        UIMAFramework.getLogger(CLASS_NAME).logrb(
-                Level.FINE,
-                this.getClass().getName(),
-                "dumpDelayedList",
-                UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE,
+      for (DelegateEntry entry : pendingDispatchList) {
+        UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINE, this.getClass().getName(),
+                "dumpDelayedList", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE,
                 "UIMAEE_dump_cas_pending_dispatch__FINE",
-                new Object[] { getComponentName(),  entry.getCasReferenceId(), delegateKey });
+                new Object[] { getComponentName(), entry.getCasReferenceId(), delegateKey });
       }
     }
   }
+
   /**
-   * Logs CASes sitting in the list of CASes pending reply. 
+   * Logs CASes sitting in the list of CASes pending reply.
    */
   private void dumpPendingReplyList() {
     if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.FINE)) {
-      for( DelegateEntry entry: outstandingCasList) {
-        UIMAFramework.getLogger(CLASS_NAME).logrb(
-                Level.FINE,
-                this.getClass().getName(),
-                "dumpPendingReplyList",
-                UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE,
+      for (DelegateEntry entry : outstandingCasList) {
+        UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINE, this.getClass().getName(),
+                "dumpPendingReplyList", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE,
                 "UIMAEE_dump_cas_pending_reply__FINE",
-                new Object[] { getComponentName(),  entry.getCasReferenceId(), delegateKey });
+                new Object[] { getComponentName(), entry.getCasReferenceId(), delegateKey });
       }
     }
   }
+
   /**
    * Increments retry count
    * 
@@ -345,20 +347,19 @@
     }
     return null;
   }
-  /** 
-   * Removes the oldest entry from the list of CASes pending dispatch.
-   * A CAS is delayed and placed on this list when the delegate status
-   * changes to TIMED_OUT and a PING message is sent to test delegate 
-   * availability. Until the PING message is acked by the delegate OR
-   * the PING times out, all CASes are delayed. When the PING is acked
-   * by the delegate ALL delayed CASes are sent to the delegate one at
-   * a time.
+
+  /**
+   * Removes the oldest entry from the list of CASes pending dispatch. A CAS is delayed and placed
+   * on this list when the delegate status changes to TIMED_OUT and a PING message is sent to test
+   * delegate availability. Until the PING message is acked by the delegate OR the PING times out,
+   * all CASes are delayed. When the PING is acked by the delegate ALL delayed CASes are sent to the
+   * delegate one at a time.
    * 
    * @return - ID of the oldest CAS in the list
    */
   public String removeOldestFromPendingDispatchList() {
     synchronized (pendingDispatchList) {
-      if ( pendingDispatchList.size() > 0 ) {
+      if (pendingDispatchList.size() > 0) {
         String casReferenceId = pendingDispatchList.remove(0).getCasReferenceId();
         if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.FINE)) {
           UIMAFramework.getLogger(CLASS_NAME).logrb(
@@ -368,7 +369,7 @@
                   UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE,
                   "UIMAEE_removed_cas_from_delegate_pending_dispatch_list__FINE",
                   new Object[] { getComponentName(), delegateKey, casReferenceId,
-                    pendingDispatchList.size() });
+                      pendingDispatchList.size() });
         }
         return casReferenceId;
       }
@@ -376,15 +377,12 @@
     return null;
   }
 
-  
-  /** 
-   * Removes an entry from the list of CASes pending dispatch that
-   * matches a given CAS Id.A CAS is delayed and placed on this list when the delegate status
-   * changes to TIMED_OUT and a PING message is sent to test delegate 
-   * availability. Until the PING message is acked by the delegate OR
-   * the PING times out, all CASes are delayed. When the PING is acked
-   * by the delegate ALL delayed CASes are sent to the delegate one at
-   * a time.
+  /**
+   * Removes an entry from the list of CASes pending dispatch that matches a given CAS Id.A CAS is
+   * delayed and placed on this list when the delegate status changes to TIMED_OUT and a PING
+   * message is sent to test delegate availability. Until the PING message is acked by the delegate
+   * OR the PING times out, all CASes are delayed. When the PING is acked by the delegate ALL
+   * delayed CASes are sent to the delegate one at a time.
    * 
    * @return - ID of the oldest CAS in the list
    */
@@ -401,7 +399,7 @@
                   UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE,
                   "UIMAEE_removed_cas_from_delegate_pending_dispatch_list__FINE",
                   new Object[] { getComponentName(), delegateKey, entry.getCasReferenceId(),
-                    pendingDispatchList.size() });
+                      pendingDispatchList.size() });
         }
         return true;
       }
@@ -442,12 +440,13 @@
       return outstandingCasList.remove(0).getCasReferenceId();
     }
   }
-  
+
   public String getOldestCasIdFromOutstandingList() {
     synchronized (outstandingCasList) {
       return outstandingCasList.get(0).getCasReferenceId();
     }
   }
+
   /**
    * Removes {@link DelegateEntry} from the list of CASes pending reply. If the CAS removed was the
    * oldest in the list (first in the list) AND there are other CASes in the list pending reply AND
@@ -506,7 +505,7 @@
     synchronized (outstandingCasList) {
       outstandingCasList.clear();
     }
-    synchronized( pendingDispatchList) {
+    synchronized (pendingDispatchList) {
       pendingDispatchList.clear();
     }
   }
@@ -522,7 +521,7 @@
       return pendingDispatchList.size();
     }
   }
-  
+
   /**
    * Cancels current timer
    */
@@ -571,23 +570,23 @@
    *          - command for which the timer is started
    */
   private synchronized void startDelegateTimer(final String aCasReferenceId, final int aCommand) {
-    //  Check if we are awaiting a Ping reply. While awaiting ping reply dont start
-    //  a new timer.
-    if ( isAwaitingPingReply() ) {
-      //  Ping is actually a GetMeta request
-      if ( aCommand == AsynchAEMessage.GetMeta ) {
-        //  Cancel any outstanding timers. A timer for a Ping message is about to
-        //  be started. Another thread may have started a Process timer.
+    // Check if we are awaiting a Ping reply. While awaiting ping reply dont start
+    // a new timer.
+    if (isAwaitingPingReply()) {
+      // Ping is actually a GetMeta request
+      if (aCommand == AsynchAEMessage.GetMeta) {
+        // Cancel any outstanding timers. A timer for a Ping message is about to
+        // be started. Another thread may have started a Process timer.
         cancelDelegateTimer();
       } else {
-        //  We are waiting for a ping reply, don't start a new timer
+        // We are waiting for a ping reply, don't start a new timer
         return;
       }
     }
     final long timeToWait = getTimeoutValueForCommand(aCommand);
     Date timeToRun = new Date(System.currentTimeMillis() + timeToWait);
-    timer = new Timer("Controller:" + getComponentName() + ":Request TimerThread-Endpoint_impl:" + endpoint
-            + ":" + System.nanoTime() + ":Cmd:" + aCommand);
+    timer = new Timer("Controller:" + getComponentName() + ":Request TimerThread-Endpoint_impl:"
+            + endpoint + ":" + System.nanoTime() + ":Cmd:" + aCommand);
     final Delegate delegate = this;
     timer.schedule(new TimerTask() {
       public void run() {
@@ -611,14 +610,14 @@
                     "UIMAEE_meta_timeout_no_reply__INFO",
                     new Object[] { delegate.getKey(), timeToWait });
           }
-          //  Check if this is a Ping timeout. If it is and there are CASes on
-          //  the list of CASes pending reply, treat this timeout as Process
-          //  Timeout
-          if ( isAwaitingPingReply() && getCasPendingReplyListSize() > 0) {
+          // Check if this is a Ping timeout. If it is and there are CASes on
+          // the list of CASes pending reply, treat this timeout as Process
+          // Timeout
+          if (isAwaitingPingReply() && getCasPendingReplyListSize() > 0) {
             String casReferenceId = getOldestCasIdFromOutstandingList();
             errorContext.add(AsynchAEMessage.CasReference, casReferenceId);
-            //  Override the command to make sure this timeout is handled
-            //  by the ProcessCasErrorHandler.
+            // Override the command to make sure this timeout is handled
+            // by the ProcessCasErrorHandler.
             errorContext.add(AsynchAEMessage.Command, AsynchAEMessage.Process);
             errorContext.add(AsynchAEMessage.ErrorCause, AsynchAEMessage.PingTimeout);
           }
@@ -669,36 +668,38 @@
 
   public void setState(int aState) {
     synchronized (stateMux) {
-      //  Change the state to timout, only if the current state = OK_STATE
-      //  This prevents overriding DISABLED state.
-      if ( aState == TIMEOUT_STATE && this.state != OK_STATE ) {
+      // Change the state to timout, only if the current state = OK_STATE
+      // This prevents overriding DISABLED state.
+      if (aState == TIMEOUT_STATE && this.state != OK_STATE) {
         return;
-      } 
+      }
       state = aState;
     }
   }
+
   public void setConcurrentConsumersOnReplyQueue() {
     concurrentConsumersOnReplyQueue = true;
   }
+
   public boolean hasConcurrentConsumersOnReplyQueue() {
     return concurrentConsumersOnReplyQueue;
   }
-  
-  public boolean isGeneratingChildrenFrom(String aCasReferenceId ) {
-    synchronized( outstandingCasList) {
+
+  public boolean isGeneratingChildrenFrom(String aCasReferenceId) {
+    synchronized (outstandingCasList) {
       DelegateEntry entry = lookupEntry(aCasReferenceId, outstandingCasList);
-      if ( entry == null ) {
+      if (entry == null) {
         return false;
       } else {
         return entry.isGeneratingChildren();
       }
     }
   }
-  
-  public void setGeneratingChildrenFrom(String aCasReferenceId, boolean tOf ) {
-    synchronized( outstandingCasList) {
+
+  public void setGeneratingChildrenFrom(String aCasReferenceId, boolean tOf) {
+    synchronized (outstandingCasList) {
       DelegateEntry entry = lookupEntry(aCasReferenceId, outstandingCasList);
-      if ( entry == null ) {
+      if (entry == null) {
         // noop;
       } else {
         entry.setGeneratingChildren(tOf);
@@ -724,7 +725,7 @@
     private int retryCount = 0;
 
     private volatile boolean generatingChildren = false;
-    
+
     public DelegateEntry(String aCasReferenceId) {
       casReferenceId = aCasReferenceId;
     }
@@ -761,5 +762,5 @@
       return casReferenceId;
     }
   }
-  
+
 }

Modified: incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/deploymentDescriptor/XsltGUIDgenerator.java
URL: http://svn.apache.org/viewvc/incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/deploymentDescriptor/XsltGUIDgenerator.java?rev=810557&r1=810556&r2=810557&view=diff
==============================================================================
--- incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/deploymentDescriptor/XsltGUIDgenerator.java (original)
+++ incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/deploymentDescriptor/XsltGUIDgenerator.java Wed Sep  2 15:22:13 2009
@@ -40,5 +40,4 @@
     return localhost + new UID().toString();
   }
 
-
 }

Modified: incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/deploymentDescriptor/XsltImportByName.java
URL: http://svn.apache.org/viewvc/incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/deploymentDescriptor/XsltImportByName.java?rev=810557&r1=810556&r2=810557&view=diff
==============================================================================
--- incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/deploymentDescriptor/XsltImportByName.java (original)
+++ incubator/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/deploymentDescriptor/XsltImportByName.java Wed Sep  2 15:22:13 2009
@@ -26,7 +26,7 @@
 import org.apache.uima.util.InvalidXMLException;
 
 public class XsltImportByName {
-  
+
   public static String resolveByName(String input) {
     ResourceManager resourceManager = UIMAFramework.newDefaultResourceManager();
     Import theImport = new Import_impl();
@@ -39,6 +39,4 @@
     }
   }
 
-
-
 }