commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1408075 - in /commons/proper/jcs/trunk/src: changes/ java/org/apache/jcs/auxiliary/lateral/ java/org/apache/jcs/auxiliary/lateral/socket/tcp/ java/org/apache/jcs/auxiliary/remote/http/client/ java/org/apache/jcs/auxiliary/remote/http/serve...
Date Sun, 11 Nov 2012 18:32:54 GMT
Author: tv
Date: Sun Nov 11 18:32:52 2012
New Revision: 1408075

URL: http://svn.apache.org/viewvc?rev=1408075&view=rev
Log:
More type-safe enums and code re-use

Added:
    commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCommand.java
  (with props)
    commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/value/RemoteRequestType.java
  (with props)
Removed:
    commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestUtil.java
    commons/proper/jcs/trunk/src/test/org/apache/jcs/servlet/
    commons/proper/jcs/trunk/src/test/org/apache/jcs/util/struct/
    commons/proper/jcs/trunk/src/test/org/apache/jcs/utils/match/
Modified:
    commons/proper/jcs/trunk/src/changes/changes.xml
    commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralElementDescriptor.java
    commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPListener.java
    commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPService.java
    commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java
    commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/server/RemoteCacheServiceAdaptor.java
    commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestFactory.java
    commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/value/RemoteCacheRequest.java
    commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java
    commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheClientUnitTest.java
    commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcherUniTest.java
    commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestFactoryUnitTest.java

Modified: commons/proper/jcs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/changes/changes.xml?rev=1408075&r1=1408074&r2=1408075&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/changes/changes.xml (original)
+++ commons/proper/jcs/trunk/src/changes/changes.xml Sun Nov 11 18:32:52 2012
@@ -20,6 +20,9 @@
 	</properties>
 	<body>
 		<release version="2.0" date="unreleased" description="JDK 1.5 based major release">
+            <action dev="tv" type="update">
+                Use type-safe enums instead of integer constants to clean up the code.
+            </action>
             <action dev="tv" type="fix" issue="JCS-91" due-to="Diego Rivera">
                 JCS fails to properly dispose of the lateral TCP listener thread. 
                 If a webapp that uses JCS lateral TCP cache is undeployed, the listener is
left 

Added: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCommand.java?rev=1408075&view=auto
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCommand.java
(added)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCommand.java
Sun Nov 11 18:32:52 2012
@@ -0,0 +1,50 @@
+package org.apache.jcs.auxiliary.lateral;
+
+/*
+ * 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.
+ */
+
+/**
+ * Enumeration of the available lateral commands
+ */
+public enum LateralCommand
+{
+    /** The command for updates */
+    UPDATE,
+
+    /** The command for removes */
+    REMOVE,
+
+    /** The command instructing us to remove all */
+    REMOVEALL,
+
+    /** The command for disposing the cache. */
+    DISPOSE,
+
+    /** Command to return an object. */
+    GET,
+
+    /** Command to return an object. */
+    GET_MATCHING,
+
+    /** Command to get all group keys */
+    GET_GROUP_KEYS,
+
+    /** Command to get all group keys */
+    GET_GROUP_NAMES
+}

