commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1570993 [9/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/server/RemoteHttpCacheService.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/server/RemoteHttpCacheService.java?rev=1570993&r1=1570992&r2=1570993&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/server/RemoteHttpCacheService.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/server/RemoteHttpCacheService.java Sun Feb 23 10:37:48 2014
@@ -1,269 +1,269 @@
-package org.apache.commons.jcs.auxiliary.remote.http.server;
-
-/*
- * 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.Map;
-import java.util.Set;
-
-import org.apache.commons.jcs.engine.behavior.ICacheElement;
-import org.apache.commons.jcs.engine.behavior.ICompositeCacheManager;
-import org.apache.commons.jcs.engine.control.CompositeCache;
-import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
-
-/**
- * This does the work. It's called by the processor. The base class wraps the processing calls in
- * event logs, if an event logger is present.
- * <p>
- * For now we assume that all clients are non-cluster clients. And listener notification is not
- * supported.
- */
-public class RemoteHttpCacheService<K extends Serializable, V extends Serializable>
-    extends AbstractRemoteCacheService<K, V>
-{
-    /** The name used in the event logs. */
-    private static final String EVENT_LOG_SOURCE_NAME = "RemoteHttpCacheServer";
-
-    /** The configuration */
-    private final RemoteHttpCacheServerAttributes remoteHttpCacheServerAttributes;
-
-    /**
-     * Create a process with a cache manager.
-     * <p>
-     * @param cacheManager
-     * @param remoteHttpCacheServerAttributes
-     * @param cacheEventLogger
-     */
-    public RemoteHttpCacheService( ICompositeCacheManager cacheManager,
-                                   RemoteHttpCacheServerAttributes remoteHttpCacheServerAttributes,
-                                   ICacheEventLogger cacheEventLogger )
-    {
-        super( cacheManager, cacheEventLogger );
-        setEventLogSourceName( EVENT_LOG_SOURCE_NAME );
-        this.remoteHttpCacheServerAttributes = remoteHttpCacheServerAttributes;
-    }
-
-    /**
-     * Processes a get request.
-     * <p>
-     * If isAllowClusterGet is enabled we will treat this as a normal request or non-remote origins.
-     * <p>
-     * @param cacheName
-     * @param key
-     * @param requesterId
-     * @return ICacheElement
-     * @throws IOException
-     */
-    @Override
-    public ICacheElement<K, V> processGet( String cacheName, K key, long requesterId )
-        throws IOException
-    {
-        CompositeCache<K, V> cache = getCacheManager().getCache( cacheName );
-
-        boolean keepLocal = !remoteHttpCacheServerAttributes.isAllowClusterGet();
-        if ( keepLocal )
-        {
-            return cache.localGet( key );
-        }
-        else
-        {
-            return cache.get( key );
-        }
-    }
-
-    /**
-     * Processes a get request.
-     * <p>
-     * If isAllowClusterGet is enabled we will treat this as a normal request of non-remote
-     * origination.
-     * <p>
-     * @param cacheName
-     * @param keys
-     * @param requesterId
-     * @return Map
-     * @throws IOException
-     */
-    @Override
-    public Map<K, ICacheElement<K, V>> processGetMultiple( String cacheName, Set<K> keys, long requesterId )
-        throws IOException
-    {
-        CompositeCache<K, V> cache = getCacheManager().getCache( cacheName );
-
-        boolean keepLocal = !remoteHttpCacheServerAttributes.isAllowClusterGet();
-        if ( keepLocal )
-        {
-            return cache.localGetMultiple( keys );
-        }
-        else
-        {
-            return cache.getMultiple( keys );
-        }
-    }
-
-    /**
-     * Processes a get request.
-     * <p>
-     * If isAllowClusterGet is enabled we will treat this as a normal request of non-remote
-     * origination.
-     * <p>
-     * @param cacheName
-     * @param pattern
-     * @param requesterId
-     * @return Map
-     * @throws IOException
-     */
-    @Override
-    public Map<K, ICacheElement<K, V>> processGetMatching( String cacheName, String pattern, long requesterId )
-        throws IOException
-    {
-        CompositeCache<K, V> cache = getCacheManager().getCache( cacheName );
-
-        boolean keepLocal = !remoteHttpCacheServerAttributes.isAllowClusterGet();
-        if ( keepLocal )
-        {
-            return cache.localGetMatching( pattern );
-        }
-        else
-        {
-            return cache.getMatching( pattern );
-        }
-    }
-
-    /**
-     * Processes an update request.
-     * <p>
-     * If isLocalClusterConsistency is enabled we will treat this as a normal request of non-remote
-     * origination.
-     * <p>
-     * @param item
-     * @param requesterId
-     * @throws IOException
-     */
-    @Override
-    public void processUpdate( ICacheElement<K, V> item, long requesterId )
-        throws IOException
-    {
-        CompositeCache<K, V> cache = getCacheManager().getCache( item.getCacheName() );
-
-        boolean keepLocal = !remoteHttpCacheServerAttributes.isLocalClusterConsistency();
-        if ( keepLocal )
-        {
-            cache.localUpdate( item );
-        }
-        else
-        {
-            cache.update( item );
-        }
-    }
-
-    /**
-     * Processes a remove request.
-     * <p>
-     * If isLocalClusterConsistency is enabled we will treat this as a normal request of non-remote
-     * origination.
-     * <p>
-     * @param cacheName
-     * @param key
-     * @param requesterId
-     * @throws IOException
-     */
-    @Override
-    public void processRemove( String cacheName, K key, long requesterId )
-        throws IOException
-    {
-        CompositeCache<K, V> cache = getCacheManager().getCache( cacheName );
-
-        boolean keepLocal = !remoteHttpCacheServerAttributes.isLocalClusterConsistency();
-        if ( keepLocal )
-        {
-            cache.localRemove( key );
-        }
-        else
-        {
-            cache.remove( key );
-        }
-    }
-
-    /**
-     * Processes a removeAll request.
-     * <p>
-     * If isLocalClusterConsistency is enabled we will treat this as a normal request of non-remote
-     * origination.
-     * <p>
-     * @param cacheName
-     * @param requesterId
-     * @throws IOException
-     */
-    @Override
-    public void processRemoveAll( String cacheName, long requesterId )
-        throws IOException
-    {
-        CompositeCache<K, V> cache = getCacheManager().getCache( cacheName );
-
-        boolean keepLocal = !remoteHttpCacheServerAttributes.isLocalClusterConsistency();
-        if ( keepLocal )
-        {
-            cache.localRemoveAll();
-        }
-        else
-        {
-            cache.removeAll();
-        }
-    }
-
-    /**
-     * Processes a shutdown request.
-     * <p>
-     * @param cacheName
-     * @param requesterId
-     * @throws IOException
-     */
-    @Override
-    public void processDispose( String cacheName, long requesterId )
-        throws IOException
-    {
-        CompositeCache<K, V> cache = getCacheManager().getCache( cacheName );
-        cache.dispose();
-    }
-
-    /**
-     * This general method should be deprecated.
-     * <p>
-     * @throws IOException
-     */
-    public void release()
-        throws IOException
-    {
-        //nothing.
-    }
-
-    /**
-     * This is called by the event log.
-     * <p>
-     * @param requesterId
-     * @return requesterId + ""
-     */
-    @Override
-    protected String getExtraInfoForRequesterId( long requesterId )
-    {
-        return requesterId + "";
-    }
-}
+package org.apache.commons.jcs.auxiliary.remote.http.server;
+
+/*
+ * 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.Map;
+import java.util.Set;
+
+import org.apache.commons.jcs.engine.behavior.ICacheElement;
+import org.apache.commons.jcs.engine.behavior.ICompositeCacheManager;
+import org.apache.commons.jcs.engine.control.CompositeCache;
+import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
+
+/**
+ * This does the work. It's called by the processor. The base class wraps the processing calls in
+ * event logs, if an event logger is present.
+ * <p>
+ * For now we assume that all clients are non-cluster clients. And listener notification is not
+ * supported.
+ */
+public class RemoteHttpCacheService<K extends Serializable, V extends Serializable>
+    extends AbstractRemoteCacheService<K, V>
+{
+    /** The name used in the event logs. */
+    private static final String EVENT_LOG_SOURCE_NAME = "RemoteHttpCacheServer";
+
+    /** The configuration */
+    private final RemoteHttpCacheServerAttributes remoteHttpCacheServerAttributes;
+
+    /**
+     * Create a process with a cache manager.
+     * <p>
+     * @param cacheManager
+     * @param remoteHttpCacheServerAttributes
+     * @param cacheEventLogger
+     */
+    public RemoteHttpCacheService( ICompositeCacheManager cacheManager,
+                                   RemoteHttpCacheServerAttributes remoteHttpCacheServerAttributes,
+                                   ICacheEventLogger cacheEventLogger )
+    {
+        super( cacheManager, cacheEventLogger );
+        setEventLogSourceName( EVENT_LOG_SOURCE_NAME );
+        this.remoteHttpCacheServerAttributes = remoteHttpCacheServerAttributes;
+    }
+
+    /**
+     * Processes a get request.
+     * <p>
+     * If isAllowClusterGet is enabled we will treat this as a normal request or non-remote origins.
+     * <p>
+     * @param cacheName
+     * @param key
+     * @param requesterId
+     * @return ICacheElement
+     * @throws IOException
+     */
+    @Override
+    public ICacheElement<K, V> processGet( String cacheName, K key, long requesterId )
+        throws IOException
+    {
+        CompositeCache<K, V> cache = getCacheManager().getCache( cacheName );
+
+        boolean keepLocal = !remoteHttpCacheServerAttributes.isAllowClusterGet();
+        if ( keepLocal )
+        {
+            return cache.localGet( key );
+        }
+        else
+        {
+            return cache.get( key );
+        }
+    }
+
+    /**
+     * Processes a get request.
+     * <p>
+     * If isAllowClusterGet is enabled we will treat this as a normal request of non-remote
+     * origination.
+     * <p>
+     * @param cacheName
+     * @param keys
+     * @param requesterId
+     * @return Map
+     * @throws IOException
+     */
+    @Override
+    public Map<K, ICacheElement<K, V>> processGetMultiple( String cacheName, Set<K> keys, long requesterId )
+        throws IOException
+    {
+        CompositeCache<K, V> cache = getCacheManager().getCache( cacheName );
+
+        boolean keepLocal = !remoteHttpCacheServerAttributes.isAllowClusterGet();
+        if ( keepLocal )
+        {
+            return cache.localGetMultiple( keys );
+        }
+        else
+        {
+            return cache.getMultiple( keys );
+        }
+    }
+
+    /**
+     * Processes a get request.
+     * <p>
+     * If isAllowClusterGet is enabled we will treat this as a normal request of non-remote
+     * origination.
+     * <p>
+     * @param cacheName
+     * @param pattern
+     * @param requesterId
+     * @return Map
+     * @throws IOException
+     */
+    @Override
+    public Map<K, ICacheElement<K, V>> processGetMatching( String cacheName, String pattern, long requesterId )
+        throws IOException
+    {
+        CompositeCache<K, V> cache = getCacheManager().getCache( cacheName );
+
+        boolean keepLocal = !remoteHttpCacheServerAttributes.isAllowClusterGet();
+        if ( keepLocal )
+        {
+            return cache.localGetMatching( pattern );
+        }
+        else
+        {
+            return cache.getMatching( pattern );
+        }
+    }
+
+    /**
+     * Processes an update request.
+     * <p>
+     * If isLocalClusterConsistency is enabled we will treat this as a normal request of non-remote
+     * origination.
+     * <p>
+     * @param item
+     * @param requesterId
+     * @throws IOException
+     */
+    @Override
+    public void processUpdate( ICacheElement<K, V> item, long requesterId )
+        throws IOException
+    {
+        CompositeCache<K, V> cache = getCacheManager().getCache( item.getCacheName() );
+
+        boolean keepLocal = !remoteHttpCacheServerAttributes.isLocalClusterConsistency();
+        if ( keepLocal )
+        {
+            cache.localUpdate( item );
+        }
+        else
+        {
+            cache.update( item );
+        }
+    }
+
+    /**
+     * Processes a remove request.
+     * <p>
+     * If isLocalClusterConsistency is enabled we will treat this as a normal request of non-remote
+     * origination.
+     * <p>
+     * @param cacheName
+     * @param key
+     * @param requesterId
+     * @throws IOException
+     */
+    @Override
+    public void processRemove( String cacheName, K key, long requesterId )
+        throws IOException
+    {
+        CompositeCache<K, V> cache = getCacheManager().getCache( cacheName );
+
+        boolean keepLocal = !remoteHttpCacheServerAttributes.isLocalClusterConsistency();
+        if ( keepLocal )
+        {
+            cache.localRemove( key );
+        }
+        else
+        {
+            cache.remove( key );
+        }
+    }
+
+    /**
+     * Processes a removeAll request.
+     * <p>
+     * If isLocalClusterConsistency is enabled we will treat this as a normal request of non-remote
+     * origination.
+     * <p>
+     * @param cacheName
+     * @param requesterId
+     * @throws IOException
+     */
+    @Override
+    public void processRemoveAll( String cacheName, long requesterId )
+        throws IOException
+    {
+        CompositeCache<K, V> cache = getCacheManager().getCache( cacheName );
+
+        boolean keepLocal = !remoteHttpCacheServerAttributes.isLocalClusterConsistency();
+        if ( keepLocal )
+        {
+            cache.localRemoveAll();
+        }
+        else
+        {
+            cache.removeAll();
+        }
+    }
+
+    /**
+     * Processes a shutdown request.
+     * <p>
+     * @param cacheName
+     * @param requesterId
+     * @throws IOException
+     */
+    @Override
+    public void processDispose( String cacheName, long requesterId )
+        throws IOException
+    {
+        CompositeCache<K, V> cache = getCacheManager().getCache( cacheName );
+        cache.dispose();
+    }
+
+    /**
+     * This general method should be deprecated.
+     * <p>
+     * @throws IOException
+     */
+    public void release()
+        throws IOException
+    {
+        //nothing.
+    }
+
+    /**
+     * This is called by the event log.
+     * <p>
+     * @param requesterId
+     * @return requesterId + ""
+     */
+    @Override
+    protected String getExtraInfoForRequesterId( long requesterId )
+    {
+        return requesterId + "";
+    }
+}

Modified: commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/server/RemoteHttpCacheServlet.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/server/RemoteHttpCacheServlet.java?rev=1570993&r1=1570992&r2=1570993&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/server/RemoteHttpCacheServlet.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/server/RemoteHttpCacheServlet.java Sun Feb 23 10:37:48 2014
@@ -1,264 +1,264 @@
-package org.apache.commons.jcs.auxiliary.remote.http.server;
-
-/*
- * 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.InputStream;
-import java.io.ObjectInputStream;
-import java.io.OutputStream;
-import java.io.Serializable;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.jcs.access.exception.CacheException;
-import org.apache.commons.jcs.auxiliary.remote.value.RemoteCacheRequest;
-import org.apache.commons.jcs.auxiliary.remote.value.RemoteCacheResponse;
-import org.apache.commons.jcs.engine.control.CompositeCacheManager;
-import org.apache.commons.jcs.utils.serialization.StandardSerializer;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * This servlet simply reads and writes objects. The requests are packaged in a general wrapper. The
- * processor works on the wrapper object and returns a response wrapper.
- */
-public class RemoteHttpCacheServlet
-    extends HttpServlet
-{
-    /** Don't change. */
-    private static final long serialVersionUID = 8752849397531933346L;
-
-    /** The Logger. */
-    private final static Log log = LogFactory.getLog( RemoteHttpCacheServlet.class );
-
-    /** The cache manager */
-    private static CompositeCacheManager cacheMgr;
-
-    /** Processes requests */
-    private RemoteCacheServiceAdaptor<Serializable, Serializable> remoteHttpCacheServiceAdaptor;
-
-    /** This needs to be standard, since the other side is standard */
-    private final StandardSerializer serializer = new StandardSerializer();
-
-    /** Number of service calls. */
-    private int serviceCalls = 0;
-
-    /** The interval at which we will log the count. */
-    private final int logInterval = 100;
-
-    /**
-     * Initializes the cache.
-     * <p>
-     * This provides an easy extension point. Simply extend this servlet and override the init
-     * method to change the way the properties are loaded.
-     * @param config
-     * @throws ServletException
-     */
-    @Override
-    public void init( ServletConfig config )
-        throws ServletException
-    {
-        try
-        {
-            ensureCacheManager();
-        }
-        catch (CacheException e)
-        {
-            throw new ServletException(e);
-        }
-
-        setRemoteHttpCacheServiceAdaptor( new RemoteCacheServiceAdaptor<Serializable, Serializable>( cacheMgr ) );
-
-        super.init( config );
-    }
-
-    /**
-     * Read the request, call the processor, write the response.
-     * <p>
-     * @param request
-     * @param response
-     * @throws ServletException
-     * @throws IOException
-     */
-    @Override
-    public void service( HttpServletRequest request, HttpServletResponse response )
-        throws ServletException, IOException
-    {
-        incrementServiceCallCount();
-        if ( log.isDebugEnabled() )
-        {
-            log.debug( "Servicing a request. " + request );
-        }
-
-        RemoteCacheRequest<Serializable, Serializable> remoteRequest = readRequest( request );
-        RemoteCacheResponse<Serializable> cacheResponse =
-            getRemoteHttpCacheServiceAdaptor().processRequest( remoteRequest );
-
-        writeResponse( response, cacheResponse );
-    }
-
-    /**
-     * Read the request from the input stream.
-     * <p>
-     * @param request
-     * @return RemoteHttpCacheRequest
-     */
-    protected RemoteCacheRequest<Serializable, Serializable> readRequest( HttpServletRequest request )
-    {
-        RemoteCacheRequest<Serializable, Serializable> remoteRequest = null;
-        try
-        {
-            InputStream inputStream = request.getInputStream();
-            if ( log.isDebugEnabled() )
-            {
-                log.debug( "After getting input stream and before reading it" );
-            }
-
-            remoteRequest = readRequestFromStream( inputStream );
-        }
-        catch ( Exception e )
-        {
-            log.error( "Could not get a RemoteHttpCacheRequest object from the input stream.", e );
-        }
-        return remoteRequest;
-    }
-
-    /**
-     * Reads the response from the stream and then closes it.
-     * <p>
-     * @param inputStream
-     * @return RemoteHttpCacheRequest
-     * @throws IOException
-     * @throws ClassNotFoundException
-     */
-    protected RemoteCacheRequest<Serializable, Serializable> readRequestFromStream( InputStream inputStream )
-        throws IOException, ClassNotFoundException
-    {
-        ObjectInputStream ois = new ObjectInputStream( inputStream );
-
-        @SuppressWarnings("unchecked") // Need to cast from Object
-        RemoteCacheRequest<Serializable, Serializable> remoteRequest
-            = (RemoteCacheRequest<Serializable, Serializable>) ois.readObject();
-        ois.close();
-        return remoteRequest;
-    }
-
-    /**
-     * Write the response to the output stream.
-     * <p>
-     * @param response
-     * @param cacheResponse
-     */
-    protected void writeResponse( HttpServletResponse response, RemoteCacheResponse<Serializable> cacheResponse )
-    {
-        try
-        {
-            response.setContentType( "application/octet-stream" );
-
-            byte[] responseAsByteAray = serializer.serialize( cacheResponse );
-            response.setContentLength( responseAsByteAray.length );
-
-            OutputStream outputStream = response.getOutputStream();
-            if ( log.isDebugEnabled() )
-            {
-                log.debug( "Opened output stream.  Response size: " + responseAsByteAray.length );
-            }
-            // WRITE
-            outputStream.write( responseAsByteAray );
-            outputStream.flush();
-            outputStream.close();
-        }
-        catch ( Exception e )
-        {
-            log.error( "Problem writing response. " + cacheResponse, e );
-        }
-    }
-
-    /**
-     * Log some details.
-     */
-    private void incrementServiceCallCount()
-    {
-        // not thread safe, but it doesn't have to be accurate
-        serviceCalls++;
-        if ( log.isInfoEnabled() )
-        {
-            if ( serviceCalls % logInterval == 0 )
-            {
-                log.info( "serviceCalls = " + serviceCalls );
-            }
-        }
-    }
-
-    /**
-     * Make sure we have a cache manager. This should have happened in the init method.
-     *
-     * @throws CacheException if the configuration cannot be loaded
-     */
-    protected synchronized void ensureCacheManager() throws CacheException
-    {
-        if ( cacheMgr == null )
-        {
-            cacheMgr = CompositeCacheManager.getInstance();
-        }
-    }
-
-    /** Release the cache manager. */
-    @Override
-    public void destroy()
-    {
-        if ( log.isInfoEnabled() )
-        {
-            log.info( "Servlet Destroyed, shutting down JCS." );
-        }
-        cacheMgr.shutDown();
-    }
-
-    /**
-     * Get servlet information
-     * <p>
-     * @return basic info
-     */
-    @Override
-    public String getServletInfo()
-    {
-        return "RemoteHttpCacheServlet";
-    }
-
-    /**
-     * @param remoteHttpCacheProcessor the remoteHttpCacheProcessor to set
-     */
-    public void setRemoteHttpCacheServiceAdaptor( RemoteCacheServiceAdaptor<Serializable, Serializable> remoteHttpCacheProcessor )
-    {
-        this.remoteHttpCacheServiceAdaptor = remoteHttpCacheProcessor;
-    }
-
-    /**
-     * @return the remoteHttpCacheProcessor
-     */
-    public RemoteCacheServiceAdaptor<Serializable, Serializable> getRemoteHttpCacheServiceAdaptor()
-    {
-        return remoteHttpCacheServiceAdaptor;
-    }
-}
+package org.apache.commons.jcs.auxiliary.remote.http.server;
+
+/*
+ * 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.InputStream;
+import java.io.ObjectInputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.jcs.access.exception.CacheException;
+import org.apache.commons.jcs.auxiliary.remote.value.RemoteCacheRequest;
+import org.apache.commons.jcs.auxiliary.remote.value.RemoteCacheResponse;
+import org.apache.commons.jcs.engine.control.CompositeCacheManager;
+import org.apache.commons.jcs.utils.serialization.StandardSerializer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * This servlet simply reads and writes objects. The requests are packaged in a general wrapper. The
+ * processor works on the wrapper object and returns a response wrapper.
+ */
+public class RemoteHttpCacheServlet
+    extends HttpServlet
+{
+    /** Don't change. */
+    private static final long serialVersionUID = 8752849397531933346L;
+
+    /** The Logger. */
+    private final static Log log = LogFactory.getLog( RemoteHttpCacheServlet.class );
+
+    /** The cache manager */
+    private static CompositeCacheManager cacheMgr;
+
+    /** Processes requests */
+    private RemoteCacheServiceAdaptor<Serializable, Serializable> remoteHttpCacheServiceAdaptor;
+
+    /** This needs to be standard, since the other side is standard */
+    private final StandardSerializer serializer = new StandardSerializer();
+
+    /** Number of service calls. */
+    private int serviceCalls = 0;
+
+    /** The interval at which we will log the count. */
+    private final int logInterval = 100;
+
+    /**
+     * Initializes the cache.
+     * <p>
+     * This provides an easy extension point. Simply extend this servlet and override the init
+     * method to change the way the properties are loaded.
+     * @param config
+     * @throws ServletException
+     */
+    @Override
+    public void init( ServletConfig config )
+        throws ServletException
+    {
+        try
+        {
+            ensureCacheManager();
+        }
+        catch (CacheException e)
+        {
+            throw new ServletException(e);
+        }
+
+        setRemoteHttpCacheServiceAdaptor( new RemoteCacheServiceAdaptor<Serializable, Serializable>( cacheMgr ) );
+
+        super.init( config );
+    }
+
+    /**
+     * Read the request, call the processor, write the response.
+     * <p>
+     * @param request
+     * @param response
+     * @throws ServletException
+     * @throws IOException
+     */
+    @Override
+    public void service( HttpServletRequest request, HttpServletResponse response )
+        throws ServletException, IOException
+    {
+        incrementServiceCallCount();
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "Servicing a request. " + request );
+        }
+
+        RemoteCacheRequest<Serializable, Serializable> remoteRequest = readRequest( request );
+        RemoteCacheResponse<Serializable> cacheResponse =
+            getRemoteHttpCacheServiceAdaptor().processRequest( remoteRequest );
+
+        writeResponse( response, cacheResponse );
+    }
+
+    /**
+     * Read the request from the input stream.
+     * <p>
+     * @param request
+     * @return RemoteHttpCacheRequest
+     */
+    protected RemoteCacheRequest<Serializable, Serializable> readRequest( HttpServletRequest request )
+    {
+        RemoteCacheRequest<Serializable, Serializable> remoteRequest = null;
+        try
+        {
+            InputStream inputStream = request.getInputStream();
+            if ( log.isDebugEnabled() )
+            {
+                log.debug( "After getting input stream and before reading it" );
+            }
+
+            remoteRequest = readRequestFromStream( inputStream );
+        }
+        catch ( Exception e )
+        {
+            log.error( "Could not get a RemoteHttpCacheRequest object from the input stream.", e );
+        }
+        return remoteRequest;
+    }
+
+    /**
+     * Reads the response from the stream and then closes it.
+     * <p>
+     * @param inputStream
+     * @return RemoteHttpCacheRequest
+     * @throws IOException
+     * @throws ClassNotFoundException
+     */
+    protected RemoteCacheRequest<Serializable, Serializable> readRequestFromStream( InputStream inputStream )
+        throws IOException, ClassNotFoundException
+    {
+        ObjectInputStream ois = new ObjectInputStream( inputStream );
+
+        @SuppressWarnings("unchecked") // Need to cast from Object
+        RemoteCacheRequest<Serializable, Serializable> remoteRequest
+            = (RemoteCacheRequest<Serializable, Serializable>) ois.readObject();
+        ois.close();
+        return remoteRequest;
+    }
+
+    /**
+     * Write the response to the output stream.
+     * <p>
+     * @param response
+     * @param cacheResponse
+     */
+    protected void writeResponse( HttpServletResponse response, RemoteCacheResponse<Serializable> cacheResponse )
+    {
+        try
+        {
+            response.setContentType( "application/octet-stream" );
+
+            byte[] responseAsByteAray = serializer.serialize( cacheResponse );
+            response.setContentLength( responseAsByteAray.length );
+
+            OutputStream outputStream = response.getOutputStream();
+            if ( log.isDebugEnabled() )
+            {
+                log.debug( "Opened output stream.  Response size: " + responseAsByteAray.length );
+            }
+            // WRITE
+            outputStream.write( responseAsByteAray );
+            outputStream.flush();
+            outputStream.close();
+        }
+        catch ( Exception e )
+        {
+            log.error( "Problem writing response. " + cacheResponse, e );
+        }
+    }
+
+    /**
+     * Log some details.
+     */
+    private void incrementServiceCallCount()
+    {
+        // not thread safe, but it doesn't have to be accurate
+        serviceCalls++;
+        if ( log.isInfoEnabled() )
+        {
+            if ( serviceCalls % logInterval == 0 )
+            {
+                log.info( "serviceCalls = " + serviceCalls );
+            }
+        }
+    }
+
+    /**
+     * Make sure we have a cache manager. This should have happened in the init method.
+     *
+     * @throws CacheException if the configuration cannot be loaded
+     */
+    protected synchronized void ensureCacheManager() throws CacheException
+    {
+        if ( cacheMgr == null )
+        {
+            cacheMgr = CompositeCacheManager.getInstance();
+        }
+    }
+
+    /** Release the cache manager. */
+    @Override
+    public void destroy()
+    {
+        if ( log.isInfoEnabled() )
+        {
+            log.info( "Servlet Destroyed, shutting down JCS." );
+        }
+        cacheMgr.shutDown();
+    }
+
+    /**
+     * Get servlet information
+     * <p>
+     * @return basic info
+     */
+    @Override
+    public String getServletInfo()
+    {
+        return "RemoteHttpCacheServlet";
+    }
+
+    /**
+     * @param remoteHttpCacheProcessor the remoteHttpCacheProcessor to set
+     */
+    public void setRemoteHttpCacheServiceAdaptor( RemoteCacheServiceAdaptor<Serializable, Serializable> remoteHttpCacheProcessor )
+    {
+        this.remoteHttpCacheServiceAdaptor = remoteHttpCacheProcessor;
+    }
+
+    /**
+     * @return the remoteHttpCacheProcessor
+     */
+    public RemoteCacheServiceAdaptor<Serializable, Serializable> getRemoteHttpCacheServiceAdaptor()
+    {
+        return remoteHttpCacheServiceAdaptor;
+    }
+}

