abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r782732 - in /abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client: AbderaClient.java cache/CacheFactory.java cache/LRUCache.java cache/LRUCacheFactory.java
Date Mon, 08 Jun 2009 19:19:27 GMT
Author: jmsnell
Date: Mon Jun  8 19:19:27 2009
New Revision: 782732

URL: http://svn.apache.org/viewvc?rev=782732&view=rev
Log:
Don't use the discovery mechanism for cache impls. for now, this means the AbderaClient is
hard coded to use the LRUCache in-memory cache implementation. The original design meant for
the cache implementation to be pluggable. Ideally, however, the HttpClient would incorporate
some kind of cache so we wouldn't have to do this at all. I'm wondering if there's some way
we could separate all the http client related stuff out to a distinct subproject?

Modified:
    abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java
    abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/CacheFactory.java
    abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/LRUCache.java
    abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/LRUCacheFactory.java

Modified: abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java?rev=782732&r1=782731&r2=782732&view=diff
==============================================================================
--- abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java
(original)
+++ abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java
Mon Jun  8 19:19:27 2009
@@ -39,7 +39,6 @@
 import org.apache.abdera.protocol.client.cache.CacheFactory;
 import org.apache.abdera.protocol.client.cache.CachedResponse;
 import org.apache.abdera.protocol.client.cache.LRUCache;
-import org.apache.abdera.protocol.client.cache.LRUCacheFactory;
 import org.apache.abdera.protocol.client.cache.Cache.Disposition;
 import org.apache.abdera.protocol.client.util.BaseRequestEntity;
 import org.apache.abdera.protocol.client.util.EntityProviderRequestEntity;
@@ -49,7 +48,6 @@
 import org.apache.abdera.protocol.error.Error;
 import org.apache.abdera.protocol.error.ProtocolException;
 import org.apache.abdera.protocol.util.CacheControlUtil;
-import org.apache.abdera.util.Discover;
 import org.apache.abdera.util.EntityTag;
 import org.apache.abdera.util.Version;
 import org.apache.commons.httpclient.Cookie;
@@ -74,7 +72,7 @@
 /**
  * An Atom Publishing Protocol client.
  */
