geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r397921 - in /geronimo/sandbox/jcache-spec/src/java/javax/cache: Cache.java CacheEntry.java CacheException.java CacheManager.java
Date Fri, 28 Apr 2006 15:23:24 GMT
Author: jstrachan
Date: Fri Apr 28 08:23:23 2006
New Revision: 397921

URL: http://svn.apache.org/viewcvs?rev=397921&view=rev
Log:
Fixed a few typeos, removed some redundant methods inherited from Map and added a couple of
missing methods from the publically available javadoc

Modified:
    geronimo/sandbox/jcache-spec/src/java/javax/cache/Cache.java
    geronimo/sandbox/jcache-spec/src/java/javax/cache/CacheEntry.java
    geronimo/sandbox/jcache-spec/src/java/javax/cache/CacheException.java
    geronimo/sandbox/jcache-spec/src/java/javax/cache/CacheManager.java

Modified: geronimo/sandbox/jcache-spec/src/java/javax/cache/Cache.java
URL: http://svn.apache.org/viewcvs/geronimo/sandbox/jcache-spec/src/java/javax/cache/Cache.java?rev=397921&r1=397920&r2=397921&view=diff
==============================================================================
--- geronimo/sandbox/jcache-spec/src/java/javax/cache/Cache.java (original)
+++ geronimo/sandbox/jcache-spec/src/java/javax/cache/Cache.java Fri Apr 28 08:23:23 2006
@@ -19,54 +19,30 @@
 
 import java.util.Collection;
 import java.util.Map;
-import java.util.Set;
 
 /**
+ * For more documentation on JCache see the 
+ * <a href="https://jsr-107-interest.dev.java.net/">JSR 107 project</a>
+ * 
  * @version $Rev$ $Date$
  */
 public interface Cache extends Map
 {
     public void addListener( CacheListener listender );
 
-    public void clear();
-
-    public boolean containsKey( Object key );
-
-    public boolean containsValue( Object value );
-
-    public Set entrySet();
-
-    public boolean equals( Object obj);
-
-    public Object get( Object obj );
-
+    public void evict();
+    
     public Map getAll( Collection keys );
 
     public CacheEntry getCacheEntry( Object key );
 
     public CacheStatistics getCacheStatistics();
 
-    public int hashCode();
-
-    public boolean isEmpty();
-
-    public Set keySet();
-
     public void load( Object obj );
 
     public void loadAll( Collection keys );
 
     public Object peek( Object key );
 
-    public Object put( Object key, Object value );
-
-    public void putAll( Map m );
-
-    public Object remove( Object key );
-
     public void removeListener( CacheListener listener );
-
-    public int size();
-
-    public Collection values();
 }

Modified: geronimo/sandbox/jcache-spec/src/java/javax/cache/CacheEntry.java
URL: http://svn.apache.org/viewcvs/geronimo/sandbox/jcache-spec/src/java/javax/cache/CacheEntry.java?rev=397921&r1=397920&r2=397921&view=diff
==============================================================================
--- geronimo/sandbox/jcache-spec/src/java/javax/cache/CacheEntry.java (original)
+++ geronimo/sandbox/jcache-spec/src/java/javax/cache/CacheEntry.java Fri Apr 28 08:23:23
2006
@@ -34,7 +34,7 @@
 
     public long getLastAccessTime();
 
-    public long getLastUpdate();
+    public long getLastUpdateTime();
 
     public long getVersion();
 

Modified: geronimo/sandbox/jcache-spec/src/java/javax/cache/CacheException.java
URL: http://svn.apache.org/viewcvs/geronimo/sandbox/jcache-spec/src/java/javax/cache/CacheException.java?rev=397921&r1=397920&r2=397921&view=diff
==============================================================================
--- geronimo/sandbox/jcache-spec/src/java/javax/cache/CacheException.java (original)
+++ geronimo/sandbox/jcache-spec/src/java/javax/cache/CacheException.java Fri Apr 28 08:23:23
2006
@@ -22,23 +22,20 @@
 /**
  * @version $Rev$ $Date$
  */