Propchange: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralElementDescriptor.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralElementDescriptor.java?rev=1408075&r1=1408074&r2=1408075&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralElementDescriptor.java
(original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/LateralElementDescriptor.java
Sun Nov 11 18:32:52 2012
@@ -34,30 +34,6 @@ public class LateralElementDescriptor<K 
     /** Don't change */
     private static final long serialVersionUID = 5268222498076063575L;
 
-    /** The int for updates */
-    public final static int UPDATE = 1;
-
-    /** The int for removes */
-    public final static int REMOVE = 2;
-
-    /** The int instructing us to remove all */
-    public final static int REMOVEALL = 3;
-
-    /** The int for disposing the cache. */
-    public final static int DISPOSE = 4;
-
-    /** Command to return an object. */
-    public final static int GET = 5;
-
-    /** Command to return an object. */
-    public final static int GET_MATCHING = 6;
-
-    /** Command to get all group keys */
-    public final static int GET_GROUP_KEYS = 7;
-
-    /** Command to get all group keys */
-    public final static int GET_GROUP_NAMES = 8;
-
     /** The Cache Element that we are distributing. */
     public ICacheElement<K, V> ce;
 
@@ -68,7 +44,7 @@ public class LateralElementDescriptor<K 
     public long requesterId;
 
     /** The operation has been requested by the client. */
-    public int command = UPDATE;
+    public LateralCommand command = LateralCommand.UPDATE;
 
     /**
      * The hashcode value for this element.

Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPListener.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPListener.java?rev=1408075&r1=1408074&r2=1408075&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPListener.java
(original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPListener.java
Sun Nov 11 18:32:52 2012
@@ -38,6 +38,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jcs.access.exception.CacheException;
 import org.apache.jcs.auxiliary.lateral.LateralCacheInfo;
+import org.apache.jcs.auxiliary.lateral.LateralCommand;
 import org.apache.jcs.auxiliary.lateral.LateralElementDescriptor;
 import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheListener;
 import org.apache.jcs.auxiliary.lateral.socket.tcp.behavior.ITCPLateralCacheAttributes;
@@ -649,11 +650,11 @@ public class LateralTCPListener<K extend
             String cacheName = led.ce.getCacheName();
             K key = led.ce.getKey();
 
-            if ( led.command == LateralElementDescriptor.UPDATE )
+            if ( led.command == LateralCommand.UPDATE )
             {
                 handlePut( led.ce );
             }
-            else if ( led.command == LateralElementDescriptor.REMOVE )
+            else if ( led.command == LateralCommand.REMOVE )
             {
                 // if a hashcode was given and filtering is on
                 // check to see if they are the same
@@ -687,11 +688,11 @@ public class LateralTCPListener<K extend
                 }
                 handleRemove( cacheName, key );
             }
-            else if ( led.command == LateralElementDescriptor.REMOVEALL )
+            else if ( led.command == LateralCommand.REMOVEALL )
             {
                 handleRemoveAll( cacheName );
             }
-            else if ( led.command == LateralElementDescriptor.GET )
+            else if ( led.command == LateralCommand.GET )
             {
                 Serializable obj = handleGet( cacheName, key );
 
@@ -699,7 +700,7 @@ public class LateralTCPListener<K extend
                 oos.writeObject( obj );
                 oos.flush();
             }
-            else if ( led.command == LateralElementDescriptor.GET_MATCHING )
+            else if ( led.command == LateralCommand.GET_MATCHING )
             {
                 Map<K, ICacheElement<K, V>> obj = handleGetMatching( cacheName,
(String) key );
 
@@ -707,7 +708,7 @@ public class LateralTCPListener<K extend
                 oos.writeObject( obj );
                 oos.flush();
             }
-            else if ( led.command == LateralElementDescriptor.GET_GROUP_KEYS )
+            else if ( led.command == LateralCommand.GET_GROUP_KEYS )
             {
             	String groupName = (String) key;
             	Set<K> obj = handleGetGroupKeys(cacheName, groupName);
@@ -716,7 +717,7 @@ public class LateralTCPListener<K extend
                 oos.writeObject( obj );
                 oos.flush();
             }
-            else if ( led.command == LateralElementDescriptor.GET_GROUP_NAMES )
+            else if ( led.command == LateralCommand.GET_GROUP_NAMES )
             {
             	Set<String> obj = handleGetGroupNames(cacheName);
 

Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPService.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPService.java?rev=1408075&r1=1408074&r2=1408075&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPService.java
(original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPService.java
Sun Nov 11 18:32:52 2012
@@ -31,6 +31,7 @@ import java.util.Set;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jcs.auxiliary.lateral.LateralCacheInfo;
+import org.apache.jcs.auxiliary.lateral.LateralCommand;
 import org.apache.jcs.auxiliary.lateral.LateralElementDescriptor;
 import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheObserver;
 import org.apache.jcs.auxiliary.lateral.socket.tcp.behavior.ITCPLateralCacheAttributes;
@@ -125,7 +126,7 @@ public class LateralTCPService<K extends
         {
             LateralElementDescriptor<K, V> led = new LateralElementDescriptor<K,
V>( item );
             led.requesterId = requesterId;
-            led.command = LateralElementDescriptor.UPDATE;
+            led.command = LateralCommand.UPDATE;
             sender.send( led );
         }
         // else issue a remove with the hashcode for remove check on
@@ -140,7 +141,7 @@ public class LateralTCPService<K extends
             CacheElement<K, V> ce = new CacheElement<K, V>( item.getCacheName(),
item.getKey(), null );
             LateralElementDescriptor<K, V> led = new LateralElementDescriptor<K,
V>( ce );
             led.requesterId = requesterId;
-            led.command = LateralElementDescriptor.REMOVE;
+            led.command = LateralCommand.REMOVE;
             led.valHashCode = item.getVal().hashCode();
             sender.send( led );
         }
@@ -170,7 +171,7 @@ public class LateralTCPService<K extends
         CacheElement<K, V> ce = new CacheElement<K, V>( cacheName, key, null
);
         LateralElementDescriptor<K, V> led = new LateralElementDescriptor<K, V>(
ce );
         led.requesterId = requesterId;
-        led.command = LateralElementDescriptor.REMOVE;
+        led.command = LateralCommand.REMOVE;
         sender.send( led );
     }
 
@@ -247,7 +248,7 @@ public class LateralTCPService<K extends
             CacheElement<K, V> ce = new CacheElement<K, V>( cacheName, key, null
);
             LateralElementDescriptor<K, V> led = new LateralElementDescriptor<K,
V>( ce );
             // led.requesterId = requesterId; // later
-            led.command = LateralElementDescriptor.GET;
+            led.command = LateralCommand.GET;
             @SuppressWarnings("unchecked") // Need to cast from Object
             ICacheElement<K, V> response = (ICacheElement<K, V>)sender.sendAndReceive(
led );
             if ( response != null )
@@ -298,7 +299,7 @@ public class LateralTCPService<K extends
             CacheElement<String, String> ce = new CacheElement<String, String>(
cacheName, pattern, null );
             LateralElementDescriptor<String, String> led = new LateralElementDescriptor<String,
String>( ce );
             // led.requesterId = requesterId; // later
-            led.command = LateralElementDescriptor.GET_MATCHING;
+            led.command = LateralCommand.GET_MATCHING;
 
             Object response = sender.sendAndReceive( led );
             if ( response != null )
@@ -375,7 +376,7 @@ public class LateralTCPService<K extends
         CacheElement<String, String> ce = new CacheElement<String, String>(cacheName,
group, null);
         LateralElementDescriptor<String, String> led = new LateralElementDescriptor<String,
String>(ce);
         // led.requesterId = requesterId; // later
-        led.command = LateralElementDescriptor.GET_GROUP_KEYS;
+        led.command = LateralCommand.GET_GROUP_KEYS;
         Object response = sender.sendAndReceive(led);
         if (response != null)
         {
@@ -400,7 +401,7 @@ public class LateralTCPService<K extends
         CacheElement<String, String> ce = new CacheElement<String, String>(cacheName,
null, null);
         LateralElementDescriptor<String, String> led = new LateralElementDescriptor<String,
String>(ce);
         // led.requesterId = requesterId; // later
-        led.command = LateralElementDescriptor.GET_GROUP_NAMES;
+        led.command = LateralCommand.GET_GROUP_NAMES;
         Object response = sender.sendAndReceive(led);
         if (response != null)
         {
@@ -431,7 +432,7 @@ public class LateralTCPService<K extends
         CacheElement<String, String> ce = new CacheElement<String, String>( cacheName,
"ALL", null );
         LateralElementDescriptor<String, String> led = new LateralElementDescriptor<String,
String>( ce );
         led.requesterId = requesterId;
-        led.command = LateralElementDescriptor.REMOVEALL;
+        led.command = LateralCommand.REMOVEALL;
         sender.send( led );
     }
 

Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java?rev=1408075&r1=1408074&r2=1408075&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java
(original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java
Sun Nov 11 18:32:52 2012
@@ -33,7 +33,6 @@ import org.apache.commons.httpclient.met
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheDispatcher;
-import org.apache.jcs.auxiliary.remote.util.RemoteCacheRequestUtil;
 import org.apache.jcs.auxiliary.remote.value.RemoteCacheRequest;
 import org.apache.jcs.auxiliary.remote.value.RemoteCacheResponse;
 import org.apache.jcs.utils.serialization.StandardSerializer;
@@ -156,25 +155,25 @@ public class RemoteHttpCacheDispatcher
                 String keyValue = "";
                 switch ( remoteCacheRequest.getRequestType() )
                 {
-                    case RemoteCacheRequest.REQUEST_TYPE_GET:
+                    case GET:
                         keyValue = remoteCacheRequest.getKey() + "";
                         break;
-                    case RemoteCacheRequest.REQUEST_TYPE_REMOVE:
+                    case REMOVE:
                         keyValue = remoteCacheRequest.getKey() + "";
                         break;
-                    case RemoteCacheRequest.REQUEST_TYPE_GET_MATCHING:
+                    case GET_MATCHING:
                         keyValue = remoteCacheRequest.getPattern();
                         break;
-                    case RemoteCacheRequest.REQUEST_TYPE_GET_MULTIPLE:
+                    case GET_MULTIPLE:
                         keyValue = remoteCacheRequest.getKeySet() + "";
                         break;
-                    case RemoteCacheRequest.REQUEST_TYPE_GET_GROUP_KEYS:
+                    case GET_GROUP_KEYS:
                         keyValue = remoteCacheRequest.getKey() + "";
                         break;
-                    case RemoteCacheRequest.REQUEST_TYPE_GET_GROUP_NAMES:
+                    case GET_GROUP_NAMES:
                         keyValue = remoteCacheRequest.getKey() + "";
                         break;
-                    case RemoteCacheRequest.REQUEST_TYPE_UPDATE:
+                    case UPDATE:
                         keyValue = remoteCacheRequest.getCacheElement().getKey() + "";
                         break;
                     default:
@@ -188,8 +187,7 @@ public class RemoteHttpCacheDispatcher
                 url.append( "&"
                     + PARAMETER_REQUEST_TYPE
                     + "="
-                    + URLEncoder.encode( RemoteCacheRequestUtil
-                        .getRequestTypeName( remoteCacheRequest.getRequestType() ), "UTF-8"
) );
+                    + URLEncoder.encode( remoteCacheRequest.getRequestType().toString(),
"UTF-8" ) );
             }
         }
         catch ( UnsupportedEncodingException e )

Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/server/RemoteCacheServiceAdaptor.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/server/RemoteCacheServiceAdaptor.java?rev=1408075&r1=1408074&r2=1408075&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/server/RemoteCacheServiceAdaptor.java
(original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/http/server/RemoteCacheServiceAdaptor.java
Sun Nov 11 18:32:52 2012
@@ -87,7 +87,7 @@ public class RemoteCacheServiceAdaptor<K
             {
                 switch ( request.getRequestType() )
                 {
-                    case RemoteCacheRequest.REQUEST_TYPE_GET:
+                    case GET:
                         ICacheElement<K, V> element = getRemoteCacheService().get(
request.getCacheName(), request.getKey(),
                                                                              request.getRequesterId()
);
                         if ( element != null )
@@ -95,7 +95,7 @@ public class RemoteCacheServiceAdaptor<K
                             response.getPayload().put( element.getKey(), element );
                         }
                         break;
-                    case RemoteCacheRequest.REQUEST_TYPE_GET_MULTIPLE:
+                    case GET_MULTIPLE:
                         Map<K, ICacheElement<K, V>> elementMap = getRemoteCacheService().getMultiple(
request.getCacheName(),
                                                                               request.getKeySet(),
                                                                               request.getRequesterId()
);
@@ -104,7 +104,7 @@ public class RemoteCacheServiceAdaptor<K
                             response.getPayload().putAll( elementMap );
                         }
                         break;
-                    case RemoteCacheRequest.REQUEST_TYPE_GET_MATCHING:
+                    case GET_MATCHING:
                         Map<K, ICacheElement<K, V>> elementMapMatching = getRemoteCacheService().getMatching(
request.getCacheName(),
                                                                                       request.getPattern(),
                                                                                       request.getRequesterId()
);
@@ -113,24 +113,24 @@ public class RemoteCacheServiceAdaptor<K
                             response.getPayload().putAll( elementMapMatching );
                         }
                         break;
-                    case RemoteCacheRequest.REQUEST_TYPE_REMOVE:
+                    case REMOVE:
                         getRemoteCacheService().remove( request.getCacheName(), request.getKey(),
                                                         request.getRequesterId() );
                         break;
-                    case RemoteCacheRequest.REQUEST_TYPE_REMOVE_ALL:
+                    case REMOVE_ALL:
                         getRemoteCacheService().removeAll( request.getCacheName(), request.getRequesterId()
);
                         break;
-                    case RemoteCacheRequest.REQUEST_TYPE_UPDATE:
+                    case UPDATE:
                         getRemoteCacheService().update( request.getCacheElement(), request.getRequesterId()
);
                         break;
-                    case RemoteCacheRequest.REQUEST_TYPE_ALIVE_CHECK:
+                    case ALIVE_CHECK:
                         response.setSuccess( true );
                         break;
-                    case RemoteCacheRequest.REQUEST_TYPE_DISPOSE:
+                    case DISPOSE:
                         response.setSuccess( true );
                         // DO NOTHING
                         break;
-                    case RemoteCacheRequest.REQUEST_TYPE_GET_GROUP_KEYS:
+                    case GET_GROUP_KEYS:
                         Set<K> groupKeys = getRemoteCacheService().getGroupKeys( request.getCacheName(),
                                                                               request.getKey()
+ "" );
                         if ( groupKeys == null )
@@ -140,7 +140,7 @@ public class RemoteCacheServiceAdaptor<K
                         // FIXME: Re-enable
                         //response.getPayload().put( request.getKey(), groupKeys );
                         break;
-                    case RemoteCacheRequest.REQUEST_TYPE_GET_GROUP_NAMES:
+                    case GET_GROUP_NAMES:
                         Set<String> groupNames = getRemoteCacheService().getGroupNames(
request.getCacheName() );
                         if ( groupNames == null )
                         {

Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestFactory.java?rev=1408075&r1=1408074&r2=1408075&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestFactory.java
(original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestFactory.java
Sun Nov 11 18:32:52 2012
@@ -6,6 +6,7 @@ import java.util.Set;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jcs.auxiliary.remote.value.RemoteCacheRequest;
+import org.apache.jcs.auxiliary.remote.value.RemoteRequestType;
 import org.apache.jcs.engine.behavior.ICacheElement;
 
 /**
@@ -31,7 +32,7 @@ public class RemoteCacheRequestFactory
         request.setCacheName( cacheName );
         request.setKey( key );
         request.setRequesterId( requesterId );
-        request.setRequestType( RemoteCacheRequest.REQUEST_TYPE_GET );
+        request.setRequestType( RemoteRequestType.GET );
 
         if ( log.isDebugEnabled() )
         {
@@ -55,7 +56,7 @@ public class RemoteCacheRequestFactory
         request.setCacheName( cacheName );
         request.setPattern( pattern );
         request.setRequesterId( requesterId );
-        request.setRequestType( RemoteCacheRequest.REQUEST_TYPE_GET_MATCHING );
+        request.setRequestType( RemoteRequestType.GET_MATCHING );
 
         if ( log.isDebugEnabled() )
         {
@@ -79,7 +80,7 @@ public class RemoteCacheRequestFactory
         request.setCacheName( cacheName );
         request.setKeySet( keys );
         request.setRequesterId( requesterId );
-        request.setRequestType( RemoteCacheRequest.REQUEST_TYPE_GET_MULTIPLE );
+        request.setRequestType( RemoteRequestType.GET_MULTIPLE );
 
         if ( log.isDebugEnabled() )
         {
@@ -103,7 +104,7 @@ public class RemoteCacheRequestFactory
         request.setCacheName( cacheName );
         request.setKey( key );
         request.setRequesterId( requesterId );
-        request.setRequestType( RemoteCacheRequest.REQUEST_TYPE_REMOVE );
+        request.setRequestType( RemoteRequestType.REMOVE );
 
         if ( log.isDebugEnabled() )
         {
@@ -127,7 +128,7 @@ public class RemoteCacheRequestFactory
         request.setCacheName( cacheName );
         request.setKey( groupName );
         request.setRequesterId( requesterId );
-        request.setRequestType( RemoteCacheRequest.REQUEST_TYPE_GET_GROUP_KEYS );
+        request.setRequestType( RemoteRequestType.GET_GROUP_KEYS );
 
         if ( log.isDebugEnabled() )
         {
@@ -150,7 +151,7 @@ public class RemoteCacheRequestFactory
 	    request.setCacheName( cacheName );
 	    request.setKey( cacheName );
 	    request.setRequesterId( requesterId );
-	    request.setRequestType( RemoteCacheRequest.REQUEST_TYPE_GET_GROUP_NAMES );
+	    request.setRequestType( RemoteRequestType.GET_GROUP_NAMES );
 
 	    if ( log.isDebugEnabled() )
 	    {
@@ -172,7 +173,7 @@ public class RemoteCacheRequestFactory
         RemoteCacheRequest<K, V> request = new RemoteCacheRequest<K, V>();
         request.setCacheName( cacheName );
         request.setRequesterId( requesterId );
-        request.setRequestType( RemoteCacheRequest.REQUEST_TYPE_REMOVE_ALL );
+        request.setRequestType( RemoteRequestType.REMOVE_ALL );
 
         if ( log.isDebugEnabled() )
         {
@@ -194,7 +195,7 @@ public class RemoteCacheRequestFactory
         RemoteCacheRequest<K, V> request = new RemoteCacheRequest<K, V>();
         request.setCacheName( cacheName );
         request.setRequesterId( requesterId );
-        request.setRequestType( RemoteCacheRequest.REQUEST_TYPE_DISPOSE );
+        request.setRequestType( RemoteRequestType.DISPOSE );
 
         if ( log.isDebugEnabled() )
         {
@@ -225,7 +226,7 @@ public class RemoteCacheRequestFactory
             log.error( "Can't create a proper update request for a null cache element." );
         }
         request.setRequesterId( requesterId );
-        request.setRequestType( RemoteCacheRequest.REQUEST_TYPE_UPDATE );
+        request.setRequestType( RemoteRequestType.UPDATE );
 
         if ( log.isDebugEnabled() )
         {
@@ -245,7 +246,7 @@ public class RemoteCacheRequestFactory
     {
         RemoteCacheRequest<K, V> request = new RemoteCacheRequest<K, V>();
         request.setRequesterId( requesterId );
-        request.setRequestType( RemoteCacheRequest.REQUEST_TYPE_ALIVE_CHECK );
+        request.setRequestType( RemoteRequestType.ALIVE_CHECK );
 
         if ( log.isDebugEnabled() )
         {

Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/value/RemoteCacheRequest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/value/RemoteCacheRequest.java?rev=1408075&r1=1408074&r2=1408075&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/value/RemoteCacheRequest.java
(original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/value/RemoteCacheRequest.java
Sun Nov 11 18:32:52 2012
@@ -17,38 +17,8 @@ public class RemoteCacheRequest<K extend
     /** Don't change. */
     private static final long serialVersionUID = -8858447417390442569L;
 
-    /** Alive check request type. */
-    public static final byte REQUEST_TYPE_ALIVE_CHECK = 0;
-
-    /** Get request type. */
-    public static final byte REQUEST_TYPE_GET = 1;
-
-    /** Get Multiple request type. */
-    public static final byte REQUEST_TYPE_GET_MULTIPLE = 2;
-
-    /** Get Matching request type. */
-    public static final byte REQUEST_TYPE_GET_MATCHING = 3;
-
-    /** Update request type. */
-    public static final byte REQUEST_TYPE_UPDATE = 4;
-
-    /** Remove request type. */
-    public static final byte REQUEST_TYPE_REMOVE = 5;
-
-    /** Remove All request type. */
-    public static final byte REQUEST_TYPE_REMOVE_ALL = 6;
-
-    /** Get group keys request type. */
-    public static final byte REQUEST_TYPE_GET_GROUP_KEYS = 7;
-
-    /** Dispose request type. */
-    public static final byte REQUEST_TYPE_DISPOSE = 8;
-
-    /** Get group keys request type. */
-    public static final byte REQUEST_TYPE_GET_GROUP_NAMES = 9;
-
     /** The request type specifies the type of request: get, put, remove, . . */
-    private byte requestType = -1;
+    private RemoteRequestType requestType = null;
 
     /** Used to identify the source. Same as listener id on the client side. */
     private long requesterId = 0;
@@ -71,7 +41,7 @@ public class RemoteCacheRequest<K extend
     /**
      * @param requestType the requestType to set
      */
-    public void setRequestType( byte requestType )
+    public void setRequestType( RemoteRequestType requestType )
     {
         this.requestType = requestType;
     }
@@ -79,7 +49,7 @@ public class RemoteCacheRequest<K extend
     /**
      * @return the requestType
      */
-    public byte getRequestType()
+    public RemoteRequestType getRequestType()
     {
         return requestType;
     }

Added: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/value/RemoteRequestType.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/value/RemoteRequestType.java?rev=1408075&view=auto
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/value/RemoteRequestType.java
(added)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/value/RemoteRequestType.java
Sun Nov 11 18:32:52 2012
@@ -0,0 +1,38 @@
+package org.apache.jcs.auxiliary.remote.value;
+
+
+/**
+ * The different types of requests
+ */
+public enum RemoteRequestType
+{
+    /** Alive check request type. */
+    ALIVE_CHECK,
+
+    /** Get request type. */
+    GET,
+
+    /** Get Multiple request type. */
+    GET_MULTIPLE,
+
+    /** Get Matching request type. */
+    GET_MATCHING,
+
+    /** Update request type. */
+    UPDATE,
+
+    /** Remove request type. */
+    REMOVE,
+
+    /** Remove All request type. */
+    REMOVE_ALL,
+
+    /** Get group keys request type. */
+    GET_GROUP_KEYS,
+
+    /** Dispose request type. */
+    DISPOSE,
+
+    /** Get group keys request type. */
+    GET_GROUP_NAMES
+}

Propchange: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/remote/value/RemoteRequestType.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java?rev=1408075&r1=1408074&r2=1408075&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java
(original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java
Sun Nov 11 18:32:52 2012
@@ -26,6 +26,7 @@ import junit.framework.TestCase;
 
 import org.apache.jcs.JCS;
 import org.apache.jcs.auxiliary.lateral.LateralCacheAttributes;
+import org.apache.jcs.auxiliary.lateral.LateralCommand;
 import org.apache.jcs.auxiliary.lateral.LateralElementDescriptor;
 import org.apache.jcs.engine.CacheElement;
 import org.apache.jcs.engine.behavior.ICacheElement;
@@ -88,7 +89,7 @@ public class TestTCPLateralUnitTest
             String message = "adsfasasfasfasdasf";
             CacheElement<String, String> ce = new CacheElement<String, String>(
"test", "test", message );
             LateralElementDescriptor<String, String> led = new LateralElementDescriptor<String,
String>( ce );
-            led.command = LateralElementDescriptor.UPDATE;
+            led.command = LateralCommand.UPDATE;
             led.requesterId = 1;
             lur.send( led );
         }

Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheClientUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheClientUnitTest.java?rev=1408075&r1=1408074&r2=1408075&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheClientUnitTest.java
(original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheClientUnitTest.java
Sun Nov 11 18:32:52 2012
@@ -26,8 +26,8 @@ import java.util.Set;
 
 import junit.framework.TestCase;
 
-import org.apache.jcs.auxiliary.remote.value.RemoteCacheRequest;
 import org.apache.jcs.auxiliary.remote.value.RemoteCacheResponse;
+import org.apache.jcs.auxiliary.remote.value.RemoteRequestType;
 import org.apache.jcs.engine.CacheElement;
 import org.apache.jcs.engine.behavior.ICacheElement;
 
@@ -60,7 +60,7 @@ public class RemoteHttpCacheClientUnitTe
 
         // VERIFY
         assertNull( "Wrong result.", result );
-        assertEquals( "Wrong type.", RemoteCacheRequest.REQUEST_TYPE_GET, mockDispatcher.lastRemoteCacheRequest
+        assertEquals( "Wrong type.", RemoteRequestType.GET, mockDispatcher.lastRemoteCacheRequest
             .getRequestType() );
     }
 
@@ -93,7 +93,7 @@ public class RemoteHttpCacheClientUnitTe
 
         // VERIFY
         assertEquals( "Wrong result.", expected, result );
-        assertEquals( "Wrong type.", RemoteCacheRequest.REQUEST_TYPE_GET, mockDispatcher.lastRemoteCacheRequest
+        assertEquals( "Wrong type.", RemoteRequestType.GET, mockDispatcher.lastRemoteCacheRequest
             .getRequestType() );
     }
 
@@ -126,7 +126,7 @@ public class RemoteHttpCacheClientUnitTe
 
         // VERIFY
         assertEquals( "Wrong result.", expected, result.get( "key" ) );
-        assertEquals( "Wrong type.", RemoteCacheRequest.REQUEST_TYPE_GET_MATCHING,
+        assertEquals( "Wrong type.", RemoteRequestType.GET_MATCHING,
                       mockDispatcher.lastRemoteCacheRequest.getRequestType() );
     }
 
@@ -159,7 +159,7 @@ public class RemoteHttpCacheClientUnitTe
 
         // VERIFY
         assertEquals( "Wrong result.", expected, result.get( "key" ) );
-        assertEquals( "Wrong type.", RemoteCacheRequest.REQUEST_TYPE_GET_MULTIPLE,
+        assertEquals( "Wrong type.", RemoteRequestType.GET_MULTIPLE,
                       mockDispatcher.lastRemoteCacheRequest.getRequestType() );
     }
 
@@ -185,7 +185,7 @@ public class RemoteHttpCacheClientUnitTe
         client.remove( cacheName, key );
 
         // VERIFY
-        assertEquals( "Wrong type.", RemoteCacheRequest.REQUEST_TYPE_REMOVE, mockDispatcher.lastRemoteCacheRequest
+        assertEquals( "Wrong type.", RemoteRequestType.REMOVE, mockDispatcher.lastRemoteCacheRequest
             .getRequestType() );
     }
 
@@ -210,7 +210,7 @@ public class RemoteHttpCacheClientUnitTe
         client.removeAll( cacheName );
 
         // VERIFY
-        assertEquals( "Wrong type.", RemoteCacheRequest.REQUEST_TYPE_REMOVE_ALL, mockDispatcher.lastRemoteCacheRequest
+        assertEquals( "Wrong type.", RemoteRequestType.REMOVE_ALL, mockDispatcher.lastRemoteCacheRequest
             .getRequestType() );
     }
 
@@ -237,7 +237,7 @@ public class RemoteHttpCacheClientUnitTe
         client.update( element );
 
         // VERIFY
-        assertEquals( "Wrong type.", RemoteCacheRequest.REQUEST_TYPE_UPDATE, mockDispatcher.lastRemoteCacheRequest
+        assertEquals( "Wrong type.", RemoteRequestType.UPDATE, mockDispatcher.lastRemoteCacheRequest
             .getRequestType() );
     }
 
@@ -262,7 +262,7 @@ public class RemoteHttpCacheClientUnitTe
         client.dispose( cacheName );
 
         // VERIFY
-        assertEquals( "Wrong type.", RemoteCacheRequest.REQUEST_TYPE_DISPOSE, mockDispatcher.lastRemoteCacheRequest
+        assertEquals( "Wrong type.", RemoteRequestType.DISPOSE, mockDispatcher.lastRemoteCacheRequest
             .getRequestType() );
     }
 }

Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcherUniTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcherUniTest.java?rev=1408075&r1=1408074&r2=1408075&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcherUniTest.java
(original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcherUniTest.java
Sun Nov 11 18:32:52 2012
@@ -3,6 +3,7 @@ package org.apache.jcs.auxiliary.remote.
 import junit.framework.TestCase;
 
 import org.apache.jcs.auxiliary.remote.value.RemoteCacheRequest;
+import org.apache.jcs.auxiliary.remote.value.RemoteRequestType;
 
 /** Unit tests for the dispatcher. */
 public class RemoteHttpCacheDispatcherUniTest
@@ -18,7 +19,7 @@ public class RemoteHttpCacheDispatcherUn
         RemoteHttpCacheDispatcher dispatcher = new RemoteHttpCacheDispatcher( remoteHttpCacheAttributes
);
 
         RemoteCacheRequest<String, String> remoteCacheRequest = new RemoteCacheRequest<String,
String>();
-        remoteCacheRequest.setRequestType( RemoteCacheRequest.REQUEST_TYPE_REMOVE_ALL );
+        remoteCacheRequest.setRequestType( RemoteRequestType.REMOVE_ALL );
         String cacheName = "myCache";
         remoteCacheRequest.setCacheName( cacheName );
 
@@ -28,6 +29,6 @@ public class RemoteHttpCacheDispatcherUn
         String result = dispatcher.addParameters( remoteCacheRequest, baseUrl );
 
         // VERIFY
-        assertEquals( "Wrong url", baseUrl + "&CacheName=" + cacheName + "&Key=&RequestType=RemoveAll",
result  );
+        assertEquals( "Wrong url", baseUrl + "&CacheName=" + cacheName + "&Key=&RequestType=REMOVE_ALL",
result  );
     }
 }

