jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r771693 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data: DataStore.java FileDataStore.java GarbageCollector.java db/DbDataStore.java db/Pool.java
Date Tue, 05 May 2009 12:26:54 GMT
Author: thomasm
Date: Tue May  5 12:26:35 2009
New Revision: 771693

URL: http://svn.apache.org/viewvc?rev=771693&view=rev
Log:
JCR-2087 Upgrade to Java 5 as the base platform

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataStore.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/Pool.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataStore.java?rev=771693&r1=771692&r2=771693&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataStore.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataStore.java
Tue May  5 12:26:35 2009
@@ -106,7 +106,7 @@
      * @return an iterator over all DataIdentifier objects
      * @throws DataStoreException if the list could not be read
      */
-    Iterator getAllIdentifiers() throws DataStoreException;
+    Iterator<DataIdentifier> getAllIdentifiers() throws DataStoreException;
 
     /**
      * Initialized the data store

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java?rev=771693&r1=771692&r2=771693&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java
Tue May  5 12:26:35 2009
@@ -104,7 +104,8 @@
     /**
      * All data identifiers that are currently in use are in this set until they are garbage
collected.
      */
-    protected Map inUse = Collections.synchronizedMap(new WeakHashMap());
+    protected Map<DataIdentifier, WeakReference<DataIdentifier>> inUse = 
+        Collections.synchronizedMap(new WeakHashMap<DataIdentifier, WeakReference<DataIdentifier>>());
 
     /**
      * Creates a uninitialized data store.
@@ -165,7 +166,7 @@
     }
 
     private void usesIdentifier(DataIdentifier identifier) {
-        inUse.put(identifier, new WeakReference(identifier));
+        inUse.put(identifier, new WeakReference<DataIdentifier>(identifier));
     }
 
     /**
@@ -308,10 +309,10 @@
                 }
             }
         } else if (file.isDirectory()) {
-            File[] list = file.listFiles();
-            for (int i = 0; i < list.length; i++) {
-                count += deleteOlderRecursive(list[i], min);
+            for (File f: file.listFiles()) {
+                count += deleteOlderRecursive(f, min);
             }
+            
             // JCR-1396: FileDataStore Garbage Collector and empty directories
             // Automatic removal of empty directories (but not the root!)
             synchronized (this) {
@@ -323,14 +324,15 @@
         return count;
     }
 
-    private void listRecursive(List list, File file) {
-        File[] l = file.listFiles();
-        for (int i = 0; l != null && i < l.length; i++) {
-            File f = l[i];
-            if (f.isDirectory()) {
-                listRecursive(list, f);
-            } else {
-                list.add(f);
+    private void listRecursive(List<File> list, File file) {
+        File[] files = file.listFiles();
+        if (files != null) {
+            for (File f : files) {
+                if (f.isDirectory()) {
+                    listRecursive(list, f);
+                } else {
+                    list.add(f);
+                }
             }
         }
     }
@@ -338,12 +340,11 @@
     /**
      * {@inheritDoc}
      */
