jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1055071 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: ./ query/ query/lucene/
Date Tue, 04 Jan 2011 14:54:03 GMT
Author: jukka
Date: Tue Jan  4 14:54:03 2011
New Revision: 1055071

URL: http://svn.apache.org/viewvc?rev=1055071&view=rev
Log:
JCR-2836: Unclosed threads in Jackrabbit

Merge all timers into a single repository-wide timer instance and arrange for it to be cancelled
when the repository is shutdown.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java?rev=1055071&r1=1055070&r2=1055071&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java
Tue Jan  4 14:54:03 2011
@@ -24,6 +24,7 @@ import org.apache.jackrabbit.core.nodety
 import org.apache.jackrabbit.core.security.JackrabbitSecurityManager;
 import org.apache.jackrabbit.core.state.ItemStateCacheFactory;
 import org.apache.jackrabbit.core.version.InternalVersionManagerImpl;
+import org.apache.jackrabbit.util.Timer;
 
 /**
  * Internal component context of a Jackrabbit content repository.
@@ -90,6 +91,11 @@ public class RepositoryContext {
     private ItemStateCacheFactory itemStateCacheFactory;
 
     /**
+     * Repository-wide timer instance.
+     */
+    private final Timer timer = new Timer(false);
+
+    /**
      * Creates a component context for the given repository.
      *
      * @param repository repository instance
@@ -109,6 +115,15 @@ public class RepositoryContext {
     }
 
     /**
+     * Returns the repository-wide timer instance.
+     *
+     * @return repository timer
+     */
+    public Timer getTimer() {
+        return timer;
+    }
+
+    /**
      * Returns the namespace registry of this repository.
      *
      * @return namespace registry

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java?rev=1055071&r1=1055070&r2=1055071&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
Tue Jan  4 14:54:03 2011
@@ -626,9 +626,8 @@ public class RepositoryImpl extends Abst
         if (systemSearchMgr == null) {
             if (repConfig.isSearchEnabled()) {
                 systemSearchMgr = new SearchManager(
+                        context,
                         repConfig,
-                        context.getNamespaceRegistry(),
-                        context.getNodeTypeRegistry(),
                         getWorkspaceInfo(wspName).itemStateMgr,
                         context.getInternalVersionManager().getPersistenceManager(),
                         SYSTEM_ROOT_NODE_ID,
@@ -1168,6 +1167,8 @@ public class RepositoryImpl extends Abst
             }
         }
 
+        context.getTimer().cancel();
+
         log.info("Repository has been shutdown");
     }
 
@@ -1857,9 +1858,8 @@ public class RepositoryImpl extends Abst
                     // search manager is lazily instantiated in order to avoid
                     // 'chicken & egg' bootstrap problems
                     searchMgr = new SearchManager(
+                            context,
                             config,
-                            context.getNamespaceRegistry(),
-                            context.getNodeTypeRegistry(),
                             itemStateMgr, persistMgr,
                             context.getRootNodeId(),
                             getSystemSearchManager(getName()),

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java?rev=1055071&r1=1055070&r2=1055071&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
Tue Jan  4 14:54:03 2011
@@ -127,16 +127,16 @@ public class SearchManager implements Sy
      *                       excluded from indexing.
      * @throws RepositoryException if the search manager cannot be initialized
      */
