commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1570993 [7/24] - in /commons/proper/jcs/trunk/src: assembly/ changes/ conf/ java/org/apache/commons/jcs/access/ java/org/apache/commons/jcs/access/exception/ java/org/apache/commons/jcs/admin/ java/org/apache/commons/jcs/auxiliary/ java/or...
Date Sun, 23 Feb 2014 10:37:52 GMT
Modified: commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheClient.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheClient.java?rev=1570993&r1=1570992&r2=1570993&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheClient.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheClient.java Sun Feb 23 10:37:48 2014
@@ -1,479 +1,479 @@
-package org.apache.commons.jcs.auxiliary.remote.http.client;
-
-/*
- * 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.
- */
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.Collections;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheDispatcher;
-import org.apache.commons.jcs.auxiliary.remote.http.client.behavior.IRemoteHttpCacheClient;
-import org.apache.commons.jcs.auxiliary.remote.util.RemoteCacheRequestFactory;
-import org.apache.commons.jcs.auxiliary.remote.value.RemoteCacheRequest;
-import org.apache.commons.jcs.auxiliary.remote.value.RemoteCacheResponse;
-import org.apache.commons.jcs.engine.behavior.ICacheElement;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/** This is the service used by the remote http auxiliary cache. */
-public class RemoteHttpCacheClient<K extends Serializable, V extends Serializable>
-    implements IRemoteHttpCacheClient<K, V>
-{
-    /** The Logger. */
-    private final static Log log = LogFactory.getLog( RemoteHttpCacheClient.class );
-
-    /** The internal client. */
-    private IRemoteCacheDispatcher remoteDispatcher;
-
-    /** The remote attributes */
-    private RemoteHttpCacheAttributes remoteHttpCacheAttributes;
-
-    /** Set to true when initialize is called */
-    private boolean initialized = false;
-
-    /** For factory construction. */
-    public RemoteHttpCacheClient()
-    {
-        // does nothing
-    }
-
-    /**
-     * Constructs a client.
-     * <p>
-     * @param attributes
-     */
-    public RemoteHttpCacheClient( RemoteHttpCacheAttributes attributes )
-    {
-        setRemoteHttpCacheAttributes( attributes );
-        initialize( attributes );
-    }
-
-    /**
-     * The provides an extension point. If you want to extend this and use a special dispatcher,
-     * here is the place to do it.
-     * <p>
-     * @param attributes
-     */
-    public void initialize( RemoteHttpCacheAttributes attributes )
-    {
-        setRemoteDispatcher( new RemoteHttpCacheDispatcher( attributes ) );
-
-        if ( log.isInfoEnabled() )
-        {
-            log.info( "Created remote Dispatcher." + getRemoteDispatcher() );
-        }
-        setInitialized( true );
-    }
-
-    /**
-     * Create a request, process, extract the payload.
-     * <p>
-     * @param cacheName
-     * @param key
-     * @return ICacheElement
-     * @throws IOException
-     */
-    public ICacheElement<K, V> get( String cacheName, K key )
-        throws IOException
-    {
-        return get( cacheName, key, 0 );
-    }
-
-    /**
-     * Create a request, process, extract the payload.
-     * <p>
-     * @param cacheName
-     * @param key
-     * @param requesterId
-     * @return ICacheElement
-     * @throws IOException
-     */
-    public ICacheElement<K, V> get( String cacheName, K key, long requesterId )
-        throws IOException
-    {
-        if ( !isInitialized() )
-        {
-            String message = "The Remote Http Client is not initialized.  Cannot process request.";
-            log.warn( message );
-            throw new IOException( message );
-        }
-        RemoteCacheRequest<K, Serializable> remoteHttpCacheRequest =
-            RemoteCacheRequestFactory.createGetRequest( cacheName, key, requesterId );
-
-        RemoteCacheResponse<ICacheElement<K, V>> remoteHttpCacheResponse =
-            getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest );
-
-        if ( log.isDebugEnabled() )
-        {
-            log.debug( "Get [" + key + "] = " + remoteHttpCacheResponse );
-        }
-
-        if ( remoteHttpCacheResponse != null)
-        {
-            return remoteHttpCacheResponse.getPayload();
-        }
-
-        return null;
-    }
-
-    /**
-     * Gets multiple items from the cache matching the pattern.
-     * <p>
-     * @param cacheName
-     * @param pattern
-     * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no
-     *         data in cache matching the pattern.
-     * @throws IOException
-     */
-    public Map<K, ICacheElement<K, V>> getMatching( String cacheName, String pattern )
-        throws IOException
-    {
-        return getMatching( cacheName, pattern, 0 );
-    }
-
-    /**
-     * Gets multiple items from the cache matching the pattern.
-     * <p>
-     * @param cacheName
-     * @param pattern
-     * @param requesterId
-     * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no
-     *         data in cache matching the pattern.
-     * @throws IOException
-     */
-    public Map<K, ICacheElement<K, V>> getMatching( String cacheName, String pattern, long requesterId )
-        throws IOException
-    {
-        if ( !isInitialized() )
-        {
-            String message = "The Remote Http Client is not initialized.  Cannot process request.";
-            log.warn( message );
-            throw new IOException( message );
-        }
-
-        RemoteCacheRequest<K, V> remoteHttpCacheRequest =
-            RemoteCacheRequestFactory.createGetMatchingRequest( cacheName, pattern, requesterId );
-
-        RemoteCacheResponse<Map<K, ICacheElement<K, V>>> remoteHttpCacheResponse =
-            getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest );
-
-        if ( log.isDebugEnabled() )
-        {
-            log.debug( "GetMatching [" + pattern + "] = " + remoteHttpCacheResponse );
-        }
-
-        return remoteHttpCacheResponse.getPayload();
-    }
-
-    /**
-     * Gets multiple items from the cache based on the given set of keys.
-     * <p>
-     * @param cacheName
-     * @param keys
-     * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no
-     *         data in cache for any of these keys
-     * @throws IOException
-     */
-    public Map<K, ICacheElement<K, V>> getMultiple( String cacheName, Set<K> keys )
-        throws IOException
-    {
-        return getMultiple( cacheName, keys, 0 );
-    }
-
-    /**
-     * Gets multiple items from the cache based on the given set of keys.
-     * <p>
-     * @param cacheName
-     * @param keys
-     * @param requesterId
-     * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no
-     *         data in cache for any of these keys
-     * @throws IOException
-     */
-    public Map<K, ICacheElement<K, V>> getMultiple( String cacheName, Set<K> keys, long requesterId )
-        throws IOException
-    {
-        if ( !isInitialized() )
-        {
-            String message = "The Remote Http Client is not initialized.  Cannot process request.";
-            log.warn( message );
-            throw new IOException( message );
-        }
-
-        RemoteCacheRequest<K, V> remoteHttpCacheRequest =
-            RemoteCacheRequestFactory.createGetMultipleRequest( cacheName, keys, requesterId );
-
-        RemoteCacheResponse<Map<K, ICacheElement<K, V>>> remoteHttpCacheResponse =
-            getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest );
-
-        if ( log.isDebugEnabled() )
-        {
-            log.debug( "GetMultiple [" + keys + "] = " + remoteHttpCacheResponse );
-        }
-
-        return remoteHttpCacheResponse.getPayload();
-    }
-
-    /**
-     * Removes the given key from the specified cache.
-     * <p>
-     * @param cacheName
-     * @param key
-     * @throws IOException
-     */
-    public void remove( String cacheName, K key )
-        throws IOException
-    {
-        remove( cacheName, key, 0 );
-    }
-
-    /**
-     * Removes the given key from the specified cache.
-     * <p>
-     * @param cacheName
-     * @param key
-     * @param requesterId
-     * @throws IOException
-     */
-    public void remove( String cacheName, K key, long requesterId )
-        throws IOException
-    {
-        if ( !isInitialized() )
-        {
-            String message = "The Remote Http Client is not initialized.  Cannot process request.";
-            log.warn( message );
-            throw new IOException( message );
-        }
-
-        RemoteCacheRequest<K, V> remoteHttpCacheRequest =
-            RemoteCacheRequestFactory.createRemoveRequest( cacheName, key, requesterId );
-
-        getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest );
-    }
-
-    /**
-     * Remove all keys from the specified cache.
-     * <p>
-     * @param cacheName
-     * @throws IOException
-     */
-    public void removeAll( String cacheName )
-        throws IOException
-    {
-        removeAll( cacheName, 0 );
-    }
-
-    /**
-     * Remove all keys from the sepcified cache.
-     * <p>
-     * @param cacheName
-     * @param requesterId
-     * @throws IOException
-     */
-    public void removeAll( String cacheName, long requesterId )
-        throws IOException
-    {
-        if ( !isInitialized() )
-        {
-            String message = "The Remote Http Client is not initialized.  Cannot process request.";
-            log.warn( message );
-            throw new IOException( message );
-        }
-
-        RemoteCacheRequest<K, V> remoteHttpCacheRequest =
-            RemoteCacheRequestFactory.createRemoveAllRequest( cacheName, requesterId );
-
-        getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest );
-    }
-
-    /**
-     * Puts a cache item to the cache.
-     * <p>
-     * @param item
-     * @throws IOException
-     */
-    public void update( ICacheElement<K, V> item )
-        throws IOException
-    {
-        update( item, 0 );
-    }
-
-    /**
-     * Puts a cache item to the cache.
-     * <p>
-     * @param cacheElement
-     * @param requesterId
-     * @throws IOException
-     */
-    public void update( ICacheElement<K, V> cacheElement, long requesterId )
-        throws IOException
-    {
-        if ( !isInitialized() )
-        {
-            String message = "The Remote Http Client is not initialized.  Cannot process request.";
-            log.warn( message );
-            throw new IOException( message );
-        }
-
-        RemoteCacheRequest<K, V> remoteHttpCacheRequest =
-            RemoteCacheRequestFactory.createUpdateRequest( cacheElement, requesterId );
-
-        getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest );
-    }
-
-    /**
-     * Frees the specified cache.
-     * <p>
-     * @param cacheName
-     * @throws IOException
-     */
-    public void dispose( String cacheName )
-        throws IOException
-    {
-        if ( !isInitialized() )
-        {
-            String message = "The Remote Http Client is not initialized.  Cannot process request.";
-            log.warn( message );
-            throw new IOException( message );
-        }
-
-        RemoteCacheRequest<K, V> remoteHttpCacheRequest =
-            RemoteCacheRequestFactory.createDisposeRequest( cacheName, 0 );
-
-        getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest );
-    }
-
-    /**
-     * Frees the specified cache.
-     * <p>
-     * @throws IOException
-     */
-    public void release()
-        throws IOException
-    {
-        // noop
-    }
-
-    /**
-     * Return the keys in this cache.
-     * <p>
-     * @param cacheName the name of the cache
-     * @see org.apache.commons.jcs.auxiliary.AuxiliaryCache#getKeySet()
-     */
-    public Set<K> getKeySet( String cacheName ) throws IOException
-    {
-        if ( !isInitialized() )
-        {
-            String message = "The Remote Http Client is not initialized.  Cannot process request.";
-            log.warn( message );
-            throw new IOException( message );
-        }
-
-        RemoteCacheRequest<String, String> remoteHttpCacheRequest =
-            RemoteCacheRequestFactory.createGetKeySetRequest(cacheName, 0 );
-
-        RemoteCacheResponse<Set<K>> remoteHttpCacheResponse = getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest );
-
-        if ( remoteHttpCacheResponse != null && remoteHttpCacheResponse.getPayload() != null )
-        {
-            return remoteHttpCacheResponse.getPayload();
-        }
-
-        return Collections.emptySet();
-    }
-
-    /**
-     * Make and alive request.
-     * <p>
-     * @return true if we make a successful alive request.
-     * @throws IOException
-     */
-    public boolean isAlive()
-        throws IOException
-    {
-        if ( !isInitialized() )
-        {
-            String message = "The Remote Http Client is not initialized.  Cannot process request.";
-            log.warn( message );
-            throw new IOException( message );
-        }
-
-        RemoteCacheRequest<K, V> remoteHttpCacheRequest = RemoteCacheRequestFactory.createAliveCheckRequest( 0 );
-        RemoteCacheResponse<String> remoteHttpCacheResponse =
-            getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest );
-
-        if ( remoteHttpCacheResponse != null )
-        {
-            return remoteHttpCacheResponse.isSuccess();
-        }
-
-        return false;
-    }
-
-    /**
-     * @param remoteDispatcher the remoteDispatcher to set
-     */
-    public void setRemoteDispatcher( IRemoteCacheDispatcher remoteDispatcher )
-    {
-        this.remoteDispatcher = remoteDispatcher;
-    }
-
-    /**
-     * @return the remoteDispatcher
-     */
-    public IRemoteCacheDispatcher getRemoteDispatcher()
-    {
-        return remoteDispatcher;
-    }
-
-    /**
-     * @param remoteHttpCacheAttributes the remoteHttpCacheAttributes to set
-     */
-    public void setRemoteHttpCacheAttributes( RemoteHttpCacheAttributes remoteHttpCacheAttributes )
-    {
-        this.remoteHttpCacheAttributes = remoteHttpCacheAttributes;
-    }
-
-    /**
-     * @return the remoteHttpCacheAttributes
-     */
-    public RemoteHttpCacheAttributes getRemoteHttpCacheAttributes()
-    {
-        return remoteHttpCacheAttributes;
-    }
-
-    /**
-     * @param initialized the initialized to set
-     */
-    protected void setInitialized( boolean initialized )
-    {
-        this.initialized = initialized;
-    }
-
-    /**
-     * @return the initialized
-     */
-    protected boolean isInitialized()
-    {
-        return initialized;
-    }
-}
+package org.apache.commons.jcs.auxiliary.remote.http.client;
+
+/*
+ * 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.
+ */
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheDispatcher;
+import org.apache.commons.jcs.auxiliary.remote.http.client.behavior.IRemoteHttpCacheClient;
+import org.apache.commons.jcs.auxiliary.remote.util.RemoteCacheRequestFactory;
+import org.apache.commons.jcs.auxiliary.remote.value.RemoteCacheRequest;
+import org.apache.commons.jcs.auxiliary.remote.value.RemoteCacheResponse;
+import org.apache.commons.jcs.engine.behavior.ICacheElement;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/** This is the service used by the remote http auxiliary cache. */
+public class RemoteHttpCacheClient<K extends Serializable, V extends Serializable>
+    implements IRemoteHttpCacheClient<K, V>
+{
+    /** The Logger. */
+    private final static Log log = LogFactory.getLog( RemoteHttpCacheClient.class );
+
+    /** The internal client. */
+    private IRemoteCacheDispatcher remoteDispatcher;
+
+    /** The remote attributes */
+    private RemoteHttpCacheAttributes remoteHttpCacheAttributes;
+
+    /** Set to true when initialize is called */
+    private boolean initialized = false;
+
+    /** For factory construction. */
+    public RemoteHttpCacheClient()
+    {
+        // does nothing
+    }
+
+    /**
+     * Constructs a client.
+     * <p>
+     * @param attributes
+     */
+    public RemoteHttpCacheClient( RemoteHttpCacheAttributes attributes )
+    {
+        setRemoteHttpCacheAttributes( attributes );
+        initialize( attributes );
+    }
+
+    /**
+     * The provides an extension point. If you want to extend this and use a special dispatcher,
+     * here is the place to do it.
+     * <p>
+     * @param attributes
+     */
+    public void initialize( RemoteHttpCacheAttributes attributes )
+    {
+        setRemoteDispatcher( new RemoteHttpCacheDispatcher( attributes ) );
+
+        if ( log.isInfoEnabled() )
+        {
+            log.info( "Created remote Dispatcher." + getRemoteDispatcher() );
+        }
+        setInitialized( true );
+    }
+
+    /**
+     * Create a request, process, extract the payload.
+     * <p>
+     * @param cacheName
+     * @param key
+     * @return ICacheElement
+     * @throws IOException
+     */
+    public ICacheElement<K, V> get( String cacheName, K key )
+        throws IOException
+    {
+        return get( cacheName, key, 0 );
+    }
+
+    /**
+     * Create a request, process, extract the payload.
+     * <p>
+     * @param cacheName
+     * @param key
+     * @param requesterId
+     * @return ICacheElement
+     * @throws IOException
+     */
+    public ICacheElement<K, V> get( String cacheName, K key, long requesterId )
+        throws IOException
+    {
+        if ( !isInitialized() )
+        {
+            String message = "The Remote Http Client is not initialized.  Cannot process request.";
+            log.warn( message );
+            throw new IOException( message );
+        }
+        RemoteCacheRequest<K, Serializable> remoteHttpCacheRequest =
+            RemoteCacheRequestFactory.createGetRequest( cacheName, key, requesterId );
+
+        RemoteCacheResponse<ICacheElement<K, V>> remoteHttpCacheResponse =
+            getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest );
+
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "Get [" + key + "] = " + remoteHttpCacheResponse );
+        }
+
+        if ( remoteHttpCacheResponse != null)
+        {
+            return remoteHttpCacheResponse.getPayload();
+        }
+
+        return null;
+    }
+
+    /**
+     * Gets multiple items from the cache matching the pattern.
+     * <p>
+     * @param cacheName
+     * @param pattern
+     * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no
+     *         data in cache matching the pattern.
+     * @throws IOException
+     */
+    public Map<K, ICacheElement<K, V>> getMatching( String cacheName, String pattern )
+        throws IOException
+    {
+        return getMatching( cacheName, pattern, 0 );
+    }
+
+    /**
+     * Gets multiple items from the cache matching the pattern.
+     * <p>
+     * @param cacheName
+     * @param pattern
+     * @param requesterId
+     * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no
+     *         data in cache matching the pattern.
+     * @throws IOException
+     */
+    public Map<K, ICacheElement<K, V>> getMatching( String cacheName, String pattern, long requesterId )
+        throws IOException
+    {
+        if ( !isInitialized() )
+        {
+            String message = "The Remote Http Client is not initialized.  Cannot process request.";
+            log.warn( message );
+            throw new IOException( message );
+        }
+
+        RemoteCacheRequest<K, V> remoteHttpCacheRequest =
+            RemoteCacheRequestFactory.createGetMatchingRequest( cacheName, pattern, requesterId );
+
+        RemoteCacheResponse<Map<K, ICacheElement<K, V>>> remoteHttpCacheResponse =
+            getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest );
+
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "GetMatching [" + pattern + "] = " + remoteHttpCacheResponse );
+        }
+
+        return remoteHttpCacheResponse.getPayload();
+    }
+
+    /**
+     * Gets multiple items from the cache based on the given set of keys.
+     * <p>
+     * @param cacheName
+     * @param keys
+     * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no
+     *         data in cache for any of these keys
+     * @throws IOException
+     */
+    public Map<K, ICacheElement<K, V>> getMultiple( String cacheName, Set<K> keys )
+        throws IOException
+    {
+        return getMultiple( cacheName, keys, 0 );
+    }
+
+    /**
+     * Gets multiple items from the cache based on the given set of keys.
+     * <p>
+     * @param cacheName
+     * @param keys
+     * @param requesterId
+     * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no
+     *         data in cache for any of these keys
+     * @throws IOException
+     */
+    public Map<K, ICacheElement<K, V>> getMultiple( String cacheName, Set<K> keys, long requesterId )
+        throws IOException
+    {
+        if ( !isInitialized() )
+        {
+            String message = "The Remote Http Client is not initialized.  Cannot process request.";
+            log.warn( message );
+            throw new IOException( message );
+        }
+
+        RemoteCacheRequest<K, V> remoteHttpCacheRequest =
+            RemoteCacheRequestFactory.createGetMultipleRequest( cacheName, keys, requesterId );
+
+        RemoteCacheResponse<Map<K, ICacheElement<K, V>>> remoteHttpCacheResponse =
+            getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest );
+
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "GetMultiple [" + keys + "] = " + remoteHttpCacheResponse );
+        }
+
+        return remoteHttpCacheResponse.getPayload();
+    }
+
+    /**
+     * Removes the given key from the specified cache.
+     * <p>
+     * @param cacheName
+     * @param key
+     * @throws IOException
+     */
+    public void remove( String cacheName, K key )
+        throws IOException
+    {
+        remove( cacheName, key, 0 );
+    }
+
+    /**
+     * Removes the given key from the specified cache.
+     * <p>
+     * @param cacheName
+     * @param key
+     * @param requesterId
+     * @throws IOException
+     */
+    public void remove( String cacheName, K key, long requesterId )
+        throws IOException
+    {
+        if ( !isInitialized() )
+        {
+            String message = "The Remote Http Client is not initialized.  Cannot process request.";
+            log.warn( message );
+            throw new IOException( message );
+        }
+
+        RemoteCacheRequest<K, V> remoteHttpCacheRequest =
+            RemoteCacheRequestFactory.createRemoveRequest( cacheName, key, requesterId );
+
+        getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest );
+    }
+
+    /**
+     * Remove all keys from the specified cache.
+     * <p>
+     * @param cacheName
+     * @throws IOException
+     */
+    public void removeAll( String cacheName )
+        throws IOException
+    {
+        removeAll( cacheName, 0 );
+    }
+
+    /**
+     * Remove all keys from the sepcified cache.
+     * <p>
+     * @param cacheName
+     * @param requesterId
+     * @throws IOException
+     */
+    public void removeAll( String cacheName, long requesterId )
+        throws IOException
+    {
+        if ( !isInitialized() )
+        {
+            String message = "The Remote Http Client is not initialized.  Cannot process request.";
+            log.warn( message );
+            throw new IOException( message );
+        }
+
+        RemoteCacheRequest<K, V> remoteHttpCacheRequest =
+            RemoteCacheRequestFactory.createRemoveAllRequest( cacheName, requesterId );
+
+        getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest );
+    }
+
+    /**
+     * Puts a cache item to the cache.
+     * <p>
+     * @param item
+     * @throws IOException
+     */
+    public void update( ICacheElement<K, V> item )
+        throws IOException
+    {
+        update( item, 0 );
+    }
+
+    /**
+     * Puts a cache item to the cache.
+     * <p>
+     * @param cacheElement
+     * @param requesterId
+     * @throws IOException
+     */
+    public void update( ICacheElement<K, V> cacheElement, long requesterId )
+        throws IOException
+    {
+        if ( !isInitialized() )
+        {
+            String message = "The Remote Http Client is not initialized.  Cannot process request.";
+            log.warn( message );
+            throw new IOException( message );
+        }
+
+        RemoteCacheRequest<K, V> remoteHttpCacheRequest =
+            RemoteCacheRequestFactory.createUpdateRequest( cacheElement, requesterId );
+
+        getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest );
+    }
+
+    /**
+     * Frees the specified cache.
+     * <p>
+     * @param cacheName
+     * @throws IOException
+     */
+    public void dispose( String cacheName )
+        throws IOException
+    {
+        if ( !isInitialized() )
+        {
+            String message = "The Remote Http Client is not initialized.  Cannot process request.";
+            log.warn( message );
+            throw new IOException( message );
+        }
+
+        RemoteCacheRequest<K, V> remoteHttpCacheRequest =
+            RemoteCacheRequestFactory.createDisposeRequest( cacheName, 0 );
+
+        getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest );
+    }
+
+    /**
+     * Frees the specified cache.
+     * <p>
+     * @throws IOException
+     */
+    public void release()
+        throws IOException
+    {
+        // noop
+    }
+
+    /**
+     * Return the keys in this cache.
+     * <p>
+     * @param cacheName the name of the cache
+     * @see org.apache.commons.jcs.auxiliary.AuxiliaryCache#getKeySet()
+     */
+    public Set<K> getKeySet( String cacheName ) throws IOException
+    {
+        if ( !isInitialized() )
+        {
+            String message = "The Remote Http Client is not initialized.  Cannot process request.";
+            log.warn( message );
+            throw new IOException( message );
+        }
+
+        RemoteCacheRequest<String, String> remoteHttpCacheRequest =
+            RemoteCacheRequestFactory.createGetKeySetRequest(cacheName, 0 );
+
+        RemoteCacheResponse<Set<K>> remoteHttpCacheResponse = getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest );
+
+        if ( remoteHttpCacheResponse != null && remoteHttpCacheResponse.getPayload() != null )
+        {
+            return remoteHttpCacheResponse.getPayload();
+        }
+
+        return Collections.emptySet();
+    }
+
+    /**
+     * Make and alive request.
+     * <p>
+     * @return true if we make a successful alive request.
+     * @throws IOException
+     */
+    public boolean isAlive()
+        throws IOException
+    {
+        if ( !isInitialized() )
+        {
+            String message = "The Remote Http Client is not initialized.  Cannot process request.";
+            log.warn( message );
+            throw new IOException( message );
+        }
+
+        RemoteCacheRequest<K, V> remoteHttpCacheRequest = RemoteCacheRequestFactory.createAliveCheckRequest( 0 );
+        RemoteCacheResponse<String> remoteHttpCacheResponse =
+            getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest );
+
+        if ( remoteHttpCacheResponse != null )
+        {
+            return remoteHttpCacheResponse.isSuccess();
+        }
+
+        return false;
+    }
+
+    /**
+     * @param remoteDispatcher the remoteDispatcher to set
+     */
+    public void setRemoteDispatcher( IRemoteCacheDispatcher remoteDispatcher )
+    {
+        this.remoteDispatcher = remoteDispatcher;
+    }
+
+    /**
+     * @return the remoteDispatcher
+     */
+    public IRemoteCacheDispatcher getRemoteDispatcher()
+    {
+        return remoteDispatcher;
+    }
+
+    /**
+     * @param remoteHttpCacheAttributes the remoteHttpCacheAttributes to set
+     */
+    public void setRemoteHttpCacheAttributes( RemoteHttpCacheAttributes remoteHttpCacheAttributes )
+    {
+        this.remoteHttpCacheAttributes = remoteHttpCacheAttributes;
+    }
+
+    /**
+     * @return the remoteHttpCacheAttributes
+     */
+    public RemoteHttpCacheAttributes getRemoteHttpCacheAttributes()
+    {
+        return remoteHttpCacheAttributes;
+    }
+
+    /**
+     * @param initialized the initialized to set
+     */
+    protected void setInitialized( boolean initialized )
+    {
+        this.initialized = initialized;
+    }
+
+    /**
+     * @return the initialized
+     */
+    protected boolean isInitialized()
+    {
+        return initialized;
+    }
+}