-@SuppressWarnings("unchecked") 
+@SuppressWarnings({ "unchecked", "deprecation" }) 
 public class AbderaClient {
 
   public static final String DEFAULT_USER_AGENT = 
@@ -97,27 +95,41 @@
   public AbderaClient(String useragent) {
     this(new Abdera(), useragent);
   }
+
+  /**
+   * Create an AbderaClient instance using the specified Abdera instance and useragent name
+   * @param abdera
+   * @param useragent
+   */
+  public AbderaClient(
+    Abdera abdera, 
+    String useragent) {
+      this(abdera,useragent,initCache(abdera));
+  }
   
   /**
    * Create an AbderaClient instance using the specified Abdera instance and useragent name
    * @param abdera
    * @param useragent
    */
-  public AbderaClient(Abdera abdera, String useragent) {
-    this.abdera = abdera;
-    this.cache = initCache(initCacheFactory());
-    MultiThreadedHttpConnectionManager connManager = 
-      new MultiThreadedHttpConnectionManager();
-    client = new HttpClient(connManager);
-    client.getParams().setParameter(
-      HttpClientParams.USER_AGENT, 
-      useragent);
-    client.getParams().setBooleanParameter(
-      HttpClientParams.USE_EXPECT_CONTINUE, true);  
-    client.getParams().setCookiePolicy(
-      CookiePolicy.BROWSER_COMPATIBILITY);
-    setAuthenticationSchemeDefaults();
-    setMaximumRedirects(DEFAULT_MAX_REDIRECTS);
+  public AbderaClient(
+    Abdera abdera, 
+    String useragent,
+    Cache cache) {
+      this.abdera = abdera;
+      this.cache = cache;
+      MultiThreadedHttpConnectionManager connManager = 
+        new MultiThreadedHttpConnectionManager();
+      client = new HttpClient(connManager);
+      client.getParams().setParameter(
+        HttpClientParams.USER_AGENT, 
+        useragent);
+      client.getParams().setBooleanParameter(
+        HttpClientParams.USE_EXPECT_CONTINUE, true);  
+      client.getParams().setCookiePolicy(
+        CookiePolicy.BROWSER_COMPATIBILITY);
+      setAuthenticationSchemeDefaults();
+      setMaximumRedirects(DEFAULT_MAX_REDIRECTS);
   }
 
   /**
@@ -137,8 +149,20 @@
   public AbderaClient(
     Abdera abdera, 
     HttpClient client) {
+      this(abdera,client,initCache(abdera));
+  }
+  
+  /**
+   * Create an Abdera using a preconfigured HttpClient object
+   * @param abdera
+   * @param client An Apache HttpClient object
+   */
+  public AbderaClient(
+    Abdera abdera, 
+    HttpClient client,
+    Cache cache) {
       this.abdera = abdera;
-      this.cache = initCache(initCacheFactory());
+      this.cache = cache;
       this.client = client;
       setAuthenticationSchemeDefaults();
       setMaximumRedirects(DEFAULT_MAX_REDIRECTS);
@@ -149,18 +173,24 @@
    * @param abdera
    */
   public AbderaClient(Abdera abdera) {
-    this(abdera,DEFAULT_USER_AGENT);
+    this(
+      abdera,
+      DEFAULT_USER_AGENT);
   }
 
-  private CacheFactory initCacheFactory() {
-    CacheFactory cacheFactory = 
-      (CacheFactory)Discover.locate(
-        CacheFactory.class.getName(),
-        LRUCacheFactory.class.getName(), 
-        abdera);
-    return cacheFactory;
+  /**
+   * Create an AbderaClient instance using the specified Abdera instance
+   * @param abdera
+   */
+  public AbderaClient(
+    Abdera abdera, 
+    Cache cache) {
+      this(
+        abdera,
+        DEFAULT_USER_AGENT,
+        cache);
   }
-
+  
   /**
    * Returns the client HTTP cache instance
    */
@@ -169,12 +199,17 @@
   }
   
   /**
-   * Initializes the client HTTP cache
+   * @deprecated The CacheFactory interface is no longer used.
    */
   public Cache initCache(CacheFactory factory) {
-    Cache cache = null;
-    if (factory != null) cache = factory.getCache(abdera);
-    return (cache != null) ? cache : new LRUCache(abdera);
+    return initCache(abdera);
+  }
+  
+  /**
+   * Initializes the client HTTP cache
+   */
+  public static Cache initCache(Abdera abdera) {
+    return new LRUCache(abdera);
   }
   
   /**

Modified: abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/CacheFactory.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/CacheFactory.java?rev=782732&r1=782731&r2=782732&view=diff
==============================================================================
--- abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/CacheFactory.java
(original)
+++ abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/CacheFactory.java
Mon Jun  8 19:19:27 2009
@@ -19,6 +19,9 @@
 
 import org.apache.abdera.Abdera;
 
+/**
+ * @deprecated No longer used
+ */
 public interface CacheFactory {
 
   Cache getCache(Abdera abdera);

Modified: abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/LRUCache.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/LRUCache.java?rev=782732&r1=782731&r2=782732&view=diff
==============================================================================
--- abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/LRUCache.java
(original)
+++ abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/LRUCache.java
Mon Jun  8 19:19:27 2009
@@ -19,7 +19,6 @@
 
 import org.apache.abdera.Abdera;
 
-@SuppressWarnings("serial")
 public class LRUCache
   extends InMemoryCache
   implements Cache {

Modified: abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/LRUCacheFactory.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/LRUCacheFactory.java?rev=782732&r1=782731&r2=782732&view=diff
==============================================================================
--- abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/LRUCacheFactory.java
(original)
+++ abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/LRUCacheFactory.java
Mon Jun  8 19:19:27 2009
@@ -19,6 +19,9 @@
 
 import org.apache.abdera.Abdera;
 
+/**
+ * @deprecated No longer used
+ */
 public class LRUCacheFactory 
   implements CacheFactory {
 



Mime
View raw message