-    public SearchManager(QueryHandlerFactory qhf,
-                         final NamespaceRegistryImpl nsReg,
-                         NodeTypeRegistry ntReg,
+    public SearchManager(
+            RepositoryContext repositoryContext,
+            QueryHandlerFactory qhf,
                          SharedItemStateManager itemMgr,
                          PersistenceManager pm,
                          NodeId rootNodeId,
                          SearchManager parentMgr,
                          NodeId excludedNodeId,
                          Executor executor) throws RepositoryException {
-        this.nsReg = nsReg;
+        this.nsReg = repositoryContext.getNamespaceRegistry();
         this.itemMgr = itemMgr;
         this.parentHandler = (parentMgr != null) ? parentMgr.handler : null;
 
@@ -172,7 +172,8 @@ public class SearchManager implements Sy
 
         // initialize query handler
         this.handler = qhf.getQueryHandler(new QueryHandlerContext(
-                itemMgr, pm, rootNodeId, ntReg, nsReg,
+                repositoryContext,
+                itemMgr, pm, rootNodeId,
                 parentHandler, excludedNodeId, executor));
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java?rev=1055071&r1=1055070&r2=1055071&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransactionContext.java
Tue Jan  4 14:54:03 2011
@@ -55,9 +55,9 @@ public class TransactionContext extends 
     private static final ThreadLocal<Xid> CURRENT_XID = new ThreadLocal<Xid>();
 
     /**
-     * Create a global timer for all transaction contexts.
+     * Timer for all transaction contexts.
      */
-    private static final Timer TIMER = new Timer(true);
+    private final Timer timer;
 
     /**
      * Transactional resources.
@@ -95,10 +95,13 @@ public class TransactionContext extends 
      * @param resources transactional resources
      * @param timeout timeout, in seconds
      */
-    public TransactionContext(Xid xid, InternalXAResource[] resources, int timeout) {
+    public TransactionContext(
+            Xid xid, InternalXAResource[] resources,
+            int timeout, Timer timer) {
         this.xid = xid;
         this.resources = resources;
         this.timeout = timeout;
+        this.timer = timer;
     }
 
     /**
@@ -174,7 +177,7 @@ public class TransactionContext extends 
         }
 
         // start rollback task in case the commit is never issued
-        TIMER.schedule(this, timeout * 1000, Integer.MAX_VALUE);
+        timer.schedule(this, timeout * 1000, Integer.MAX_VALUE);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java?rev=1055071&r1=1055070&r2=1055071&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/XASessionImpl.java
Tue Jan  4 14:54:03 2011
@@ -251,7 +251,9 @@ public class XASessionImpl extends Sessi
      * @return transaction context
      */
     private TransactionContext createTransaction(Xid xid) {
-        TransactionContext tx = new TransactionContext(xid, txResources, getTransactionTimeout());
+        TransactionContext tx = new TransactionContext(
+                xid, txResources,
+                getTransactionTimeout(), repositoryContext.getTimer());
         txGlobal.put(xid, tx);
         return tx;
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java?rev=1055071&r1=1055070&r2=1055071&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandlerContext.java
Tue Jan  4 14:54:03 2011
@@ -21,11 +21,13 @@ import java.util.concurrent.Executor;
 import org.apache.jackrabbit.core.CachingHierarchyManager;
 import org.apache.jackrabbit.core.HierarchyManager;
 import org.apache.jackrabbit.core.NamespaceRegistryImpl;
+import org.apache.jackrabbit.core.RepositoryContext;
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.nodetype.NodeTypeRegistry;
 import org.apache.jackrabbit.core.persistence.PersistenceManager;
 import org.apache.jackrabbit.core.state.ItemStateManager;
 import org.apache.jackrabbit.core.state.SharedItemStateManager;
+import org.apache.jackrabbit.util.Timer;
 
 /**
  * Acts as an argument for the {@link QueryHandler} to keep the interface
@@ -35,6 +37,11 @@ import org.apache.jackrabbit.core.state.
 public class QueryHandlerContext {
 
     /**
+     * Repository context.
+     */
+    private final RepositoryContext repositoryContext;
+
+    /**
      * The persistent <code>ItemStateManager</code>
      */
     private final SharedItemStateManager stateMgr;
@@ -50,16 +57,6 @@ public class QueryHandlerContext {
     private final PersistenceManager pm;
 
     /**
-     * The node type registry of the repository
-     */
-    private final NodeTypeRegistry ntRegistry;
-
-    /**
-     * The namespace registry of the repository.
-     */
-    private final NamespaceRegistryImpl nsRegistry;
-
-    /**
      * The id of the root node.
      */
     private NodeId rootId;
@@ -90,8 +87,6 @@ public class QueryHandlerContext {
      * @param stateMgr         provides persistent item states.
      * @param pm               the underlying persistence manager.
      * @param rootId           the id of the root node.
-     * @param ntRegistry       the node type registry.
-     * @param nsRegistry       the namespace registry.
      * @param parentHandler    the parent query handler or <code>null</code>
it
      *                         there is no parent handler.
      * @param excludedNodeId   id of the node that should be excluded from
@@ -99,21 +94,21 @@ public class QueryHandlerContext {
      *                         excluded from indexing.
      * @param executor         background task executor
      */
-    public QueryHandlerContext(SharedItemStateManager stateMgr,
-                               PersistenceManager pm,
-                               NodeId rootId,
-                               NodeTypeRegistry ntRegistry,
-                               NamespaceRegistryImpl nsRegistry,
-                               QueryHandler parentHandler,
-                               NodeId excludedNodeId,
-                               Executor executor) {
+    public QueryHandlerContext(
+            RepositoryContext repositoryContext,
+            SharedItemStateManager stateMgr,
+            PersistenceManager pm,
+            NodeId rootId,
+            QueryHandler parentHandler,
+            NodeId excludedNodeId,
+            Executor executor) {
+        this.repositoryContext = repositoryContext;
         this.stateMgr = stateMgr;
         this.hmgr = new CachingHierarchyManager(rootId, stateMgr);
         this.stateMgr.addListener(hmgr);
         this.pm = pm;
         this.rootId = rootId;
-        this.ntRegistry = ntRegistry;
-        this.nsRegistry = nsRegistry;
+        NodeTypeRegistry ntRegistry = repositoryContext.getNodeTypeRegistry();
         propRegistry = new PropertyTypeRegistry(ntRegistry);
         this.parentHandler = parentHandler;
         this.excludedNodeId = excludedNodeId;
@@ -170,7 +165,7 @@ public class QueryHandlerContext {
      * @return the NodeTypeRegistry for this repository.
      */
     public NodeTypeRegistry getNodeTypeRegistry() {
-        return ntRegistry;
+        return repositoryContext.getNodeTypeRegistry();
     }
 
     /**
@@ -178,7 +173,7 @@ public class QueryHandlerContext {
      * @return the NamespaceRegistryImpl for this repository.
      */
     public NamespaceRegistryImpl getNamespaceRegistry() {
-        return nsRegistry;
+        return repositoryContext.getNamespaceRegistry();
     }
 
     /**
@@ -203,7 +198,7 @@ public class QueryHandlerContext {
      * Destroys this context and releases resources.
      */
     public void destroy() {
-        ntRegistry.removeListener(propRegistry);
+        repositoryContext.getNodeTypeRegistry().removeListener(propRegistry);
     }
 
     /**
@@ -215,4 +210,13 @@ public class QueryHandlerContext {
         return executor;
     }
 
+    /**
+     * Returns the repository timer.
+     *
+     * @return repository timer
+     */
+    public Timer getTimer() {
+        return repositoryContext.getTimer();
+    }
+
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java?rev=1055071&r1=1055070&r2=1055071&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiIndex.java
Tue Jan  4 14:54:03 2011
@@ -183,12 +183,7 @@ public class MultiIndex {
     private final IndexMerger merger;
 
     /**
-     * Timer to schedule flushes of this index after some idle time.
-     */
-    private final Timer flushTimer = new Timer(true);
-
-    /**
-     * Task that is periodically called by {@link #FLUSH_TIMER} and checks
+     * Task that is periodically called by the repository timer for checking
      * if index should be flushed.
      */
     private final Timer.Task flushTask;
@@ -275,7 +270,7 @@ public class MultiIndex {
         this.indexingQueue = new IndexingQueue(store);
 
         // open persistent indexes
-        for (Iterator it = indexNames.iterator(); it.hasNext(); ) {
+        for (Iterator<?> it = indexNames.iterator(); it.hasNext(); ) {
             IndexInfo info = (IndexInfo) it.next();
             String name = info.getName();
             // only open if it still exists
@@ -804,7 +799,6 @@ public class MultiIndex {
         synchronized (this) {
             // stop timer
             flushTask.cancel();
-            flushTimer.cancel();
 
             // commit / close indexes
             try {
@@ -1082,7 +1076,7 @@ public class MultiIndex {
 
     private void scheduleFlushTask() {
         lastFlushTime = System.currentTimeMillis();
-        flushTimer.schedule(flushTask, 0, 1000);
+        handler.getContext().getTimer().schedule(flushTask, 0, 1000);
     }
 
     /**



Mime
View raw message