manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1539604 - in /manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager: FileLockObjectFactory.java LockManager.java LockObjectFactory.java LockPool.java
Date Thu, 07 Nov 2013 12:02:26 GMT
Author: kwright
Date: Thu Nov  7 12:02:25 2013
New Revision: 1539604

URL: http://svn.apache.org/r1539604
Log:
Abstract from how lock objects are created, indirect via factory.

Added:
    manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/FileLockObjectFactory.java
  (with props)
    manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockObjectFactory.java
  (with props)
Modified:
    manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockManager.java
    manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockPool.java

Added: manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/FileLockObjectFactory.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/FileLockObjectFactory.java?rev=1539604&view=auto
==============================================================================
--- manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/FileLockObjectFactory.java
(added)
+++ manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/FileLockObjectFactory.java
Thu Nov  7 12:02:25 2013
@@ -0,0 +1,45 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.manifoldcf.core.lockmanager;
+
+import org.apache.manifoldcf.core.interfaces.*;
+import org.apache.manifoldcf.core.system.ManifoldCF;
+import org.apache.manifoldcf.core.system.Logging;
+import java.io.*;
+
+/** Base factory for file lock objects.
+*/
+public class FileLockObjectFactory extends LockObjectFactory
+{
+  public static final String _rcsid = "@(#)$Id$";
+
+  protected final File synchDir;
+  
+  public FileLockObjectFactory(File synchDir)
+  {
+    this.synchDir = synchDir;
+  }
+  
+  @Override
+  public LockObject newLockObject(LockPool lockPool, Object lockKey)
+  {
+    return new FileLockObject(lockPool, lockKey, synchDir);
+  }
+}
+

Propchange: manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/FileLockObjectFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/FileLockObjectFactory.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockManager.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockManager.java?rev=1539604&r1=1539603&r2=1539604&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockManager.java
(original)
+++ manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockManager.java
Thu Nov  7 12:02:25 2013
@@ -40,12 +40,13 @@ public class LockManager implements ILoc
   protected final static int TYPE_WRITE = 3;
 
   // These are for locks (which cross JVM boundaries)
-  protected HashMap localLocks = new HashMap();
-  protected static LockPool myLocks = new LockPool();
+  protected final HashMap localLocks = new HashMap();
+  protected final static Integer lockPoolInitialization = new Integer(0);
+  protected static LockPool myLocks = null;
 
   // These are for critical sections (which do not cross JVM boundaries)
-  protected HashMap localSections = new HashMap();
-  protected static LockPool mySections = new LockPool();
+  protected final HashMap localSections = new HashMap();
+  protected final static LockPool mySections = new LockPool(new LockObjectFactory());
 
   // This is the directory used for cross-JVM synchronization, or null if off
   protected File synchDirectory = null;