Modified: commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestFactoryUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestFactoryUnitTest.java?rev=1408075&r1=1408074&r2=1408075&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestFactoryUnitTest.java
(original)
+++ commons/proper/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/util/RemoteCacheRequestFactoryUnitTest.java
Sun Nov 11 18:32:52 2012
@@ -7,6 +7,7 @@ import java.util.Set;
 import junit.framework.TestCase;
 
 import org.apache.jcs.auxiliary.remote.value.RemoteCacheRequest;
+import org.apache.jcs.auxiliary.remote.value.RemoteRequestType;
 import org.apache.jcs.engine.CacheElement;
 
 /** Unit tests for the request creator. */
@@ -28,7 +29,7 @@ public class RemoteCacheRequestFactoryUn
         // VERIFY
         assertNotNull( "Should have a result", result );
         assertEquals( "Wrong cacheName", cacheName, result.getCacheName() );
-        assertEquals( "Wrong type", RemoteCacheRequest.REQUEST_TYPE_GET, result.getRequestType()
);
+        assertEquals( "Wrong type", RemoteRequestType.GET, result.getRequestType() );
     }
 
     /** Simple test */
@@ -46,7 +47,7 @@ public class RemoteCacheRequestFactoryUn
         // VERIFY
         assertNotNull( "Should have a result", result );
         assertEquals( "Wrong cacheName", cacheName, result.getCacheName() );
