directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r366626 - /directory/trunk/apacheds-server-unit/src/test/java/org/apache/ldap/server/ChangeListener.java
Date Sat, 07 Jan 2006 01:44:29 GMT
Author: akarasulu
Date: Fri Jan  6 17:44:27 2006
New Revision: 366626

URL: http://svn.apache.org/viewcvs?rev=366626&view=rev
Log:
add a shutdown hook to abandon a request

Modified:
    directory/trunk/apacheds-server-unit/src/test/java/org/apache/ldap/server/ChangeListener.java

Modified: directory/trunk/apacheds-server-unit/src/test/java/org/apache/ldap/server/ChangeListener.java
URL: http://svn.apache.org/viewcvs/directory/trunk/apacheds-server-unit/src/test/java/org/apache/ldap/server/ChangeListener.java?rev=366626&r1=366625&r2=366626&view=diff
==============================================================================
--- directory/trunk/apacheds-server-unit/src/test/java/org/apache/ldap/server/ChangeListener.java
(original)
+++ directory/trunk/apacheds-server-unit/src/test/java/org/apache/ldap/server/ChangeListener.java
Fri Jan  6 17:44:27 2006
@@ -19,6 +19,7 @@
 
 import java.util.Hashtable;
 
+import javax.naming.Context;
 import javax.naming.NamingEnumeration;
 import javax.naming.directory.SearchResult;
 import javax.naming.ldap.Control;
@@ -48,6 +49,7 @@
         env.put( "java.naming.security.credentials", "secret" );
         env.put( "java.naming.security.authentication", "simple" );
         InitialLdapContext ctx = new InitialLdapContext( env, null );
+        Runtime.getRuntime().addShutdownHook( new Thread( new ShutdownHook( ctx ) ) );
         PersistentSearchControl control = new PersistentSearchControl();
         control.setChangesOnly( false );
         control.setReturnECs( true );
@@ -103,6 +105,25 @@
         catch( Exception e ) 
         {
             e.printStackTrace();
+        }
+    }
+    
+    
+    static class ShutdownHook implements Runnable
+    {
+        final Context ctx;
+        
+        ShutdownHook( Context ctx )
+        {
+            this.ctx = ctx;
+        }
+        
+        public void run()
+        {
+            if ( ctx != null )
+            {
+                try { ctx.close(); } catch( Exception e ){ e.printStackTrace(); };
+            }
         }
     }
 }



Mime
View raw message