Modified: commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/server/RemoteHttpCacheSeviceFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/server/RemoteHttpCacheSeviceFactory.java?rev=1570993&r1=1570992&r2=1570993&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/server/RemoteHttpCacheSeviceFactory.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/server/RemoteHttpCacheSeviceFactory.java Sun Feb 23 10:37:48 2014
@@ -1,91 +1,91 @@
-package org.apache.commons.jcs.auxiliary.remote.http.server;
-
-/*
- * 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.Properties;
-
-import org.apache.commons.jcs.auxiliary.AuxiliaryCacheConfigurator;
-import org.apache.commons.jcs.auxiliary.remote.http.behavior.IRemoteHttpCacheConstants;
-import org.apache.commons.jcs.engine.behavior.ICompositeCacheManager;
-import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
-import org.apache.commons.jcs.utils.config.PropertySetter;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/** Creates the server. */
-public class RemoteHttpCacheSeviceFactory
-{
-    /** The logger */
-    private final static Log log = LogFactory.getLog( RemoteHttpCacheSeviceFactory.class );
-
-    /**
-     * Configures the attributes and the event logger and constructs a service.
-     * <p>
-     * @param cacheManager
-     * @return RemoteHttpCacheService
-     */
-    public static <K extends Serializable, V extends Serializable> RemoteHttpCacheService<K, V> createRemoteHttpCacheService( ICompositeCacheManager cacheManager )
-    {
-        Properties props = cacheManager.getConfigurationProperties();
-        ICacheEventLogger cacheEventLogger = configureCacheEventLogger( props );
-        RemoteHttpCacheServerAttributes attributes = configureRemoteHttpCacheServerAttributes( props );
-
-        RemoteHttpCacheService<K, V> service = new RemoteHttpCacheService<K, V>( cacheManager, attributes, cacheEventLogger );
-        if ( log.isInfoEnabled() )
-        {
-            log.info( "Created new RemoteHttpCacheService " + service );
-        }
-        return service;
-    }
-
-    /**
-     * Tries to get the event logger.
-     * <p>
-     * @param props
-     * @return ICacheEventLogger
-     */
-    protected static ICacheEventLogger configureCacheEventLogger( Properties props )
-    {
-        ICacheEventLogger cacheEventLogger = AuxiliaryCacheConfigurator
-            .parseCacheEventLogger( props, IRemoteHttpCacheConstants.HTTP_CACHE_SERVER_PREFIX );
-
-        return cacheEventLogger;
-    }
-
-    /**
-     * Configure.
-     * <p>
-     * jcs.remotehttpcache.serverattributes.ATTRIBUTENAME=ATTRIBUTEVALUE
-     * <p>
-     * @param prop
-     * @return RemoteCacheServerAttributesconfigureRemoteCacheServerAttributes
-     */
-    protected static RemoteHttpCacheServerAttributes configureRemoteHttpCacheServerAttributes( Properties prop )
-    {
-        RemoteHttpCacheServerAttributes rcsa = new RemoteHttpCacheServerAttributes();
-
-        // configure automatically
-        PropertySetter.setProperties( rcsa, prop,
-                                      IRemoteHttpCacheConstants.HTTP_CACHE_SERVER_ATTRIBUTES_PROPERTY_PREFIX + "." );
-
-        return rcsa;
-    }
-}
+package org.apache.commons.jcs.auxiliary.remote.http.server;
+
+/*
+ * 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.Properties;
+
+import org.apache.commons.jcs.auxiliary.AuxiliaryCacheConfigurator;
+import org.apache.commons.jcs.auxiliary.remote.http.behavior.IRemoteHttpCacheConstants;
+import org.apache.commons.jcs.engine.behavior.ICompositeCacheManager;
+import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
+import org.apache.commons.jcs.utils.config.PropertySetter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/** Creates the server. */
+public class RemoteHttpCacheSeviceFactory
+{
+    /** The logger */
+    private final static Log log = LogFactory.getLog( RemoteHttpCacheSeviceFactory.class );
+
+    /**
+     * Configures the attributes and the event logger and constructs a service.
+     * <p>
+     * @param cacheManager
+     * @return RemoteHttpCacheService
+     */
+    public static <K extends Serializable, V extends Serializable> RemoteHttpCacheService<K, V> createRemoteHttpCacheService( ICompositeCacheManager cacheManager )
+    {
+        Properties props = cacheManager.getConfigurationProperties();
+        ICacheEventLogger cacheEventLogger = configureCacheEventLogger( props );
+        RemoteHttpCacheServerAttributes attributes = configureRemoteHttpCacheServerAttributes( props );
+
+        RemoteHttpCacheService<K, V> service = new RemoteHttpCacheService<K, V>( cacheManager, attributes, cacheEventLogger );
+        if ( log.isInfoEnabled() )
+        {
+            log.info( "Created new RemoteHttpCacheService " + service );
+        }
+        return service;
+    }
+
+    /**
+     * Tries to get the event logger.
+     * <p>
+     * @param props
+     * @return ICacheEventLogger
+     */
+    protected static ICacheEventLogger configureCacheEventLogger( Properties props )
+    {
+        ICacheEventLogger cacheEventLogger = AuxiliaryCacheConfigurator
+            .parseCacheEventLogger( props, IRemoteHttpCacheConstants.HTTP_CACHE_SERVER_PREFIX );
+
+        return cacheEventLogger;
+    }
+
+    /**
+     * Configure.
+     * <p>
+     * jcs.remotehttpcache.serverattributes.ATTRIBUTENAME=ATTRIBUTEVALUE
+     * <p>
+     * @param prop
+     * @return RemoteCacheServerAttributesconfigureRemoteCacheServerAttributes
+     */
+    protected static RemoteHttpCacheServerAttributes configureRemoteHttpCacheServerAttributes( Properties prop )
+    {
+        RemoteHttpCacheServerAttributes rcsa = new RemoteHttpCacheServerAttributes();
+
+        // configure automatically
+        PropertySetter.setProperties( rcsa, prop,
+                                      IRemoteHttpCacheConstants.HTTP_CACHE_SERVER_ATTRIBUTES_PROPERTY_PREFIX + "." );
+
+        return rcsa;
+    }
+}