-public class CacheException extends Exception implements Serializable
-{
-    public String detailMessage;
-
-    public Throwable cause;
-
-    public CacheException()
-    {}
-
-    public CacheException( String message )
-    {
-        detailMessage = message;
+public class CacheException extends Exception implements Serializable {
+
+    public CacheException() {
+        super();
+
+    }
+
+    public CacheException(String message, Throwable cause) {
+        super(message, cause);
+
     }
 
-    public  CacheException( String message, Throwable t )
-    {
-        detailMessage = message;
-        cause = t;
+    public CacheException(String message) {
+        super(message);
+
     }
 }

Modified: geronimo/sandbox/jcache-spec/src/java/javax/cache/CacheManager.java
URL: http://svn.apache.org/viewcvs/geronimo/sandbox/jcache-spec/src/java/javax/cache/CacheManager.java?rev=397921&r1=397920&r2=397921&view=diff
==============================================================================
--- geronimo/sandbox/jcache-spec/src/java/javax/cache/CacheManager.java (original)
+++ geronimo/sandbox/jcache-spec/src/java/javax/cache/CacheManager.java Fri Apr 28 08:23:23
2006
@@ -17,9 +17,99 @@
 
 package javax.cache;
 
-public class CacheManager
-{
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+public class CacheManager {
     protected static CacheManager instance = new CacheManager();
+    private final Map caches = Collections.synchronizedMap(new HashMap());
+
+    public static CacheManager getInstance() {
+        return instance;
+    }
+
+    public Cache getCache(String cacheName) {
+        return (Cache) caches.get(cacheName);
+    }
+
+    public void registerCache(String cacheName, Cache cache) {
+        caches.put(cacheName, cache);
+    }
+
+    public CacheFactory getCacheFactory() throws CacheException {
+        String name = getImplementationClassName(CacheFactory.class.getName());
+        if (name == null) {
+            throw new CacheException("No implementation of JCache can be found on the classpath");
+        }
+        Class type = null;
+        try {
+            type = Thread.currentThread().getContextClassLoader().loadClass(name);
+        }
+        catch (ClassNotFoundException e) {
+            try {
+                type = getClass().getClassLoader().loadClass(name);
+            }
+            catch (ClassNotFoundException e1) {
+                throw new CacheException("Could not find class name: " + name);
+            }
+        }
+        try {
+            return (CacheFactory) type.newInstance();
+        }
+        catch (Exception e) {
+            throw new CacheException("Could not instantiate instance of: " + name + ". Reason:
" + e, e);
+        }
+    }
+
+    protected String getImplementationClassName(String interfaceType) {
+        try {
+            String name = System.getProperty(interfaceType);
+            if (name != null && name.length() > 0)
+                return name;
+        }
+        catch (SecurityException e) {
+            // ignore security exceptions disallowing us from accessing 
+            // system properties
+        }
+
+        // lets try META-INF/services
+        try {
+            InputStream in = getResourceAsStream("META-INF/services/" + interfaceType);
+            if (in != null) {
+                BufferedReader r = new BufferedReader(new InputStreamReader(in));
+                try {
+                    String line = r.readLine();
+                    if (line != null) {
+                        line = line.trim();
+                        if (line.length() > 0) {
+                            return line;
+                        }
+                    }
+                }
+                finally {
+                    r.close();
+                }
+            }
+        }
+        catch (IOException e) {
+            // ignore errors reading the file
+        }
+        return null;
+    }
 
-    
+    protected InputStream getResourceAsStream(String name) {
+        InputStream answer = Thread.currentThread().getContextClassLoader().getResourceAsStream(name);
+        if (answer == null) {
+            answer = getClass().getClassLoader().getResourceAsStream(name);
+        }
+        return answer;
+    }
 }



Mime
View raw message