uima-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cwik...@apache.org
Subject svn commit: r800791 - /incubator/uima/sandbox/trunk/uima-as/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/BaseAnalysisEngineController.java
Date Tue, 04 Aug 2009 13:51:52 GMT
Author: cwiklik
Date: Tue Aug  4 13:51:52 2009
New Revision: 800791

URL: http://svn.apache.org/viewvc?rev=800791&view=rev
Log:
UIMA-1454 Added code to handle DoNotProcess List. Added cleanup thread to remove expired entries
from the DoNotProcess list

Modified:
    incubator/uima/sandbox/trunk/uima-as/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/BaseAnalysisEngineController.java

Modified: incubator/uima/sandbox/trunk/uima-as/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/BaseAnalysisEngineController.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/uima-as/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/BaseAnalysisEngineController.java?rev=800791&r1=800790&r2=800791&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/uima-as/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/BaseAnalysisEngineController.java
(original)
+++ incubator/uima/sandbox/trunk/uima-as/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/BaseAnalysisEngineController.java
Tue Aug  4 13:51:52 2009
@@ -36,6 +36,9 @@
 import java.util.Map.Entry;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
 
 import javax.management.ObjectName;
 
@@ -96,6 +99,8 @@
 {
 	private static final Class CLASS_NAME = BaseAnalysisEngineController.class;
 
+	private static final long DoNotProcessTTL = 30*60*1000;  // 30 minute time to live 
+	
 	protected volatile ControllerLatch latch = new ControllerLatch();
 
 	protected ConcurrentHashMap statsMap = new ConcurrentHashMap();
@@ -229,6 +234,12 @@
   
   //  Set to true when stopping the service
   private volatile boolean releasedAllCASes;
+  
+  protected List<DoNotProcessEntry> doNotProcessList = 
+    new ArrayList<DoNotProcessEntry>();
+  
+  private ScheduledExecutorService daemonServiceExecutor=null;
+  
   public BaseAnalysisEngineController() {
     
   }
@@ -1798,6 +1809,10 @@
 		{
 			setStopped();
 		}
+		
+		if ( daemonServiceExecutor != null ) {
+		  daemonServiceExecutor.shutdown();
+		}
     if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.INFO)) {
       UIMAFramework.getLogger(CLASS_NAME).logrb(Level.INFO, getClass().getName(), "stop",
UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE, "UIMAEE_stop__INFO", new Object[] { getComponentName()
});
     }
@@ -2803,5 +2818,90 @@
 	  public boolean isAwaitingCacheCallbackNotification() {
 	    return awaitingCacheCallbackNotification;
 	  }
+	  public void addEndpointToDoNotProcessList( String anEndpointName ) {
+	    if ( !isEndpointOnDontProcessList(anEndpointName)) {
+        if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.INFO)) {
+          UIMAFramework.getLogger(CLASS_NAME).logrb(Level.INFO, CLASS_NAME.getName(),
+                   "addEndpointToDoNotProcessList", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE,
"UIMAEE_add_endpoint_to_do_not_process_list__INFO",
+                   new Object[] { getComponentName(), anEndpointName });
+        }
+	      // Given endpoint will be removed from DoNotProcess list in 30 minutes. 
+	      doNotProcessList.add(new DoNotProcessEntry(DoNotProcessTTL, anEndpointName));
+	    }
+	  }
+	  
+	  public boolean isEndpointOnDontProcessList( String anEndpointName) {
+      for( Iterator<DoNotProcessEntry> it = doNotProcessList.iterator(); it.hasNext();){
+        DoNotProcessEntry entry = it.next();
+        if ( entry.getEndpointName().equals(anEndpointName)) {
+          return true;
+        }
+      }
+      return false;
+	  }
+	  /**
+	   * Invoked by a cleaner thread this method removed entries from a DoNotProcess 
+	   * list that are older than 30 minutes.
+	   */
+	  public void cleanup() {
+	    try {
+	      for( Iterator<DoNotProcessEntry> it = doNotProcessList.iterator(); it.hasNext();){
+	        DoNotProcessEntry entry = it.next();
+	        if ( entry.hasExpired() ) {
+	          doNotProcessList.remove(entry);
+	        }
+	      }
+	    } catch( Exception e) {
+	      
+	    }
+	  }
+	  // An entry for the DoNotProcess list. Holds endpoints that are no longer
+	  // reachable. Each entry expires in 30 minutes of its creation and is
+	  // subsequently removed from the list.
+	  private class DoNotProcessEntry {
+	    private long timeToLive;
+	    private String endpointName;
+	    private long entryTime;
+	    
+	    public DoNotProcessEntry( long aTimeToLive, String anEndpointName) {
+	      timeToLive = aTimeToLive;
+	      endpointName = anEndpointName;
+	      entryTime = System.currentTimeMillis();
+	    }
+	    public boolean hasExpired() {
+	      long now = System.currentTimeMillis();
+	      if ( now > (entryTime+timeToLive) ) {
+	        return true;
+	      }
+	      return false;
+	    }
+      public String getEndpointName() {
+        return endpointName;
+      }
+	  }
 	  
+	  // Cleanup thread 
+	  protected class UimaAsServiceCleanupThread implements Runnable { 
+	   
+	    private AnalysisEngineController controller;
+	    
+	    public UimaAsServiceCleanupThread( AnalysisEngineController aController ) {
+	      controller = aController;
+	    }
+	    
+	    public void run() {
+	      controller.cleanup();
+	    }
+	  }
+
+	  /**
+	   * Registers runnable cleanup thread. It will run at a given intervals until
+	   * the service is stopped.
+	   * 
+	   * @param sleepInterval - how often to run in millis
+	   */
+	  protected void startServiceCleanupThread(long sleepInterval ) {
+	    daemonServiceExecutor = Executors.newScheduledThreadPool(1);
+	    daemonServiceExecutor.scheduleWithFixedDelay(new UimaAsServiceCleanupThread(this), 0,
sleepInterval, TimeUnit.MILLISECONDS);
+	  }
 }



Mime
View raw message