Modified: commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/server/RegistryKeepAliveRunner.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/server/RegistryKeepAliveRunner.java?rev=1570993&r1=1570992&r2=1570993&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/server/RegistryKeepAliveRunner.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/server/RegistryKeepAliveRunner.java Sun Feb 23 10:37:48 2014
@@ -1,177 +1,196 @@
-package org.apache.commons.jcs.auxiliary.remote.server;
-
-import java.rmi.Naming;
-import java.rmi.RemoteException;
-import java.rmi.registry.LocateRegistry;
-
-import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * This class tries to keep the resitry alive. If if is able to create a registry, it will also
- * rebind the remote cache server.
- */
-public class RegistryKeepAliveRunner
-    implements Runnable
-{
-    /** The logger */
-    private final static Log log = LogFactory.getLog( RegistryKeepAliveRunner.class );
-
-    /** Hostname of the registry */
-    private String registryHost;
-
-    /** the port on which to start the registry */
-    private int registryPort;
-
-    /** The name of the service to look for. */
-    private String serviceName;
-
-    /** An optional event logger */
-    private ICacheEventLogger cacheEventLogger;
-
-    /**
-     * @param registryHost - Hostname of the registry
-     * @param registryPort - the port on which to start the registry
-     * @param serviceName
-     */
-    public RegistryKeepAliveRunner( String registryHost, int registryPort, String serviceName )
-    {
-        this.registryHost = registryHost;
-        this.registryPort = registryPort;
-        this.serviceName = serviceName;
-    }
-
-    /**
-     * Tries to lookup the server. If unsuccessful it will rebind the server using the factory
-     * rebind method.
-     * <p>
-     */
-    public void run()
-    {
-        checkAndRestoreIfNeeded();
-    }
-
-    /**
-     * Tries to lookup the server. If unsuccessful it will rebind the server using the factory
-     * rebind method.
-     */
-    protected void checkAndRestoreIfNeeded()
-    {
-        String registry = "//" + registryHost + ":" + registryPort + "/" + serviceName;
-        if ( log.isDebugEnabled() )
-        {
-            log.debug( "looking up server " + registry );
-        }
-        try
-        {
-            Object obj = Naming.lookup( registry );
-
-            // Successful connection to the remote server.
-            String message = "RMI registry looks fine.  Found [" + obj + "] in registry [" + registry + "]";
-            if ( cacheEventLogger != null )
-            {
-                cacheEventLogger.logApplicationEvent( "RegistryKeepAliveRunner", "Naming.lookup", message );
-            }
-            if ( log.isDebugEnabled() )
-            {
-                log.debug( message );
-            }
-            obj = null;
-        }
-        catch ( Exception ex )
-        {
-            // Failed to connect to the remote server.
-            String message = "Problem finding server at [" + registry
-                + "].  Will attempt to start registry and rebind.";
-            log.error( message, ex );
-            if ( cacheEventLogger != null )
-            {
-                cacheEventLogger.logError( "RegistryKeepAliveRunner", "Naming.lookup", message + ":" + ex.getMessage() );
-            }
-            createAndRegister( registry );
-        }
-    }
-
-    /**
-     * Creates the registry and registers the server.
-     * <p>
-     * @param registry
-     */
-    protected void createAndRegister( String registry )
-    {
-        createReqistry( registry );
-
-        registerServer( registry );
-    }
-
-    /**
-     * Try to create the registry. Log errors
-     * <p>
-     * @param registry
-     */
-    protected void createReqistry( String registry )
-    {
-        try
-        {
-            LocateRegistry.createRegistry( registryPort );
-            String message = "Successfully created registry [" + registry + "].";
-            if ( cacheEventLogger != null )
-            {
-                cacheEventLogger.logApplicationEvent( "RegistryKeepAliveRunner", "createRegistry", message );
-            }
-        }
-        catch ( RemoteException e )
-        {
-            String message = "Could not start registry [" + registry + "].";
-            log.error( message, e );
-            if ( cacheEventLogger != null )
-            {
-                cacheEventLogger.logError( "RegistryKeepAliveRunner", "createRegistry", message + ":" + e.getMessage() );
-            }
-        }
-    }
-
-    /**
-     * Try to rebind the server.
-     * <p>
-     * @param registry
-     */
-    protected void registerServer( String registry )
-    {
-        try
-        {
-            // try to rebind anyway
-            RemoteCacheServerFactory.registerServer( registryHost, registryPort, serviceName );
-            String message = "Successfully rebound server to registry [" + registry + "].";
-            if ( cacheEventLogger != null )
-            {
-                cacheEventLogger.logApplicationEvent( "RegistryKeepAliveRunner", "registerServer", message );
-            }
-            if ( log.isInfoEnabled() )
-            {
-                log.info( message );
-            }
-        }
-        catch ( RemoteException e )
-        {
-            String message = "Could not rebind server to registry [" + registry + "].";
-            log.error( message, e );
-            if ( cacheEventLogger != null )
-            {
-                cacheEventLogger.logError( "RegistryKeepAliveRunner", "registerServer", message + ":"
-                    + e.getMessage() );
-            }
-        }
-    }
-
-    /**
-     * Allows it to be injected.
-     * <p>
-     * @param cacheEventLogger
-     */
-    public void setCacheEventLogger( ICacheEventLogger cacheEventLogger )
-    {
-        this.cacheEventLogger = cacheEventLogger;
-    }
-}
+package org.apache.commons.jcs.auxiliary.remote.server;
+
+/*
+ * 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.rmi.Naming;
+import java.rmi.RemoteException;
+import java.rmi.registry.LocateRegistry;
+
+import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * This class tries to keep the resitry alive. If if is able to create a registry, it will also
+ * rebind the remote cache server.
+ */
+public class RegistryKeepAliveRunner
+    implements Runnable
+{
+    /** The logger */
+    private final static Log log = LogFactory.getLog( RegistryKeepAliveRunner.class );
+
+    /** Hostname of the registry */
+    private String registryHost;
+
+    /** the port on which to start the registry */
+    private int registryPort;
+
+    /** The name of the service to look for. */
+    private String serviceName;
+
+    /** An optional event logger */
+    private ICacheEventLogger cacheEventLogger;
+
+    /**
+     * @param registryHost - Hostname of the registry
+     * @param registryPort - the port on which to start the registry
+     * @param serviceName
+     */
+    public RegistryKeepAliveRunner( String registryHost, int registryPort, String serviceName )
+    {
+        this.registryHost = registryHost;
+        this.registryPort = registryPort;
+        this.serviceName = serviceName;
+    }
+
+    /**
+     * Tries to lookup the server. If unsuccessful it will rebind the server using the factory
+     * rebind method.
+     * <p>
+     */
+    public void run()
+    {
+        checkAndRestoreIfNeeded();
+    }
+
+    /**
+     * Tries to lookup the server. If unsuccessful it will rebind the server using the factory
+     * rebind method.
+     */
+    protected void checkAndRestoreIfNeeded()
+    {
+        String registry = "//" + registryHost + ":" + registryPort + "/" + serviceName;
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "looking up server " + registry );
+        }
+        try
+        {
+            Object obj = Naming.lookup( registry );
+
+            // Successful connection to the remote server.
+            String message = "RMI registry looks fine.  Found [" + obj + "] in registry [" + registry + "]";
+            if ( cacheEventLogger != null )
+            {
+                cacheEventLogger.logApplicationEvent( "RegistryKeepAliveRunner", "Naming.lookup", message );
+            }
+            if ( log.isDebugEnabled() )
+            {
+                log.debug( message );
+            }
+            obj = null;
+        }
+        catch ( Exception ex )
+        {
+            // Failed to connect to the remote server.
+            String message = "Problem finding server at [" + registry
+                + "].  Will attempt to start registry and rebind.";
+            log.error( message, ex );
+            if ( cacheEventLogger != null )
+            {
+                cacheEventLogger.logError( "RegistryKeepAliveRunner", "Naming.lookup", message + ":" + ex.getMessage() );
+            }
+            createAndRegister( registry );
+        }
+    }
+
+    /**
+     * Creates the registry and registers the server.
+     * <p>
+     * @param registry
+     */
+    protected void createAndRegister( String registry )
+    {
+        createReqistry( registry );
+
+        registerServer( registry );
+    }
+
+    /**
+     * Try to create the registry. Log errors
+     * <p>
+     * @param registry
+     */
+    protected void createReqistry( String registry )
+    {
+        try
+        {
+            LocateRegistry.createRegistry( registryPort );
+            String message = "Successfully created registry [" + registry + "].";
+            if ( cacheEventLogger != null )
+            {
+                cacheEventLogger.logApplicationEvent( "RegistryKeepAliveRunner", "createRegistry", message );
+            }
+        }
+        catch ( RemoteException e )
+        {
+            String message = "Could not start registry [" + registry + "].";
+            log.error( message, e );
+            if ( cacheEventLogger != null )
+            {
+                cacheEventLogger.logError( "RegistryKeepAliveRunner", "createRegistry", message + ":" + e.getMessage() );
+            }
+        }
+    }
+
+    /**
+     * Try to rebind the server.
+     * <p>
+     * @param registry
+     */
+    protected void registerServer( String registry )
+    {
+        try
+        {
+            // try to rebind anyway
+            RemoteCacheServerFactory.registerServer( registryHost, registryPort, serviceName );
+            String message = "Successfully rebound server to registry [" + registry + "].";
+            if ( cacheEventLogger != null )
+            {
+                cacheEventLogger.logApplicationEvent( "RegistryKeepAliveRunner", "registerServer", message );
+            }
+            if ( log.isInfoEnabled() )
+            {
+                log.info( message );
+            }
+        }
+        catch ( RemoteException e )
+        {
+            String message = "Could not rebind server to registry [" + registry + "].";
+            log.error( message, e );
+            if ( cacheEventLogger != null )
+            {
+                cacheEventLogger.logError( "RegistryKeepAliveRunner", "registerServer", message + ":"
+                    + e.getMessage() );
+            }
+        }
+    }
+
+    /**
+     * Allows it to be injected.
+     * <p>
+     * @param cacheEventLogger
+     */
+    public void setCacheEventLogger( ICacheEventLogger cacheEventLogger )
+    {
+        this.cacheEventLogger = cacheEventLogger;
+    }
+}