Modified: commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java?rev=1570993&r1=1570992&r2=1570993&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java Sun Feb 23 10:37:48 2014
@@ -1,231 +1,231 @@
-package org.apache.commons.jcs.auxiliary.remote.http.client;
-
-/*
- * 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.
- */
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.HttpMethod;
-import org.apache.commons.httpclient.HttpState;
-import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.methods.RequestEntity;
-import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheDispatcher;
-import org.apache.commons.jcs.auxiliary.remote.value.RemoteCacheRequest;
-import org.apache.commons.jcs.auxiliary.remote.value.RemoteCacheResponse;
-import org.apache.commons.jcs.utils.serialization.StandardSerializer;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/** Calls the service. */
-public class RemoteHttpCacheDispatcher
-    extends AbstractHttpClient
-    implements IRemoteCacheDispatcher
-{
-    /** Named of the parameter */
-    private static final String PARAMETER_REQUEST_TYPE = "RequestType";
-
-    /** Named of the parameter */
-    private static final String PARAMETER_KEY = "Key";
-
-    /** Named of the parameter */
-    private static final String PARAMETER_CACHE_NAME = "CacheName";
-
-    /** The Logger. */
-    private final static Log log = LogFactory.getLog( RemoteHttpCacheDispatcher.class );
-
-    /** This needs to be standard, since the other side is standard */
-    private StandardSerializer serializer = new StandardSerializer();
-
-    /**
-     * @param remoteHttpCacheAttributes
-     */
-    public RemoteHttpCacheDispatcher( RemoteHttpCacheAttributes remoteHttpCacheAttributes )
-    {
-        super( remoteHttpCacheAttributes );
-    }
-
-    /**
-     * All requests will go through this method.
-     * <p>
-     * TODO consider taking in a URL instead of using the one in the configuration.
-     * <p>
-     * @param remoteCacheRequest
-     * @return RemoteCacheResponse
-     * @throws IOException
-     */
-    public <K extends Serializable, V extends Serializable, T>
-        RemoteCacheResponse<T> dispatchRequest( RemoteCacheRequest<K, V> remoteCacheRequest )
-        throws IOException
-    {
-        try
-        {
-            byte[] requestAsByteArray = serializer.serialize( remoteCacheRequest );
-
-            String url = addParameters( remoteCacheRequest, getRemoteHttpCacheAttributes().getUrl() );
-
-            byte[] responseAsByteArray = processRequest( requestAsByteArray, url );
-
-            RemoteCacheResponse<T> remoteCacheResponse = null;
-            try
-            {
-                remoteCacheResponse = serializer.deSerialize( responseAsByteArray );
-            }
-            catch ( ClassNotFoundException e )
-            {
-                log.error( "Couldn't deserialize the response.", e );
-            }
-            return remoteCacheResponse;
-        }
-        catch ( Exception e )
-        {
-            log.error( "Problem dispatching request.", e );
-            throw new IOException( e.getMessage() );
-        }
-    }
-
-    /**
-     * @param requestAsByteArray
-     * @param url
-     * @return byte[] - the response
-     * @throws IOException
-     * @throws HttpException
-     */
-    protected byte[] processRequest( byte[] requestAsByteArray, String url )
-        throws IOException, HttpException
-    {
-        PostMethod post = new PostMethod( url );
-        RequestEntity requestEntity = new ByteArrayRequestEntity( requestAsByteArray );
-        post.setRequestEntity( requestEntity );
-        doWebserviceCall( post );
-        byte[] response = post.getResponseBody();
-        return response;
-    }
-
-    /**
-     * @param remoteCacheRequest
-     * @param baseUrl
-     * @return String
-     */
-    protected <K extends Serializable, V extends Serializable> String addParameters( RemoteCacheRequest<K, V> remoteCacheRequest, String baseUrl )
-    {
-        StringBuffer url = new StringBuffer( baseUrl );
-
-        try
-        {
-            if ( baseUrl != null && ( baseUrl.indexOf( "?" ) == -1 ) )
-            {
-                url.append( "?" );
-            }
-            else
-            {
-                url.append( "&" );
-            }
-
-            if ( getRemoteHttpCacheAttributes().isIncludeCacheNameAsParameter() )
-            {
-                if ( remoteCacheRequest.getCacheName() != null )
-                {
-                    url.append( PARAMETER_CACHE_NAME + "="
-                        + URLEncoder.encode( remoteCacheRequest.getCacheName(), "UTF-8" ) );
-                }
-            }
-            if ( getRemoteHttpCacheAttributes().isIncludeKeysAndPatternsAsParameter() )
-            {
-                String keyValue = "";
-                switch ( remoteCacheRequest.getRequestType() )
-                {
-                    case GET:
-                        keyValue = remoteCacheRequest.getKey() + "";
-                        break;
-                    case REMOVE:
-                        keyValue = remoteCacheRequest.getKey() + "";
-                        break;
-                    case GET_MATCHING:
-                        keyValue = remoteCacheRequest.getPattern();
-                        break;
-                    case GET_MULTIPLE:
-                        keyValue = remoteCacheRequest.getKeySet() + "";
-                        break;
-                    case GET_KEYSET:
-                        keyValue = remoteCacheRequest.getKey() + "";
-                        break;
-                    case UPDATE:
-                        keyValue = remoteCacheRequest.getCacheElement().getKey() + "";
-                        break;
-                    default:
-                        break;
-                }
-                String encodedKeyValue = URLEncoder.encode( keyValue, "UTF-8" );
-                url.append( "&" + PARAMETER_KEY + "=" + encodedKeyValue );
-            }
-            if ( getRemoteHttpCacheAttributes().isIncludeRequestTypeasAsParameter() )
-            {
-                url.append( "&"
-                    + PARAMETER_REQUEST_TYPE
-                    + "="
-                    + URLEncoder.encode( remoteCacheRequest.getRequestType().toString(), "UTF-8" ) );
-            }
-        }
-        catch ( UnsupportedEncodingException e )
-        {
-            log.error( "Couldn't encode URL.", e );
-        }
-
-        if ( log.isDebugEnabled() )
-        {
-            log.debug( "Url: " + url.toString() );
-        }
-
-        return url.toString();
-    }
-
-    /**
-     * Called before the executeMethod on the client.
-     * <p>
-     * @param post http method
-     * @return HttpState
-     * @throws IOException
-     */
-    @Override
-    public HttpState preProcessWebserviceCall( HttpMethod post )
-        throws IOException
-    {
-        // do nothing. Child can override.
-        return null;
-    }
-
-    /**
-     * Called after the executeMethod on the client.
-     * <p>
-     * @param post http method
-     * @param httpState state
-     * @throws IOException
-     */
-    @Override
-    public void postProcessWebserviceCall( HttpMethod post, HttpState httpState )
-        throws IOException
-    {
-        // do nothing. Child can override.
-    }
-}
+package org.apache.commons.jcs.auxiliary.remote.http.client;
+
+/*
+ * 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.
+ */
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.HttpState;
+import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.RequestEntity;
+import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheDispatcher;
+import org.apache.commons.jcs.auxiliary.remote.value.RemoteCacheRequest;
+import org.apache.commons.jcs.auxiliary.remote.value.RemoteCacheResponse;
+import org.apache.commons.jcs.utils.serialization.StandardSerializer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/** Calls the service. */
+public class RemoteHttpCacheDispatcher
+    extends AbstractHttpClient
+    implements IRemoteCacheDispatcher
+{
+    /** Named of the parameter */
+    private static final String PARAMETER_REQUEST_TYPE = "RequestType";
+
+    /** Named of the parameter */
+    private static final String PARAMETER_KEY = "Key";
+
+    /** Named of the parameter */
+    private static final String PARAMETER_CACHE_NAME = "CacheName";
+
+    /** The Logger. */
+    private final static Log log = LogFactory.getLog( RemoteHttpCacheDispatcher.class );
+
+    /** This needs to be standard, since the other side is standard */
+    private StandardSerializer serializer = new StandardSerializer();
+
+    /**
+     * @param remoteHttpCacheAttributes
+     */
+    public RemoteHttpCacheDispatcher( RemoteHttpCacheAttributes remoteHttpCacheAttributes )
+    {
+        super( remoteHttpCacheAttributes );
+    }
+
+    /**
+     * All requests will go through this method.
+     * <p>
+     * TODO consider taking in a URL instead of using the one in the configuration.
+     * <p>
+     * @param remoteCacheRequest
+     * @return RemoteCacheResponse
+     * @throws IOException
+     */
+    public <K extends Serializable, V extends Serializable, T>
+        RemoteCacheResponse<T> dispatchRequest( RemoteCacheRequest<K, V> remoteCacheRequest )
+        throws IOException
+    {
+        try
+        {
+            byte[] requestAsByteArray = serializer.serialize( remoteCacheRequest );
+
+            String url = addParameters( remoteCacheRequest, getRemoteHttpCacheAttributes().getUrl() );
+
+            byte[] responseAsByteArray = processRequest( requestAsByteArray, url );
+
+            RemoteCacheResponse<T> remoteCacheResponse = null;
+            try
+            {
+                remoteCacheResponse = serializer.deSerialize( responseAsByteArray );
+            }
+            catch ( ClassNotFoundException e )
+            {
+                log.error( "Couldn't deserialize the response.", e );
+            }
+            return remoteCacheResponse;
+        }
+        catch ( Exception e )
+        {
+            log.error( "Problem dispatching request.", e );
+            throw new IOException( e.getMessage() );
+        }
+    }
+
+    /**
+     * @param requestAsByteArray
+     * @param url
+     * @return byte[] - the response
+     * @throws IOException
+     * @throws HttpException
+     */
+    protected byte[] processRequest( byte[] requestAsByteArray, String url )
+        throws IOException, HttpException
+    {
+        PostMethod post = new PostMethod( url );
+        RequestEntity requestEntity = new ByteArrayRequestEntity( requestAsByteArray );
+        post.setRequestEntity( requestEntity );
+        doWebserviceCall( post );
+        byte[] response = post.getResponseBody();
+        return response;
+    }
+
+    /**
+     * @param remoteCacheRequest
+     * @param baseUrl
+     * @return String
+     */
+    protected <K extends Serializable, V extends Serializable> String addParameters( RemoteCacheRequest<K, V> remoteCacheRequest, String baseUrl )
+    {
+        StringBuffer url = new StringBuffer( baseUrl );
+
+        try
+        {
+            if ( baseUrl != null && ( baseUrl.indexOf( "?" ) == -1 ) )
+            {
+                url.append( "?" );
+            }
+            else
+            {
+                url.append( "&" );
+            }
+
+            if ( getRemoteHttpCacheAttributes().isIncludeCacheNameAsParameter() )
+            {
+                if ( remoteCacheRequest.getCacheName() != null )
+                {
+                    url.append( PARAMETER_CACHE_NAME + "="
+                        + URLEncoder.encode( remoteCacheRequest.getCacheName(), "UTF-8" ) );
+                }
+            }
+            if ( getRemoteHttpCacheAttributes().isIncludeKeysAndPatternsAsParameter() )
+            {
+                String keyValue = "";
+                switch ( remoteCacheRequest.getRequestType() )
+                {
+                    case GET:
+                        keyValue = remoteCacheRequest.getKey() + "";
+                        break;
+                    case REMOVE:
+                        keyValue = remoteCacheRequest.getKey() + "";
+                        break;
+                    case GET_MATCHING:
+                        keyValue = remoteCacheRequest.getPattern();
+                        break;
+                    case GET_MULTIPLE:
+                        keyValue = remoteCacheRequest.getKeySet() + "";
+                        break;
+                    case GET_KEYSET:
+                        keyValue = remoteCacheRequest.getKey() + "";
+                        break;
+                    case UPDATE:
+                        keyValue = remoteCacheRequest.getCacheElement().getKey() + "";
+                        break;
+                    default:
+                        break;
+                }
+                String encodedKeyValue = URLEncoder.encode( keyValue, "UTF-8" );
+                url.append( "&" + PARAMETER_KEY + "=" + encodedKeyValue );
+            }
+            if ( getRemoteHttpCacheAttributes().isIncludeRequestTypeasAsParameter() )
+            {
+                url.append( "&"
+                    + PARAMETER_REQUEST_TYPE
+                    + "="
+                    + URLEncoder.encode( remoteCacheRequest.getRequestType().toString(), "UTF-8" ) );
+            }
+        }
+        catch ( UnsupportedEncodingException e )
+        {
+            log.error( "Couldn't encode URL.", e );
+        }
+
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "Url: " + url.toString() );
+        }
+
+        return url.toString();
+    }
+
+    /**
+     * Called before the executeMethod on the client.
+     * <p>
+     * @param post http method
+     * @return HttpState
+     * @throws IOException
+     */
+    @Override
+    public HttpState preProcessWebserviceCall( HttpMethod post )
+        throws IOException
+    {
+        // do nothing. Child can override.
+        return null;
+    }
+
+    /**
+     * Called after the executeMethod on the client.
+     * <p>
+     * @param post http method
+     * @param httpState state
+     * @throws IOException
+     */
+    @Override
+    public void postProcessWebserviceCall( HttpMethod post, HttpState httpState )
+        throws IOException
+    {
+        // do nothing. Child can override.
+    }
+}