@@ -53,11 +54,18 @@ public class LockManager implements ILoc
   public LockManager()
     throws ManifoldCFException
   {
-    synchDirectory = ManifoldCF.getFileProperty(synchDirectoryProperty);
-    if (synchDirectory != null)
+    synchronized(lockPoolInitialization)
     {
-      if (!synchDirectory.isDirectory())
-        throw new ManifoldCFException("Property "+synchDirectoryProperty+" must point to
an existing, writeable directory!",ManifoldCFException.SETUP_ERROR);
+      if (myLocks == null)
+      {
+        synchDirectory = ManifoldCF.getFileProperty(synchDirectoryProperty);
+        if (synchDirectory != null)
+        {
+          if (!synchDirectory.isDirectory())
+            throw new ManifoldCFException("Property "+synchDirectoryProperty+" must point
to an existing, writeable directory!",ManifoldCFException.SETUP_ERROR);
+        }
+        myLocks = new LockPool(new FileLockObjectFactory(synchDirectory));
+      }
     }
   }
 
@@ -334,7 +342,7 @@ public class LockManager implements ILoc
     // to know if we already have a a read lock.
     while (true)
     {
-      LockObject lo = myLocks.getObject(lockKey,synchDirectory);
+      LockObject lo = myLocks.getObject(lockKey);
       try
       {
         lo.enterNonExWriteLock();
@@ -384,7 +392,7 @@ public class LockManager implements ILoc
     // to know if we already have a a read lock.
     while (true)
     {
-      LockObject lo = myLocks.getObject(lockKey,synchDirectory);
+      LockObject lo = myLocks.getObject(lockKey);
       try
       {
         synchronized (lo)
@@ -438,7 +446,7 @@ public class LockManager implements ILoc
     {
       while (true)
       {
-        LockObject lo = myLocks.getObject(lockKey,synchDirectory);
+        LockObject lo = myLocks.getObject(lockKey);
         try
         {
           lo.leaveNonExWriteLock();
@@ -507,7 +515,7 @@ public class LockManager implements ILoc
     // it's illegal.
     while (true)
     {
-      LockObject lo = myLocks.getObject(lockKey,synchDirectory);
+      LockObject lo = myLocks.getObject(lockKey);
       try
       {
         lo.enterWriteLock();
@@ -557,7 +565,7 @@ public class LockManager implements ILoc
     // it's illegal.
     while (true)
     {
-      LockObject lo = myLocks.getObject(lockKey,synchDirectory);
+      LockObject lo = myLocks.getObject(lockKey);
       try
       {
         synchronized (lo)
@@ -606,7 +614,7 @@ public class LockManager implements ILoc
     {
       while (true)
       {
-        LockObject lo = myLocks.getObject(lockKey,synchDirectory);
+        LockObject lo = myLocks.getObject(lockKey);
         try
         {
           lo.leaveWriteLock();
@@ -667,7 +675,7 @@ public class LockManager implements ILoc
     // We don't own a local read lock.  Get one.
     while (true)
     {
-      LockObject lo = myLocks.getObject(lockKey,synchDirectory);
+      LockObject lo = myLocks.getObject(lockKey);
       try
       {
         lo.enterReadLock();
@@ -709,7 +717,7 @@ public class LockManager implements ILoc
     // We don't own a local read lock.  Get one.
     while (true)
     {
-      LockObject lo = myLocks.getObject(lockKey,synchDirectory);
+      LockObject lo = myLocks.getObject(lockKey);
       try
       {
         synchronized (lo)
@@ -758,7 +766,7 @@ public class LockManager implements ILoc
     {
       while (true)
       {
-        LockObject lo = myLocks.getObject(lockKey,synchDirectory);
+        LockObject lo = myLocks.getObject(lockKey);
         try
         {
           lo.leaveReadLock();
@@ -881,7 +889,7 @@ public class LockManager implements ILoc
             // We don't own a local write lock.  Get one.
             while (true)
             {
-              LockObject lo = myLocks.getObject(lockKey,synchDirectory);
+              LockObject lo = myLocks.getObject(lockKey);
               try
               {
                 lo.enterWriteLock();
@@ -909,7 +917,7 @@ public class LockManager implements ILoc
             // We don't own a local write lock.  Get one.
             while (true)
             {
-              LockObject lo = myLocks.getObject(lockKey,synchDirectory);
+              LockObject lo = myLocks.getObject(lockKey);
               try
               {
                 lo.enterNonExWriteLock();
@@ -930,7 +938,7 @@ public class LockManager implements ILoc
             // We don't own a local read lock.  Get one.
             while (true)
             {
-              LockObject lo = myLocks.getObject(lockKey,synchDirectory);
+              LockObject lo = myLocks.getObject(lockKey);
               try
               {
                 lo.enterReadLock();
@@ -1067,7 +1075,7 @@ public class LockManager implements ILoc
             // We don't own a local write lock.  Get one.
             while (true)
             {
-              LockObject lo = myLocks.getObject(lockKey,synchDirectory);
+              LockObject lo = myLocks.getObject(lockKey);
               synchronized (lo)
               {
                 try
@@ -1098,7 +1106,7 @@ public class LockManager implements ILoc
             // We don't own a local write lock.  Get one.
             while (true)
             {
-              LockObject lo = myLocks.getObject(lockKey,synchDirectory);
+              LockObject lo = myLocks.getObject(lockKey);
               synchronized (lo)
               {
                 try
@@ -1122,7 +1130,7 @@ public class LockManager implements ILoc
             // We don't own a local read lock.  Get one.
             while (true)
             {
-              LockObject lo = myLocks.getObject(lockKey,synchDirectory);
+              LockObject lo = myLocks.getObject(lockKey);
               synchronized (lo)
               {
                 try
@@ -1268,7 +1276,7 @@ public class LockManager implements ILoc
     // We don't own a local read lock.  Get one.
     while (true)
     {
-      LockObject lo = mySections.getObject(sectionKey,null);
+      LockObject lo = mySections.getObject(sectionKey);
       try
       {
         lo.enterReadLock();
@@ -1301,7 +1309,7 @@ public class LockManager implements ILoc
     {
       while (true)
       {
-        LockObject lo = mySections.getObject(sectionKey,null);
+        LockObject lo = mySections.getObject(sectionKey);
         try
         {
           lo.leaveReadLock();
@@ -1365,7 +1373,7 @@ public class LockManager implements ILoc
     // to know if we already have a a read lock.
     while (true)
     {
-      LockObject lo = mySections.getObject(sectionKey,null);
+      LockObject lo = mySections.getObject(sectionKey);
       try
       {
         lo.enterNonExWriteLock();
@@ -1401,7 +1409,7 @@ public class LockManager implements ILoc
     {
       while (true)
       {
-        LockObject lo = mySections.getObject(sectionKey,null);
+        LockObject lo = mySections.getObject(sectionKey);
         try
         {
           lo.leaveNonExWriteLock();
@@ -1465,7 +1473,7 @@ public class LockManager implements ILoc
     // it's illegal.
     while (true)
     {
-      LockObject lo = mySections.getObject(sectionKey,null);
+      LockObject lo = mySections.getObject(sectionKey);
       try
       {
         lo.enterWriteLock();
@@ -1499,7 +1507,7 @@ public class LockManager implements ILoc
     {
       while (true)
       {
-        LockObject lo = mySections.getObject(sectionKey,null);
+        LockObject lo = mySections.getObject(sectionKey);
         try
         {
           lo.leaveWriteLock();
@@ -1570,7 +1578,7 @@ public class LockManager implements ILoc
             // We don't own a local write lock.  Get one.
             while (true)
             {
-              LockObject lo = mySections.getObject(lockKey,null);
+              LockObject lo = mySections.getObject(lockKey);
               try
               {
                 lo.enterWriteLock();
@@ -1598,7 +1606,7 @@ public class LockManager implements ILoc
             // We don't own a local write lock.  Get one.
             while (true)
             {
-              LockObject lo = mySections.getObject(lockKey,null);
+              LockObject lo = mySections.getObject(lockKey);
               try
               {
                 lo.enterNonExWriteLock();
@@ -1619,7 +1627,7 @@ public class LockManager implements ILoc
             // We don't own a local read lock.  Get one.
             while (true)
             {
-              LockObject lo = mySections.getObject(lockKey,null);
+              LockObject lo = mySections.getObject(lockKey);
               try
               {
                 lo.enterReadLock();

Added: manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockObjectFactory.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockObjectFactory.java?rev=1539604&view=auto
==============================================================================
--- manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockObjectFactory.java
(added)
+++ manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockObjectFactory.java
Thu Nov  7 12:02:25 2013
@@ -0,0 +1,42 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.manifoldcf.core.lockmanager;
+
+import org.apache.manifoldcf.core.interfaces.*;
+import org.apache.manifoldcf.core.system.ManifoldCF;
+import org.apache.manifoldcf.core.system.Logging;
+import java.io.*;
+
+/** Base factory for lock objects.  This will be extended to
+* support different kinds of lock objects.
+*/
+public class LockObjectFactory
+{
+  public static final String _rcsid = "@(#)$Id$";
+
+  public LockObjectFactory()
+  {
+  }
+  
+  public LockObject newLockObject(LockPool lockPool, Object lockKey)
+  {
+    return new LockObject(lockPool, lockKey);
+  }
+}
+

Propchange: manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockObjectFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockObjectFactory.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockPool.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockPool.java?rev=1539604&r1=1539603&r2=1539604&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockPool.java
(original)
+++ manifoldcf/branches/CONNECTORS-13/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/LockPool.java
Thu Nov  7 12:02:25 2013
@@ -21,18 +21,29 @@ package org.apache.manifoldcf.core.lockm
 import java.util.*;
 import java.io.*;
 
+/** Base class of all lock pools.  A lock pool is a global set of lock objects looked up
by
+* a key.  Lock object instantiation differs for different kinds of lock objects, so this
+* base class is expected to be extended accordingly.
+*/
 public class LockPool
 {
   public static final String _rcsid = "@(#)$Id: LockPool.java 988245 2010-08-23 18:39:35Z
kwright $";
 
-  private HashMap myLocks = new HashMap();
+  protected final Map<Object,LockObject> myLocks = new HashMap<Object,LockObject>();
 
-  public synchronized LockObject getObject(Object lockKey, File synchDir)
+  protected final LockObjectFactory factory;
+  
+  public LockPool(LockObjectFactory factory)
   {
-    LockObject lo = (LockObject)myLocks.get(lockKey);
+    this.factory = factory;
+  }
+  
+  public synchronized LockObject getObject(Object lockKey)
+  {
+    LockObject lo = myLocks.get(lockKey);
     if (lo == null)
     {
-      lo = new FileLockObject(this,lockKey,synchDir);
+      lo = factory.newLockObject(this,lockKey);
       myLocks.put(lockKey,lo);
     }
     return lo;



Mime
View raw message