Modified: commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/server/RemoteCacheServer.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/server/RemoteCacheServer.java?rev=1570993&r1=1570992&r2=1570993&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/server/RemoteCacheServer.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/server/RemoteCacheServer.java Sun Feb 23 10:37:48 2014
@@ -1,18 +1,22 @@
 package org.apache.commons.jcs.auxiliary.remote.server;
 
 /*
- * 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
+ * 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
+ *   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.
+ * 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;

Modified: commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/server/RemoteCacheServerAttributes.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/server/RemoteCacheServerAttributes.java?rev=1570993&r1=1570992&r2=1570993&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/server/RemoteCacheServerAttributes.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/server/RemoteCacheServerAttributes.java Sun Feb 23 10:37:48 2014
@@ -1,18 +1,22 @@
 package org.apache.commons.jcs.auxiliary.remote.server;
 
 /*
- * 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
+ * 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
+ *   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.
+ * 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 org.apache.commons.jcs.auxiliary.remote.CommonRemoteCacheAttributes;

Modified: commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/server/TimeoutConfigurableRMIScoketFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/server/TimeoutConfigurableRMIScoketFactory.java?rev=1570993&r1=1570992&r2=1570993&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/server/TimeoutConfigurableRMIScoketFactory.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/server/TimeoutConfigurableRMIScoketFactory.java Sun Feb 23 10:37:48 2014
@@ -1,92 +1,111 @@
-package org.apache.commons.jcs.auxiliary.remote.server;
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.net.InetSocketAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.rmi.server.RMISocketFactory;
-
-/**
- * This can be injected into the the remote cache server as follows:
- * 
- * <pre>
- * jcs.remotecache.customrmisocketfactory=org.apache.commons.jcs.auxiliary.remote.server.TimeoutConfigurableRMIScoketFactory
- * jcs.remotecache.customrmisocketfactory.readTimeout=5000
- * jcs.remotecache.customrmisocketfactory.openTimeout=5000
- * </pre>
- */
-public class TimeoutConfigurableRMIScoketFactory
-    extends RMISocketFactory
-    implements Serializable
-{
-    /** Don't change. */
-    private static final long serialVersionUID = 1489909775271203334L;
-
-    /** The socket read timeout */
-    private int readTimeout = 5000;
-
-    /** The socket open timeout */
-    private int openTimeout = 5000;
-
-    /**
-     * @param port
-     * @return ServerSocket
-     * @throws IOException
-     */
-    @Override
-    public ServerSocket createServerSocket( int port )
-        throws IOException
-    {
-        return new ServerSocket( port );
-    }
-
-    /**
-     * @param host
-     * @param port
-     * @return Socket
-     * @throws IOException
-     */
-    @Override
-    public Socket createSocket( String host, int port )
-        throws IOException
-    {
-        Socket socket = new Socket();
-        socket.setSoTimeout( readTimeout );
-        socket.setSoLinger( false, 0 );
-        socket.connect( new InetSocketAddress( host, port ), openTimeout );
-        return socket;
-    }
-
-    /**
-     * @param readTimeout the readTimeout to set
-     */
-    public void setReadTimeout( int readTimeout )
-    {
-        this.readTimeout = readTimeout;
-    }
-
-    /**
-     * @return the readTimeout
-     */
-    public int getReadTimeout()
-    {
-        return readTimeout;
-    }
-
-    /**
-     * @param openTimeout the openTimeout to set
-     */
-    public void setOpenTimeout( int openTimeout )
-    {
-        this.openTimeout = openTimeout;
-    }
-
-    /**
-     * @return the openTimeout
-     */
-    public int getOpenTimeout()
-    {
-        return openTimeout;
-    }
-}
+package org.apache.commons.jcs.auxiliary.remote.server;
+
+/*
+ * 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.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.rmi.server.RMISocketFactory;
+
+/**
+ * This can be injected into the the remote cache server as follows:
+ *
+ * <pre>
+ * jcs.remotecache.customrmisocketfactory=org.apache.commons.jcs.auxiliary.remote.server.TimeoutConfigurableRMIScoketFactory
+ * jcs.remotecache.customrmisocketfactory.readTimeout=5000
+ * jcs.remotecache.customrmisocketfactory.openTimeout=5000
+ * </pre>
+ */
+public class TimeoutConfigurableRMIScoketFactory
+    extends RMISocketFactory
+    implements Serializable
+{
+    /** Don't change. */
+    private static final long serialVersionUID = 1489909775271203334L;
+
+    /** The socket read timeout */
+    private int readTimeout = 5000;
+
+    /** The socket open timeout */
+    private int openTimeout = 5000;
+
+    /**
+     * @param port
+     * @return ServerSocket
+     * @throws IOException
+     */
+    @Override
+    public ServerSocket createServerSocket( int port )
+        throws IOException
+    {
+        return new ServerSocket( port );
+    }
+
+    /**
+     * @param host
+     * @param port
+     * @return Socket
+     * @throws IOException
+     */
+    @Override
+    public Socket createSocket( String host, int port )
+        throws IOException
+    {
+        Socket socket = new Socket();
+        socket.setSoTimeout( readTimeout );
+        socket.setSoLinger( false, 0 );
+        socket.connect( new InetSocketAddress( host, port ), openTimeout );
+        return socket;
+    }
+
+    /**
+     * @param readTimeout the readTimeout to set
+     */
+    public void setReadTimeout( int readTimeout )
+    {
+        this.readTimeout = readTimeout;
+    }
+
+    /**
+     * @return the readTimeout
+     */
+    public int getReadTimeout()
+    {
+        return readTimeout;
+    }
+
+    /**
+     * @param openTimeout the openTimeout to set
+     */
+    public void setOpenTimeout( int openTimeout )
+    {
+        this.openTimeout = openTimeout;
+    }
+
+    /**
+     * @return the openTimeout
+     */
+    public int getOpenTimeout()
+    {
+        return openTimeout;
+    }
+}