Modified: commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheFactory.java?rev=1570993&r1=1570992&r2=1570993&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheFactory.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheFactory.java Sun Feb 23 10:37:48 2014
@@ -1,129 +1,129 @@
-package org.apache.commons.jcs.auxiliary.remote.http.client;
-
-/*
- * 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.
- */
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.HashMap;
-
-import org.apache.commons.jcs.auxiliary.AuxiliaryCache;
-import org.apache.commons.jcs.auxiliary.AuxiliaryCacheAttributes;
-import org.apache.commons.jcs.auxiliary.AuxiliaryCacheFactory;
-import org.apache.commons.jcs.auxiliary.remote.RemoteCacheNoWait;
-import org.apache.commons.jcs.auxiliary.remote.RemoteCacheNoWaitFacade;
-import org.apache.commons.jcs.auxiliary.remote.server.behavior.RemoteType;
-import org.apache.commons.jcs.engine.behavior.ICache;
-import org.apache.commons.jcs.engine.behavior.ICompositeCacheManager;
-import org.apache.commons.jcs.engine.behavior.IElementSerializer;
-import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * The RemoteCacheFactory creates remote caches for the cache hub. It returns a no wait facade which
- * is a wrapper around a no wait. The no wait object is either an active connection to a remote
- * cache or a balking zombie if the remote cache is not accessible. It should be transparent to the
- * clients.
- */
-public class RemoteHttpCacheFactory
-    implements AuxiliaryCacheFactory
-{
-    /** The logger. */
-    private final static Log log = LogFactory.getLog( RemoteHttpCacheFactory.class );
-
-    /** The name of this auxiliary */
-    private String name;
-
-    /** store reference of facades to initiate failover */
-    private final static HashMap<String, RemoteCacheNoWaitFacade<? extends Serializable, ? extends Serializable>> facades =
-        new HashMap<String, RemoteCacheNoWaitFacade<? extends Serializable, ? extends Serializable>>();
-
-    /**
-     * For LOCAL clients we get a handle to all the failovers, but we do not register a listener
-     * with them. We create the RemoteCacheManager, but we do not get a cache.
-     * <p>
-     * The failover runner will get a cache from the manager. When the primary is restored it will
-     * tell the manager for the failover to deregister the listener.
-     * <p>
-     * @param iaca
-     * @param cacheMgr
-     * @param cacheEventLogger
-     * @param elementSerializer
-     * @return AuxiliaryCache
-     */
-    public <K extends Serializable, V extends Serializable> AuxiliaryCache<K, V> createCache( AuxiliaryCacheAttributes iaca, ICompositeCacheManager cacheMgr,
-                                       ICacheEventLogger cacheEventLogger, IElementSerializer elementSerializer )
-    {
-        RemoteHttpCacheAttributes rca = (RemoteHttpCacheAttributes) iaca;
-
-        ArrayList<ICache<K, V>> noWaits = new ArrayList<ICache<K, V>>();
-
-        RemoteHttpCacheManager rcm = RemoteHttpCacheManager.getInstance( cacheMgr, cacheEventLogger, elementSerializer );
-        // TODO, use the configured value.
-        rca.setRemoteType( RemoteType.LOCAL );
-        ICache<K, V> ic = rcm.getCache( rca );
-        if ( ic != null )
-        {
-            noWaits.add( ic );
-        }
-        else
-        {
-            log.info( "noWait is null" );
-        }
-
-        @SuppressWarnings("unchecked") // No generic arrays in java
-        RemoteCacheNoWait<K, V>[] rcnwArray = noWaits.toArray( new RemoteCacheNoWait[0] );
-        RemoteCacheNoWaitFacade<K, V> rcnwf =
-            new RemoteCacheNoWaitFacade<K, V>(rcnwArray, rca, cacheMgr, cacheEventLogger, elementSerializer );
-
-        getFacades().put( rca.getCacheName(), rcnwf );
-
-        return rcnwf;
-    }
-
-    /**
-     * Gets the name attribute of the RemoteCacheFactory object
-     * <p>
-     * @return The name value
-     */
-    public String getName()
-    {
-        return this.name;
-    }
-
-    /**
-     * Sets the name attribute of the RemoteCacheFactory object
-     * <p>
-     * @param name The new name value
-     */
-    public void setName( String name )
-    {
-        this.name = name;
-    }
-
-    /**
-     * The facades are what the cache hub talks to.
-     * @return Returns the facades.
-     */
-    public static HashMap<String, RemoteCacheNoWaitFacade<? extends Serializable, ? extends Serializable>> getFacades()
-    {
-        return facades;
-    }
-}
+package org.apache.commons.jcs.auxiliary.remote.http.client;
+
+/*
+ * 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.
+ */
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.apache.commons.jcs.auxiliary.AuxiliaryCache;
+import org.apache.commons.jcs.auxiliary.AuxiliaryCacheAttributes;
+import org.apache.commons.jcs.auxiliary.AuxiliaryCacheFactory;
+import org.apache.commons.jcs.auxiliary.remote.RemoteCacheNoWait;
+import org.apache.commons.jcs.auxiliary.remote.RemoteCacheNoWaitFacade;
+import org.apache.commons.jcs.auxiliary.remote.server.behavior.RemoteType;
+import org.apache.commons.jcs.engine.behavior.ICache;
+import org.apache.commons.jcs.engine.behavior.ICompositeCacheManager;
+import org.apache.commons.jcs.engine.behavior.IElementSerializer;
+import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * The RemoteCacheFactory creates remote caches for the cache hub. It returns a no wait facade which
+ * is a wrapper around a no wait. The no wait object is either an active connection to a remote
+ * cache or a balking zombie if the remote cache is not accessible. It should be transparent to the
+ * clients.
+ */
+public class RemoteHttpCacheFactory
+    implements AuxiliaryCacheFactory
+{
+    /** The logger. */
+    private final static Log log = LogFactory.getLog( RemoteHttpCacheFactory.class );
+
+    /** The name of this auxiliary */
+    private String name;
+
+    /** store reference of facades to initiate failover */
+    private final static HashMap<String, RemoteCacheNoWaitFacade<? extends Serializable, ? extends Serializable>> facades =
+        new HashMap<String, RemoteCacheNoWaitFacade<? extends Serializable, ? extends Serializable>>();
+
+    /**
+     * For LOCAL clients we get a handle to all the failovers, but we do not register a listener
+     * with them. We create the RemoteCacheManager, but we do not get a cache.
+     * <p>
+     * The failover runner will get a cache from the manager. When the primary is restored it will
+     * tell the manager for the failover to deregister the listener.
+     * <p>
+     * @param iaca
+     * @param cacheMgr
+     * @param cacheEventLogger
+     * @param elementSerializer
+     * @return AuxiliaryCache
+     */
+    public <K extends Serializable, V extends Serializable> AuxiliaryCache<K, V> createCache( AuxiliaryCacheAttributes iaca, ICompositeCacheManager cacheMgr,
+                                       ICacheEventLogger cacheEventLogger, IElementSerializer elementSerializer )
+    {
+        RemoteHttpCacheAttributes rca = (RemoteHttpCacheAttributes) iaca;
+
+        ArrayList<ICache<K, V>> noWaits = new ArrayList<ICache<K, V>>();
+
+        RemoteHttpCacheManager rcm = RemoteHttpCacheManager.getInstance( cacheMgr, cacheEventLogger, elementSerializer );
+        // TODO, use the configured value.
+        rca.setRemoteType( RemoteType.LOCAL );
+        ICache<K, V> ic = rcm.getCache( rca );
+        if ( ic != null )
+        {
+            noWaits.add( ic );
+        }
+        else
+        {
+            log.info( "noWait is null" );
+        }
+
+        @SuppressWarnings("unchecked") // No generic arrays in java
+        RemoteCacheNoWait<K, V>[] rcnwArray = noWaits.toArray( new RemoteCacheNoWait[0] );
+        RemoteCacheNoWaitFacade<K, V> rcnwf =
+            new RemoteCacheNoWaitFacade<K, V>(rcnwArray, rca, cacheMgr, cacheEventLogger, elementSerializer );
+
+        getFacades().put( rca.getCacheName(), rcnwf );
+
+        return rcnwf;
+    }
+
+    /**
+     * Gets the name attribute of the RemoteCacheFactory object
+     * <p>
+     * @return The name value
+     */
+    public String getName()
+    {
+        return this.name;
+    }
+
+    /**
+     * Sets the name attribute of the RemoteCacheFactory object
+     * <p>
+     * @param name The new name value
+     */
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+
+    /**
+     * The facades are what the cache hub talks to.
+     * @return Returns the facades.
+     */
+    public static HashMap<String, RemoteCacheNoWaitFacade<? extends Serializable, ? extends Serializable>> getFacades()
+    {
+        return facades;
+    }
+}