-        assertEquals( "Wrong type", RemoteCacheRequest.REQUEST_TYPE_GET_MATCHING, result.getRequestType()
);
+        assertEquals( "Wrong type", RemoteRequestType.GET_MATCHING, result.getRequestType()
);
     }
 
     /** Simple test */
@@ -64,7 +65,7 @@ public class RemoteCacheRequestFactoryUn
         // VERIFY
         assertNotNull( "Should have a result", result );
         assertEquals( "Wrong cacheName", cacheName, result.getCacheName() );
-        assertEquals( "Wrong type", RemoteCacheRequest.REQUEST_TYPE_GET_MULTIPLE, result.getRequestType()
);
+        assertEquals( "Wrong type", RemoteRequestType.GET_MULTIPLE, result.getRequestType()
);
     }
 
     /** Simple test */
@@ -82,7 +83,7 @@ public class RemoteCacheRequestFactoryUn
         // VERIFY
         assertNotNull( "Should have a result", result );
         assertEquals( "Wrong cacheName", cacheName, result.getCacheName() );
-        assertEquals( "Wrong type", RemoteCacheRequest.REQUEST_TYPE_REMOVE, result.getRequestType()
);
+        assertEquals( "Wrong type", RemoteRequestType.REMOVE, result.getRequestType() );
     }
 
     /** Simple test */
@@ -99,7 +100,7 @@ public class RemoteCacheRequestFactoryUn
         // VERIFY
         assertNotNull( "Should have a result", result );
         assertEquals( "Wrong cacheName", cacheName, result.getCacheName() );
-        assertEquals( "Wrong type", RemoteCacheRequest.REQUEST_TYPE_REMOVE_ALL, result.getRequestType()
);
+        assertEquals( "Wrong type", RemoteRequestType.REMOVE_ALL, result.getRequestType()
);
     }
 
     /** Simple test */
@@ -120,6 +121,6 @@ public class RemoteCacheRequestFactoryUn
         // VERIFY
         assertNotNull( "Should have a result", result );
         assertEquals( "Wrong cacheName", cacheName, result.getCacheName() );
-        assertEquals( "Wrong type", RemoteCacheRequest.REQUEST_TYPE_UPDATE, result.getRequestType()
);
+        assertEquals( "Wrong type", RemoteRequestType.UPDATE, result.getRequestType() );
     }
 }



Mime
View raw message