Modified: commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/server/behavior/RemoteType.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/server/behavior/RemoteType.java?rev=1570993&r1=1570992&r2=1570993&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/server/behavior/RemoteType.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/server/behavior/RemoteType.java Sun Feb 23 10:37:48 2014
@@ -29,4 +29,4 @@ public enum RemoteType
 
     /** A remote cache is either a local cache or a cluster cache */
     CLUSTER
-}
\ No newline at end of file
+}

Modified: commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/util/RemoteCacheRequestFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/util/RemoteCacheRequestFactory.java?rev=1570993&r1=1570992&r2=1570993&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/util/RemoteCacheRequestFactory.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/util/RemoteCacheRequestFactory.java Sun Feb 23 10:37:48 2014
@@ -1,236 +1,255 @@
-package org.apache.commons.jcs.auxiliary.remote.util;
-
-import java.io.Serializable;
-import java.util.Set;
-
-import org.apache.commons.jcs.auxiliary.remote.value.RemoteCacheRequest;
-import org.apache.commons.jcs.auxiliary.remote.value.RemoteRequestType;
-import org.apache.commons.jcs.engine.behavior.ICacheElement;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * This creates request objects. You could write your own client and use the objects from this
- * factory.
- */
-public class RemoteCacheRequestFactory
-{
-    /** The Logger. */
-    private final static Log log = LogFactory.getLog( RemoteCacheRequestFactory.class );
-
-    /**
-     * Creates a get Request.
-     * <p>
-     * @param cacheName
-     * @param key
-     * @param requesterId
-     * @return RemoteHttpCacheRequest
-     */
-    public static <K extends Serializable, V extends Serializable> RemoteCacheRequest<K, V> createGetRequest( String cacheName, K key, long requesterId )
-    {
-        RemoteCacheRequest<K, V> request = new RemoteCacheRequest<K, V>();
-        request.setCacheName( cacheName );
-        request.setKey( key );
-        request.setRequesterId( requesterId );
-        request.setRequestType( RemoteRequestType.GET );
-
-        if ( log.isDebugEnabled() )
-        {
-            log.debug( "Created: " + request );
-        }
-
-        return request;
-    }
-
-    /**
-     * Creates a getMatching Request.
-     * <p>
-     * @param cacheName
-     * @param pattern
-     * @param requesterId
-     * @return RemoteHttpCacheRequest
-     */
-    public static <K extends Serializable, V extends Serializable> RemoteCacheRequest<K, V> createGetMatchingRequest( String cacheName, String pattern, long requesterId )
-    {
-        RemoteCacheRequest<K, V> request = new RemoteCacheRequest<K, V>();
-        request.setCacheName( cacheName );
-        request.setPattern( pattern );
-        request.setRequesterId( requesterId );
-        request.setRequestType( RemoteRequestType.GET_MATCHING );
-
-        if ( log.isDebugEnabled() )
-        {
-            log.debug( "Created: " + request );
-        }
-
-        return request;
-    }
-
-    /**
-     * Creates a getMultiple Request.
-     * <p>
-     * @param cacheName
-     * @param keys
-     * @param requesterId
-     * @return RemoteHttpCacheRequest
-     */
-    public static <K extends Serializable, V extends Serializable> RemoteCacheRequest<K, V> createGetMultipleRequest( String cacheName, Set<K> keys, long requesterId )
-    {
-        RemoteCacheRequest<K, V> request = new RemoteCacheRequest<K, V>();
-        request.setCacheName( cacheName );
-        request.setKeySet( keys );
-        request.setRequesterId( requesterId );
-        request.setRequestType( RemoteRequestType.GET_MULTIPLE );
-
-        if ( log.isDebugEnabled() )
-        {
-            log.debug( "Created: " + request );
-        }
-
-        return request;
-    }
-
-    /**
-     * Creates a remove Request.
-     * <p>
-     * @param cacheName
-     * @param key
-     * @param requesterId
-     * @return RemoteHttpCacheRequest
-     */
-    public static <K extends Serializable, V extends Serializable> RemoteCacheRequest<K, V> createRemoveRequest( String cacheName, K key, long requesterId )
-    {
-        RemoteCacheRequest<K, V> request = new RemoteCacheRequest<K, V>();
-        request.setCacheName( cacheName );
-        request.setKey( key );
-        request.setRequesterId( requesterId );
-        request.setRequestType( RemoteRequestType.REMOVE );
-
-        if ( log.isDebugEnabled() )
-        {
-            log.debug( "Created: " + request );
-        }
-
-        return request;
-    }
-
-    /**
-     * Creates a GetKeySet Request.
-     * <p>
-     * @param cacheName
-     * @param requesterId
-     * @return RemoteHttpCacheRequest
-     */
-    public static RemoteCacheRequest<String, String> createGetKeySetRequest( String cacheName, long requesterId )
-    {
-        RemoteCacheRequest<String, String> request = new RemoteCacheRequest<String, String>();
-        request.setCacheName( cacheName );
-        request.setKey( cacheName );
-        request.setRequesterId( requesterId );
-        request.setRequestType( RemoteRequestType.GET_KEYSET );
-
-        if ( log.isDebugEnabled() )
-        {
-            log.debug( "Created: " + request );
-        }
-
-        return request;
-    }
-
-    /**
-     * Creates a removeAll Request.
-     * <p>
-     * @param cacheName
-     * @param requesterId
-     * @return RemoteHttpCacheRequest
-     */
-    public static <K extends Serializable, V extends Serializable> RemoteCacheRequest<K, V> createRemoveAllRequest( String cacheName, long requesterId )
-    {
-        RemoteCacheRequest<K, V> request = new RemoteCacheRequest<K, V>();
-        request.setCacheName( cacheName );
-        request.setRequesterId( requesterId );
-        request.setRequestType( RemoteRequestType.REMOVE_ALL );
-
-        if ( log.isDebugEnabled() )
-        {
-            log.debug( "Created: " + request );
-        }
-
-        return request;
-    }
-
-    /**
-     * Creates a dispose Request.
-     * <p>
-     * @param cacheName
-     * @param requesterId
-     * @return RemoteHttpCacheRequest
-     */
-    public static <K extends Serializable, V extends Serializable> RemoteCacheRequest<K, V> createDisposeRequest( String cacheName, long requesterId )
-    {
-        RemoteCacheRequest<K, V> request = new RemoteCacheRequest<K, V>();
-        request.setCacheName( cacheName );
-        request.setRequesterId( requesterId );
-        request.setRequestType( RemoteRequestType.DISPOSE );
-
-        if ( log.isDebugEnabled() )
-        {
-            log.debug( "Created: " + request );
-        }
-
-        return request;
-    }
-
-    /**
-     * Creates an Update Request.
-     * <p>
-     * @param cacheElement
-     * @param requesterId
-     * @return RemoteHttpCacheRequest
-     */
-    public static <K extends Serializable, V extends Serializable> RemoteCacheRequest<K, V> createUpdateRequest( ICacheElement<K, V> cacheElement, long requesterId )
-    {
-        RemoteCacheRequest<K, V> request = new RemoteCacheRequest<K, V>();
-        if ( cacheElement != null )
-        {
-            request.setCacheName( cacheElement.getCacheName() );
-            request.setCacheElement( cacheElement );
-            request.setKey( cacheElement.getKey() );
-        }
-        else
-        {
-            log.error( "Can't create a proper update request for a null cache element." );
-        }
-        request.setRequesterId( requesterId );
-        request.setRequestType( RemoteRequestType.UPDATE );
-
-        if ( log.isDebugEnabled() )
-        {
-            log.debug( "Created: " + request );
-        }
-
-        return request;
-    }
-
-    /**
-     * Creates an alive check Request.
-     * <p>
-     * @param requesterId
-     * @return RemoteHttpCacheRequest
-     */
-    public static <K extends Serializable, V extends Serializable> RemoteCacheRequest<K, V> createAliveCheckRequest( long requesterId )
-    {
-        RemoteCacheRequest<K, V> request = new RemoteCacheRequest<K, V>();
-        request.setRequesterId( requesterId );
-        request.setRequestType( RemoteRequestType.ALIVE_CHECK );
-
-        if ( log.isDebugEnabled() )
-        {
-            log.debug( "Created: " + request );
-        }
-
-        return request;
-    }
-
-
-}
+package org.apache.commons.jcs.auxiliary.remote.util;
+
+/*
+ * 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.Set;
+
+import org.apache.commons.jcs.auxiliary.remote.value.RemoteCacheRequest;
+import org.apache.commons.jcs.auxiliary.remote.value.RemoteRequestType;
+import org.apache.commons.jcs.engine.behavior.ICacheElement;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * This creates request objects. You could write your own client and use the objects from this
+ * factory.
+ */
+public class RemoteCacheRequestFactory
+{
+    /** The Logger. */
+    private final static Log log = LogFactory.getLog( RemoteCacheRequestFactory.class );
+
+    /**
+     * Creates a get Request.
+     * <p>
+     * @param cacheName
+     * @param key
+     * @param requesterId
+     * @return RemoteHttpCacheRequest
+     */
+    public static <K extends Serializable, V extends Serializable> RemoteCacheRequest<K, V> createGetRequest( String cacheName, K key, long requesterId )
+    {
+        RemoteCacheRequest<K, V> request = new RemoteCacheRequest<K, V>();
+        request.setCacheName( cacheName );
+        request.setKey( key );
+        request.setRequesterId( requesterId );
+        request.setRequestType( RemoteRequestType.GET );
+
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "Created: " + request );
+        }
+
+        return request;
+    }
+
+    /**
+     * Creates a getMatching Request.
+     * <p>
+     * @param cacheName
+     * @param pattern
+     * @param requesterId
+     * @return RemoteHttpCacheRequest
+     */
+    public static <K extends Serializable, V extends Serializable> RemoteCacheRequest<K, V> createGetMatchingRequest( String cacheName, String pattern, long requesterId )
+    {
+        RemoteCacheRequest<K, V> request = new RemoteCacheRequest<K, V>();
+        request.setCacheName( cacheName );
+        request.setPattern( pattern );
+        request.setRequesterId( requesterId );
+        request.setRequestType( RemoteRequestType.GET_MATCHING );
+
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "Created: " + request );
+        }
+
+        return request;
+    }
+
+    /**
+     * Creates a getMultiple Request.
+     * <p>
+     * @param cacheName
+     * @param keys
+     * @param requesterId
+     * @return RemoteHttpCacheRequest
+     */
+    public static <K extends Serializable, V extends Serializable> RemoteCacheRequest<K, V> createGetMultipleRequest( String cacheName, Set<K> keys, long requesterId )
+    {
+        RemoteCacheRequest<K, V> request = new RemoteCacheRequest<K, V>();
+        request.setCacheName( cacheName );
+        request.setKeySet( keys );
+        request.setRequesterId( requesterId );
+        request.setRequestType( RemoteRequestType.GET_MULTIPLE );
+
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "Created: " + request );
+        }
+
+        return request;
+    }
+
+    /**
+     * Creates a remove Request.
+     * <p>
+     * @param cacheName
+     * @param key
+     * @param requesterId
+     * @return RemoteHttpCacheRequest
+     */
+    public static <K extends Serializable, V extends Serializable> RemoteCacheRequest<K, V> createRemoveRequest( String cacheName, K key, long requesterId )
+    {
+        RemoteCacheRequest<K, V> request = new RemoteCacheRequest<K, V>();
+        request.setCacheName( cacheName );
+        request.setKey( key );
+        request.setRequesterId( requesterId );
+        request.setRequestType( RemoteRequestType.REMOVE );
+
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "Created: " + request );
+        }
+
+        return request;
+    }
+
+    /**
+     * Creates a GetKeySet Request.
+     * <p>
+     * @param cacheName
+     * @param requesterId
+     * @return RemoteHttpCacheRequest
+     */
+    public static RemoteCacheRequest<String, String> createGetKeySetRequest( String cacheName, long requesterId )
+    {
+        RemoteCacheRequest<String, String> request = new RemoteCacheRequest<String, String>();
+        request.setCacheName( cacheName );
+        request.setKey( cacheName );
+        request.setRequesterId( requesterId );
+        request.setRequestType( RemoteRequestType.GET_KEYSET );
+
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "Created: " + request );
+        }
+
+        return request;
+    }
+
+    /**
+     * Creates a removeAll Request.
+     * <p>
+     * @param cacheName
+     * @param requesterId
+     * @return RemoteHttpCacheRequest
+     */
+    public static <K extends Serializable, V extends Serializable> RemoteCacheRequest<K, V> createRemoveAllRequest( String cacheName, long requesterId )
+    {
+        RemoteCacheRequest<K, V> request = new RemoteCacheRequest<K, V>();
+        request.setCacheName( cacheName );
+        request.setRequesterId( requesterId );
+        request.setRequestType( RemoteRequestType.REMOVE_ALL );
+
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "Created: " + request );
+        }
+
+        return request;
+    }
+
+    /**
+     * Creates a dispose Request.
+     * <p>
+     * @param cacheName
+     * @param requesterId
+     * @return RemoteHttpCacheRequest
+     */
+    public static <K extends Serializable, V extends Serializable> RemoteCacheRequest<K, V> createDisposeRequest( String cacheName, long requesterId )
+    {
+        RemoteCacheRequest<K, V> request = new RemoteCacheRequest<K, V>();
+        request.setCacheName( cacheName );
+        request.setRequesterId( requesterId );
+        request.setRequestType( RemoteRequestType.DISPOSE );
+
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "Created: " + request );
+        }
+
+        return request;
+    }
+
+    /**
+     * Creates an Update Request.
+     * <p>
+     * @param cacheElement
+     * @param requesterId
+     * @return RemoteHttpCacheRequest
+     */
+    public static <K extends Serializable, V extends Serializable> RemoteCacheRequest<K, V> createUpdateRequest( ICacheElement<K, V> cacheElement, long requesterId )
+    {
+        RemoteCacheRequest<K, V> request = new RemoteCacheRequest<K, V>();
+        if ( cacheElement != null )
+        {
+            request.setCacheName( cacheElement.getCacheName() );
+            request.setCacheElement( cacheElement );
+            request.setKey( cacheElement.getKey() );
+        }
+        else
+        {
+            log.error( "Can't create a proper update request for a null cache element." );
+        }
+        request.setRequesterId( requesterId );
+        request.setRequestType( RemoteRequestType.UPDATE );
+
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "Created: " + request );
+        }
+
+        return request;
+    }
+
+    /**
+     * Creates an alive check Request.
+     * <p>
+     * @param requesterId
+     * @return RemoteHttpCacheRequest
+     */
+    public static <K extends Serializable, V extends Serializable> RemoteCacheRequest<K, V> createAliveCheckRequest( long requesterId )
+    {
+        RemoteCacheRequest<K, V> request = new RemoteCacheRequest<K, V>();
+        request.setRequesterId( requesterId );
+        request.setRequestType( RemoteRequestType.ALIVE_CHECK );
+
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "Created: " + request );
+        }
+
+        return request;
+    }
+
+
+}



Mime
View raw message