-    public Iterator getAllIdentifiers() {
-        ArrayList files = new ArrayList();
+    public Iterator<DataIdentifier> getAllIdentifiers() {
+        ArrayList<File> files = new ArrayList<File>();
         listRecursive(files, directory);
-        ArrayList identifiers = new ArrayList();
-        for (int i = 0; i < files.size(); i++) {
-            File f = (File) files.get(i);
+        ArrayList<DataIdentifier> identifiers = new ArrayList<DataIdentifier>();
+        for (File f: files) {
             String name = f.getName();
             if (!name.startsWith(TMP)) {
                 DataIdentifier id = new DataIdentifier(name);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java?rev=771693&r1=771692&r2=771693&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/GarbageCollector.java
Tue May  5 12:26:35 2009
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.core.data;
 
 import org.apache.jackrabbit.core.NodeId;
+import org.apache.jackrabbit.core.NodeIdIterator;
 import org.apache.jackrabbit.core.PropertyId;
 import org.apache.jackrabbit.core.RepositoryImpl;
 import org.apache.jackrabbit.core.SessionImpl;
@@ -78,7 +79,7 @@
 
     private long startScanTimestamp;
 
-    private final ArrayList listeners = new ArrayList();
+    private final ArrayList<Listener> listeners = new ArrayList<Listener>();
 
     private final IterablePersistenceManager[] pmList;
 
@@ -157,8 +158,8 @@
         }
 
         if (pmList == null || !persistenceManagerScan) {
-            for (int i = 0; i < sessionList.length; i++) {
-                scanNodes(sessionList[i]);
+            for (Session s : sessionList) {
+                scanNodes(s);
             }
         } else {
             scanPersistenceManagers();
@@ -199,11 +200,10 @@
     }
 
     private void scanPersistenceManagers() throws ItemStateException, RepositoryException
{
-        for (int i = 0; i < pmList.length; i++) {
-            IterablePersistenceManager pm = pmList[i];
-            Iterator it = pm.getAllNodeIds(null, 0);
+        for (IterablePersistenceManager pm : pmList) {
+            NodeIdIterator it = pm.getAllNodeIds(null, 0);
             while (it.hasNext()) {
-                NodeId id = (NodeId) it.next();
+                NodeId id = it.nextNodeId();
                 if (callback != null) {
                     callback.beforeScanning(null);
                 }
@@ -216,9 +216,8 @@
                         PropertyId pid = new PropertyId(id, name);
                         PropertyState ps = pm.load(pid);
                         if (ps.getType() == PropertyType.BINARY) {
-                            InternalValue[] values = ps.getValues();
-                            for (int j = 0; j < values.length; j++) {
-                                values[j].getBLOBFileValue().getLength();
+                            for (InternalValue v : ps.getValues()) {
+                                v.getBLOBFileValue().getLength();
                             }
                         }
                     }
@@ -235,8 +234,7 @@
 
     public void stopScan() throws RepositoryException {
         checkScanStarted();
-        for (int i = 0; i < listeners.size(); i++) {
-            Listener listener = (Listener) listeners.get(i);
+        for (Listener listener : listeners) {
             try {
                 listener.stop();
             } catch (Exception e) {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java?rev=771693&r1=771692&r2=771693&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java
Tue May  5 12:26:35 2009
@@ -282,12 +282,13 @@
     /**
      * All data identifiers that are currently in use are in this set until they are garbage
collected.
      */
-    protected Map inUse = Collections.synchronizedMap(new WeakHashMap());
+    protected Map<DataIdentifier, WeakReference<DataIdentifier>> inUse = 
+        Collections.synchronizedMap(new WeakHashMap<DataIdentifier, WeakReference<DataIdentifier>>());
     
     /**
      * The temporary identifiers that are currently in use.
      */
-    protected List temporaryInUse = Collections.synchronizedList(new ArrayList());
+    protected List<String> temporaryInUse = Collections.synchronizedList(new ArrayList<String>());
 
     /**
      * {@inheritDoc}
@@ -418,17 +419,15 @@
     public synchronized int deleteAllOlderThan(long min) throws DataStoreException {
         ConnectionRecoveryManager conn = getConnection();
         try {
-            ArrayList touch = new ArrayList();
-            for (Iterator it = new ArrayList(inUse.keySet()).iterator(); it.hasNext();) {
-                DataIdentifier identifier = (DataIdentifier) it.next();
+            ArrayList<String> touch = new ArrayList<String>();
+            ArrayList<DataIdentifier> ids = new ArrayList<DataIdentifier>(inUse.keySet());
+            for (DataIdentifier identifier: ids) {
                 if (identifier != null) {
                     touch.add(identifier.toString());
                 }
             }
             touch.addAll(temporaryInUse);
-            Iterator it = touch.iterator();
-            while (it.hasNext()) {
-                String key = (String) it.next();
+            for (String key : touch) {
                 updateLastModifiedDate(key, 0);
             }
             // DELETE FROM DATASTORE WHERE LAST_MODIFIED<?
@@ -444,9 +443,9 @@
     /**
      * {@inheritDoc}
      */
-    public Iterator getAllIdentifiers() throws DataStoreException {
+    public Iterator<DataIdentifier> getAllIdentifiers() throws DataStoreException {
         ConnectionRecoveryManager conn = getConnection();
-        ArrayList list = new ArrayList();
+        ArrayList<DataIdentifier> list = new ArrayList<DataIdentifier>();
         ResultSet rs = null;
         try {
             // SELECT ID FROM DATASTORE
@@ -830,16 +829,15 @@
      * {@inheritDoc}
      */
     public synchronized void close() {
-        ArrayList list = connectionPool.getAll();
-        for (int i = 0; i < list.size(); i++) {
-            ConnectionRecoveryManager conn = (ConnectionRecoveryManager) list.get(i);
+        ArrayList<ConnectionRecoveryManager> list = connectionPool.getAll();
+        for (ConnectionRecoveryManager conn : list) {
             conn.close();
         }
         list.clear();
     }
 
     protected void usesIdentifier(DataIdentifier identifier) {
-        inUse.put(identifier, new WeakReference(identifier));
+        inUse.put(identifier, new WeakReference<DataIdentifier>(identifier));
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/Pool.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/Pool.java?rev=771693&r1=771692&r2=771693&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/Pool.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/Pool.java
Tue May  5 12:26:35 2009
@@ -17,10 +17,11 @@
 package org.apache.jackrabbit.core.data.db;
 
 import java.util.ArrayList;
+import java.util.concurrent.LinkedBlockingQueue;
 
 import javax.jcr.RepositoryException;
 
-import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
+import org.apache.jackrabbit.core.persistence.bundle.util.ConnectionRecoveryManager;
 
 /**
  * Implementation of a simple ConnectionRecoveryManager pool.
@@ -29,9 +30,9 @@
  */
 public class Pool {
     protected final int maxSize;
-    protected final ArrayList all = new ArrayList();
+    protected final ArrayList<ConnectionRecoveryManager> all = new ArrayList<ConnectionRecoveryManager>();
     protected final DbDataStore factory;
-    protected final LinkedQueue pool = new LinkedQueue();
+    protected final LinkedBlockingQueue<ConnectionRecoveryManager> pool = new LinkedBlockingQueue<ConnectionRecoveryManager>();
 
     /**
      * Create a new pool using the given factory and maximum pool size.
@@ -51,8 +52,8 @@
      *
      * @return the connection
      */
-    protected Object get() throws InterruptedException, RepositoryException {
-        Object o = pool.poll(0);
+    protected ConnectionRecoveryManager get() throws InterruptedException, RepositoryException
{
+        ConnectionRecoveryManager o = pool.poll();
         if (o == null) {
             synchronized (all) {
                 if (all.size() < maxSize) {
@@ -72,7 +73,7 @@
      *
      * @param o the connection
      */
-    protected void add(Object o) throws InterruptedException {
+    protected void add(ConnectionRecoveryManager o) throws InterruptedException {
         pool.put(o);
     }
 
@@ -81,7 +82,7 @@
      *
      * @return all connections
      */
-    protected ArrayList getAll() {
+    protected ArrayList<ConnectionRecoveryManager> getAll() {
         return all;
     }
 }



Mime
View raw message