Modified: commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheManager.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheManager.java?rev=1570993&r1=1570992&r2=1570993&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheManager.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheManager.java Sun Feb 23 10:37:48 2014
@@ -1,274 +1,274 @@
-package org.apache.commons.jcs.auxiliary.remote.http.client;
-
-/*
- * 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.
- */
-
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.commons.jcs.auxiliary.AuxiliaryCacheManager;
-import org.apache.commons.jcs.auxiliary.remote.RemoteCacheNoWait;
-import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes;
-import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheClient;
-import org.apache.commons.jcs.auxiliary.remote.http.client.behavior.IRemoteHttpCacheClient;
-import org.apache.commons.jcs.engine.behavior.ICompositeCacheManager;
-import org.apache.commons.jcs.engine.behavior.IElementSerializer;
-import org.apache.commons.jcs.engine.behavior.IShutdownObserver;
-import org.apache.commons.jcs.engine.control.CompositeCacheManager;
-import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
-import org.apache.commons.jcs.utils.config.OptionConverter;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * This is a very crude copy of the RMI remote manager. It needs a lot of work!
- */
-public class RemoteHttpCacheManager
-    implements AuxiliaryCacheManager, IShutdownObserver
-{
-    /** Don't change */
-    private static final long serialVersionUID = 798077557166389498L;
-
-    /** The logger */
-    private final static Log log = LogFactory.getLog( RemoteHttpCacheManager.class );
-
-    /** Contains mappings of Location instance to RemoteCacheManager instance. */
-    private static RemoteHttpCacheManager instance;
-
-    /** Contains instances of RemoteCacheNoWait managed by a RemoteCacheManager instance. */
-    static final Map<String, RemoteCacheNoWait<? extends Serializable, ? extends Serializable>> caches =
-        new HashMap<String, RemoteCacheNoWait<? extends Serializable, ? extends Serializable>>();
-
-    /** The configuration attributes. */
-    private IRemoteCacheAttributes remoteCacheAttributes;
-
-    /** The event logger. */
-    private final ICacheEventLogger cacheEventLogger;
-
-    /** The serializer. */
-    private final IElementSerializer elementSerializer;
-
-    /** The cache manager listeners will need to use to get a cache. */
-    private final ICompositeCacheManager cacheMgr;
-
-    /** Remote cache monitor. */
-    private static RemoteHttpCacheMonitor monitor;
-
-    /**
-     * Constructs an instance to with the given remote connection parameters. If the connection
-     * cannot be made, "zombie" services will be temporarily used until a successful re-connection
-     * is made by the monitoring daemon.
-     * <p>
-     * @param cacheMgr
-     * @param cacheEventLogger
-     * @param elementSerializer
-     */
-    private RemoteHttpCacheManager( ICompositeCacheManager cacheMgr, ICacheEventLogger cacheEventLogger,
-                                    IElementSerializer elementSerializer )
-    {
-        this.cacheMgr = cacheMgr;
-        this.cacheEventLogger = cacheEventLogger;
-        this.elementSerializer = elementSerializer;
-
-        // register shutdown observer
-        // TODO add the shutdown observable methods to the interface
-        if ( this.cacheMgr instanceof CompositeCacheManager )
-        {
-            ( (CompositeCacheManager) this.cacheMgr ).registerShutdownObserver( this );
-        }
-    }
-
-    /**
-     * Gets the defaultCattr attribute of the RemoteCacheManager object.
-     * <p>
-     * @return The defaultCattr value
-     */
-    public IRemoteCacheAttributes getDefaultCattr()
-    {
-        return this.remoteCacheAttributes;
-    }
-
-    /** @return Returns an instance if it exists. else null. */
-    public synchronized static RemoteHttpCacheManager getInstance()
-    {
-        return instance;
-    }
-
-    /**
-     * Get the singleton instance.
-     * <p>
-     * @param cacheMgr
-     * @param cacheEventLogger
-     * @param elementSerializer
-     * @return The instance value
-     */
-    public synchronized static RemoteHttpCacheManager getInstance( ICompositeCacheManager cacheMgr,
-                                                                   ICacheEventLogger cacheEventLogger,
-                                                                   IElementSerializer elementSerializer )
-    {
-        if ( instance == null )
-        {
-            instance = new RemoteHttpCacheManager( cacheMgr, cacheEventLogger, elementSerializer );
-        }
-
-        // Fires up the monitoring daemon.
-        if ( monitor == null )
-        {
-            monitor = RemoteHttpCacheMonitor.getInstance();
-            // If the returned monitor is null, it means it's already started
-            // elsewhere.
-            if ( monitor != null )
-            {
-                Thread t = new Thread( monitor );
-                t.setDaemon( true );
-                t.start();
-            }
-        }
-
-        return instance;
-    }
-
-    /**
-     * Returns a remote cache for the given cache name.
-     * <p>
-     * @param cacheName
-     * @return The cache value
-     */
-    public <K extends Serializable, V extends Serializable> RemoteCacheNoWait<K, V> getCache( String cacheName )
-    {
-        // TODO get some defaults!
-        // Perhaps we will need a manager per URL????
-        RemoteHttpCacheAttributes ca = new RemoteHttpCacheAttributes();
-        ca.setCacheName( cacheName );
-        return getCache( ca );
-    }
-
-    /**
-     * Gets a RemoteCacheNoWait from the RemoteCacheManager. The RemoteCacheNoWait objects are
-     * identified by the cache name value of the RemoteCacheAttributes object.
-     * <p>
-     * If the client is configured to register a listener, this call results on a listener being
-     * created if one isn't already registered with the remote cache for this region.
-     * <p>
-     * @param cattr
-     * @return The cache value
-     */
-    public <K extends Serializable, V extends Serializable> RemoteCacheNoWait<K, V> getCache( RemoteHttpCacheAttributes cattr )
-    {
-        RemoteCacheNoWait<K, V> remoteCacheNoWait = null;
-
-        synchronized ( caches )
-        {
-            @SuppressWarnings("unchecked") // Need to cast because of common map for all caches
-            RemoteCacheNoWait<K, V> remoteCacheNoWait2 = (RemoteCacheNoWait<K, V>) caches.get( cattr.getCacheName() + cattr.getUrl() );
-            remoteCacheNoWait = remoteCacheNoWait2;
-            if ( remoteCacheNoWait == null )
-            {
-                RemoteHttpClientListener<K, V> listener = new RemoteHttpClientListener<K, V>( cattr, cacheMgr );
-
-                IRemoteHttpCacheClient<K, V> remoteService = createRemoteHttpCacheClientForAttributes( cattr );
-
-                IRemoteCacheClient<K, V> remoteCacheClient = new RemoteHttpCache<K, V>( cattr, remoteService, listener );
-                remoteCacheClient.setCacheEventLogger( cacheEventLogger );
-                remoteCacheClient.setElementSerializer( elementSerializer );
-
-                remoteCacheNoWait = new RemoteCacheNoWait<K, V>( remoteCacheClient );
-                remoteCacheNoWait.setCacheEventLogger( cacheEventLogger );
-                remoteCacheNoWait.setElementSerializer( elementSerializer );
-
-                caches.put( cattr.getCacheName() + cattr.getUrl(), remoteCacheNoWait );
-            }
-            // might want to do some listener sanity checking here.
-        }
-
-        return remoteCacheNoWait;
-    }
-
-    /**
-     * This is an extension point. The manager and other classes will only create
-     * RemoteHttpCacheClient through this method.
-     * <p>
-     * @param cattr
-     * @return IRemoteHttpCacheClient
-     */
-    protected <K extends Serializable, V extends Serializable> IRemoteHttpCacheClient<K, V> createRemoteHttpCacheClientForAttributes( RemoteHttpCacheAttributes cattr )
-    {
-        IRemoteHttpCacheClient<K, V> client = OptionConverter.instantiateByClassName( cattr
-            .getRemoteHttpClientClassName(), null );
-
-        if ( client == null )
-        {
-            if ( log.isInfoEnabled() )
-            {
-                log.info( "Creating the default client." );
-            }
-            client = new RemoteHttpCacheClient<K, V>( );
-        }
-        client.initialize( cattr );
-        return client;
-    }
-
-    /**
-     * Gets the stats attribute of the RemoteCacheManager object
-     * <p>
-     * @return The stats value
-     */
-    public String getStats()
-    {
-        StringBuffer stats = new StringBuffer();
-        for (RemoteCacheNoWait<?, ?> c : caches.values())
-        {
-            if ( c != null )
-            {
-                stats.append( c.getCacheName() );
-            }
-        }
-        return stats.toString();
-    }
-
-    /**
-     * Shutdown callback from composite cache manager.
-     * <p>
-     * @see org.apache.commons.jcs.engine.behavior.IShutdownObserver#shutdown()
-     */
-    public void shutdown()
-    {
-        if ( log.isInfoEnabled() )
-        {
-            log.info( "Observed shutdown request." );
-        }
-        //release();
-    }
-
-    /**
-     * Logs an event if an event logger is configured.
-     * <p>
-     * @param source
-     * @param eventName
-     * @param optionalDetails
-     */
-    protected void logApplicationEvent( String source, String eventName, String optionalDetails )
-    {
-        if ( cacheEventLogger != null )
-        {
-            cacheEventLogger.logApplicationEvent( source, eventName, optionalDetails );
-        }
-    }
-}
+package org.apache.commons.jcs.auxiliary.remote.http.client;
+
+/*
+ * 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.
+ */
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.jcs.auxiliary.AuxiliaryCacheManager;
+import org.apache.commons.jcs.auxiliary.remote.RemoteCacheNoWait;
+import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes;
+import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheClient;
+import org.apache.commons.jcs.auxiliary.remote.http.client.behavior.IRemoteHttpCacheClient;
+import org.apache.commons.jcs.engine.behavior.ICompositeCacheManager;
+import org.apache.commons.jcs.engine.behavior.IElementSerializer;
+import org.apache.commons.jcs.engine.behavior.IShutdownObserver;
+import org.apache.commons.jcs.engine.control.CompositeCacheManager;
+import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
+import org.apache.commons.jcs.utils.config.OptionConverter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * This is a very crude copy of the RMI remote manager. It needs a lot of work!
+ */
+public class RemoteHttpCacheManager
+    implements AuxiliaryCacheManager, IShutdownObserver
+{
+    /** Don't change */
+    private static final long serialVersionUID = 798077557166389498L;
+
+    /** The logger */
+    private final static Log log = LogFactory.getLog( RemoteHttpCacheManager.class );
+
+    /** Contains mappings of Location instance to RemoteCacheManager instance. */
+    private static RemoteHttpCacheManager instance;
+
+    /** Contains instances of RemoteCacheNoWait managed by a RemoteCacheManager instance. */
+    static final Map<String, RemoteCacheNoWait<? extends Serializable, ? extends Serializable>> caches =
+        new HashMap<String, RemoteCacheNoWait<? extends Serializable, ? extends Serializable>>();
+
+    /** The configuration attributes. */
+    private IRemoteCacheAttributes remoteCacheAttributes;
+
+    /** The event logger. */
+    private final ICacheEventLogger cacheEventLogger;
+
+    /** The serializer. */
+    private final IElementSerializer elementSerializer;
+
+    /** The cache manager listeners will need to use to get a cache. */
+    private final ICompositeCacheManager cacheMgr;
+
+    /** Remote cache monitor. */
+    private static RemoteHttpCacheMonitor monitor;
+
+    /**
+     * Constructs an instance to with the given remote connection parameters. If the connection
+     * cannot be made, "zombie" services will be temporarily used until a successful re-connection
+     * is made by the monitoring daemon.
+     * <p>
+     * @param cacheMgr
+     * @param cacheEventLogger
+     * @param elementSerializer
+     */
+    private RemoteHttpCacheManager( ICompositeCacheManager cacheMgr, ICacheEventLogger cacheEventLogger,
+                                    IElementSerializer elementSerializer )
+    {
+        this.cacheMgr = cacheMgr;
+        this.cacheEventLogger = cacheEventLogger;
+        this.elementSerializer = elementSerializer;
+
+        // register shutdown observer
+        // TODO add the shutdown observable methods to the interface
+        if ( this.cacheMgr instanceof CompositeCacheManager )
+        {
+            ( (CompositeCacheManager) this.cacheMgr ).registerShutdownObserver( this );
+        }
+    }
+
+    /**
+     * Gets the defaultCattr attribute of the RemoteCacheManager object.
+     * <p>
+     * @return The defaultCattr value
+     */
+    public IRemoteCacheAttributes getDefaultCattr()
+    {
+        return this.remoteCacheAttributes;
+    }
+
+    /** @return Returns an instance if it exists. else null. */
+    public synchronized static RemoteHttpCacheManager getInstance()
+    {
+        return instance;
+    }
+
+    /**
+     * Get the singleton instance.
+     * <p>
+     * @param cacheMgr
+     * @param cacheEventLogger
+     * @param elementSerializer
+     * @return The instance value
+     */
+    public synchronized static RemoteHttpCacheManager getInstance( ICompositeCacheManager cacheMgr,
+                                                                   ICacheEventLogger cacheEventLogger,
+                                                                   IElementSerializer elementSerializer )
+    {
+        if ( instance == null )
+        {
+            instance = new RemoteHttpCacheManager( cacheMgr, cacheEventLogger, elementSerializer );
+        }
+
+        // Fires up the monitoring daemon.
+        if ( monitor == null )
+        {
+            monitor = RemoteHttpCacheMonitor.getInstance();
+            // If the returned monitor is null, it means it's already started
+            // elsewhere.
+            if ( monitor != null )
+            {
+                Thread t = new Thread( monitor );
+                t.setDaemon( true );
+                t.start();
+            }
+        }
+
+        return instance;
+    }
+
+    /**
+     * Returns a remote cache for the given cache name.
+     * <p>
+     * @param cacheName
+     * @return The cache value
+     */
+    public <K extends Serializable, V extends Serializable> RemoteCacheNoWait<K, V> getCache( String cacheName )
+    {
+        // TODO get some defaults!
+        // Perhaps we will need a manager per URL????
+        RemoteHttpCacheAttributes ca = new RemoteHttpCacheAttributes();
+        ca.setCacheName( cacheName );
+        return getCache( ca );
+    }
+
+    /**
+     * Gets a RemoteCacheNoWait from the RemoteCacheManager. The RemoteCacheNoWait objects are
+     * identified by the cache name value of the RemoteCacheAttributes object.
+     * <p>
+     * If the client is configured to register a listener, this call results on a listener being
+     * created if one isn't already registered with the remote cache for this region.
+     * <p>
+     * @param cattr
+     * @return The cache value
+     */
+    public <K extends Serializable, V extends Serializable> RemoteCacheNoWait<K, V> getCache( RemoteHttpCacheAttributes cattr )
+    {
+        RemoteCacheNoWait<K, V> remoteCacheNoWait = null;
+
+        synchronized ( caches )
+        {
+            @SuppressWarnings("unchecked") // Need to cast because of common map for all caches
+            RemoteCacheNoWait<K, V> remoteCacheNoWait2 = (RemoteCacheNoWait<K, V>) caches.get( cattr.getCacheName() + cattr.getUrl() );
+            remoteCacheNoWait = remoteCacheNoWait2;
+            if ( remoteCacheNoWait == null )
+            {
+                RemoteHttpClientListener<K, V> listener = new RemoteHttpClientListener<K, V>( cattr, cacheMgr );
+
+                IRemoteHttpCacheClient<K, V> remoteService = createRemoteHttpCacheClientForAttributes( cattr );
+
+                IRemoteCacheClient<K, V> remoteCacheClient = new RemoteHttpCache<K, V>( cattr, remoteService, listener );
+                remoteCacheClient.setCacheEventLogger( cacheEventLogger );
+                remoteCacheClient.setElementSerializer( elementSerializer );
+
+                remoteCacheNoWait = new RemoteCacheNoWait<K, V>( remoteCacheClient );
+                remoteCacheNoWait.setCacheEventLogger( cacheEventLogger );
+                remoteCacheNoWait.setElementSerializer( elementSerializer );
+
+                caches.put( cattr.getCacheName() + cattr.getUrl(), remoteCacheNoWait );
+            }
+            // might want to do some listener sanity checking here.
+        }
+
+        return remoteCacheNoWait;
+    }
+
+    /**
+     * This is an extension point. The manager and other classes will only create
+     * RemoteHttpCacheClient through this method.
+     * <p>
+     * @param cattr
+     * @return IRemoteHttpCacheClient
+     */
+    protected <K extends Serializable, V extends Serializable> IRemoteHttpCacheClient<K, V> createRemoteHttpCacheClientForAttributes( RemoteHttpCacheAttributes cattr )
+    {
+        IRemoteHttpCacheClient<K, V> client = OptionConverter.instantiateByClassName( cattr
+            .getRemoteHttpClientClassName(), null );
+
+        if ( client == null )
+        {
+            if ( log.isInfoEnabled() )
+            {
+                log.info( "Creating the default client." );
+            }
+            client = new RemoteHttpCacheClient<K, V>( );
+        }
+        client.initialize( cattr );
+        return client;
+    }
+
+    /**
+     * Gets the stats attribute of the RemoteCacheManager object
+     * <p>
+     * @return The stats value
+     */
+    public String getStats()
+    {
+        StringBuffer stats = new StringBuffer();
+        for (RemoteCacheNoWait<?, ?> c : caches.values())
+        {
+            if ( c != null )
+            {
+                stats.append( c.getCacheName() );
+            }
+        }
+        return stats.toString();
+    }
+
+    /**
+     * Shutdown callback from composite cache manager.
+     * <p>
+     * @see org.apache.commons.jcs.engine.behavior.IShutdownObserver#shutdown()
+     */
+    public void shutdown()
+    {
+        if ( log.isInfoEnabled() )
+        {
+            log.info( "Observed shutdown request." );
+        }
+        //release();
+    }
+
+    /**
+     * Logs an event if an event logger is configured.
+     * <p>
+     * @param source
+     * @param eventName
+     * @param optionalDetails
+     */
+    protected void logApplicationEvent( String source, String eventName, String optionalDetails )
+    {
+        if ( cacheEventLogger != null )
+        {
+            cacheEventLogger.logApplicationEvent( source, eventName, optionalDetails );
+        }
+    }
+}



Mime
View raw message