This is an automated email from the ASF dual-hosted git repository. tv pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-jcs.git
commit b58165f42c9f69573d4bf0742029562a320245f4 Author: Thomas Vandahl <[email protected]> AuthorDate: Mon Feb 16 16:19:47 2026 +0100 More records --- .../remote/http/client/RemoteHttpCacheClient.java | 12 +- .../http/client/RemoteHttpCacheDispatcher.java | 18 +- .../remote/http/server/RemoteHttpCacheServlet.java | 47 +++--- .../remote/util/RemoteCacheRequestFactory.java | 54 ++---- .../auxiliary/remote/value/RemoteCacheRequest.java | 183 ++++++++------------- .../remote/value/RemoteCacheResponse.java | 80 +++------ .../http/client/RemoteHttpCacheClientUnitTest.java | 25 ++- .../server/RemoteHttpCacheServletUnitTest.java | 2 +- .../util/RemoteCacheRequestFactoryUnitTest.java | 24 +-- 9 files changed, 172 insertions(+), 273 deletions(-) diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/client/RemoteHttpCacheClient.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/client/RemoteHttpCacheClient.java index c4ee4048..026645b9 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/client/RemoteHttpCacheClient.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/client/RemoteHttpCacheClient.java @@ -133,7 +133,7 @@ public class RemoteHttpCacheClient<K, V> if ( remoteHttpCacheResponse != null) { - return remoteHttpCacheResponse.getPayload(); + return remoteHttpCacheResponse.payload(); } return null; @@ -160,9 +160,9 @@ public class RemoteHttpCacheClient<K, V> final RemoteCacheResponse<Set<K>> remoteHttpCacheResponse = getRemoteDispatcher().dispatchRequest( remoteHttpCacheRequest ); - if ( remoteHttpCacheResponse != null && remoteHttpCacheResponse.getPayload() != null ) + if ( remoteHttpCacheResponse != null && remoteHttpCacheResponse.payload() != null ) { - return remoteHttpCacheResponse.getPayload(); + return remoteHttpCacheResponse.payload(); } return Collections.emptySet(); @@ -213,7 +213,7 @@ public class RemoteHttpCacheClient<K, V> log.debug( "GetMatching [{0}] = {1}", pattern, remoteHttpCacheResponse ); - return remoteHttpCacheResponse.getPayload(); + return remoteHttpCacheResponse.payload(); } /** @@ -261,7 +261,7 @@ public class RemoteHttpCacheClient<K, V> log.debug( "GetMultiple [{0}] = {1}", keys, remoteHttpCacheResponse ); - return remoteHttpCacheResponse.getPayload(); + return remoteHttpCacheResponse.payload(); } /** @@ -318,7 +318,7 @@ public class RemoteHttpCacheClient<K, V> if ( remoteHttpCacheResponse != null ) { - return remoteHttpCacheResponse.isSuccess(); + return remoteHttpCacheResponse.success(); } return false; diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java index 8865bdc2..f19e8400 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java @@ -149,28 +149,30 @@ public class RemoteHttpCacheDispatcher final RequestBuilder builder = RequestBuilder.post( url ).setCharset( DEFAULT_ENCODING ); if ( getRemoteHttpCacheAttributes().isIncludeCacheNameAsParameter() - && remoteCacheRequest.getCacheName() != null ) + && remoteCacheRequest.cacheName() != null ) { - builder.addParameter( PARAMETER_CACHE_NAME, remoteCacheRequest.getCacheName() ); + builder.addParameter( PARAMETER_CACHE_NAME, remoteCacheRequest.cacheName() ); } if ( getRemoteHttpCacheAttributes().isIncludeKeysAndPatternsAsParameter() ) { String keyValue = ""; - switch ( remoteCacheRequest.getRequestType() ) + switch ( remoteCacheRequest.requestType() ) { case GET: case REMOVE: + keyValue = remoteCacheRequest.key().toString(); + break; case GET_KEYSET: - keyValue = remoteCacheRequest.getKey().toString(); + keyValue = remoteCacheRequest.cacheName(); break; case GET_MATCHING: - keyValue = remoteCacheRequest.getPattern(); + keyValue = remoteCacheRequest.pattern(); break; case GET_MULTIPLE: - keyValue = remoteCacheRequest.getKeySet().toString(); + keyValue = remoteCacheRequest.keySet().toString(); break; case UPDATE: - keyValue = remoteCacheRequest.getCacheElement().key().toString(); + keyValue = remoteCacheRequest.cacheElement().key().toString(); break; default: break; @@ -180,7 +182,7 @@ public class RemoteHttpCacheDispatcher if ( getRemoteHttpCacheAttributes().isIncludeRequestTypeasAsParameter() ) { builder.addParameter( PARAMETER_REQUEST_TYPE, - remoteCacheRequest.getRequestType().toString() ); + remoteCacheRequest.requestType().toString() ); } builder.setEntity(new ByteArrayEntity( requestAsByteArray )); diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/server/RemoteHttpCacheServlet.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/server/RemoteHttpCacheServlet.java index 18d528d5..cc7a969d 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/server/RemoteHttpCacheServlet.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/server/RemoteHttpCacheServlet.java @@ -23,7 +23,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.Serializable; -import java.util.HashMap; import java.util.Map; import java.util.Properties; import java.util.Set; @@ -190,65 +189,60 @@ public class RemoteHttpCacheServlet */ protected RemoteCacheResponse<Object> processRequest( final RemoteCacheRequest<Serializable, Serializable> request ) { - final RemoteCacheResponse<Object> response = new RemoteCacheResponse<>(); + RemoteCacheResponse<Object> response; if ( request == null ) { final String message = "The request is null. Cannot process"; log.warn( message ); - response.setSuccess( false ); - response.setErrorMessage( message ); + response = new RemoteCacheResponse<>(false, message); } else { try { - switch ( request.getRequestType() ) + switch ( request.requestType() ) { case GET: final ICacheElement<Serializable, Serializable> element = - remoteCacheService.get( request.getCacheName(), request.getKey(), request.getRequesterId() ); - response.setPayload(element); + remoteCacheService.get( request.cacheName(), request.key(), request.requesterId() ); + response = new RemoteCacheResponse<>(element); break; case GET_MULTIPLE: final Map<Serializable, ICacheElement<Serializable, Serializable>> elementMap = - remoteCacheService.getMultiple( request.getCacheName(), request.getKeySet(), request.getRequesterId() ); - if ( elementMap != null ) - { - response.setPayload(new HashMap<>(elementMap)); - } + remoteCacheService.getMultiple( request.cacheName(), request.keySet(), request.requesterId() ); + response = new RemoteCacheResponse<>(elementMap); break; case GET_MATCHING: final Map<Serializable, ICacheElement<Serializable, Serializable>> elementMapMatching = - remoteCacheService.getMatching( request.getCacheName(), request.getPattern(), request.getRequesterId() ); - if ( elementMapMatching != null ) - { - response.setPayload(new HashMap<>(elementMapMatching)); - } + remoteCacheService.getMatching( request.cacheName(), request.pattern(), request.requesterId() ); + response = new RemoteCacheResponse<>(elementMapMatching); break; case REMOVE: - remoteCacheService.remove( request.getCacheName(), request.getKey(), request.getRequesterId() ); + remoteCacheService.remove( request.cacheName(), request.key(), request.requesterId() ); + response = new RemoteCacheResponse<>(true, "OK"); break; case REMOVE_ALL: - remoteCacheService.removeAll( request.getCacheName(), request.getRequesterId() ); + remoteCacheService.removeAll( request.cacheName(), request.requesterId() ); + response = new RemoteCacheResponse<>(true, "OK"); break; case UPDATE: - remoteCacheService.update( request.getCacheElement(), request.getRequesterId() ); + remoteCacheService.update( request.cacheElement(), request.requesterId() ); + response = new RemoteCacheResponse<>(true, "OK"); break; case ALIVE_CHECK: case DISPOSE: - response.setSuccess( true ); + response = new RemoteCacheResponse<>(true, "OK"); // DO NOTHING break; case GET_KEYSET: - final Set<Serializable> keys = remoteCacheService.getKeySet( request.getCacheName() ); - response.setPayload( keys ); + final Set<Serializable> keys = remoteCacheService.getKeySet( request.cacheName() ); + response = new RemoteCacheResponse<>(keys); break; default: final String message = "Unknown event type. Cannot process " + request; log.warn( message ); - response.setSuccess( false ); - response.setErrorMessage( message ); + response = new RemoteCacheResponse<>(false, message); break; } } @@ -256,8 +250,7 @@ public class RemoteHttpCacheServlet { final String message = "Problem processing request. " + request + " Error: " + e.getMessage(); log.error( message, e ); - response.setSuccess( false ); - response.setErrorMessage( message ); + response = new RemoteCacheResponse<>(false, message); } } diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/util/RemoteCacheRequestFactory.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/util/RemoteCacheRequestFactory.java index 02490fb8..97d5bce3 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/util/RemoteCacheRequestFactory.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/util/RemoteCacheRequestFactory.java @@ -44,7 +44,7 @@ public class RemoteCacheRequestFactory public static <K, V> RemoteCacheRequest<K, V> createAliveCheckRequest( final long requesterId ) { - return createRequest(null, RemoteRequestType.ALIVE_CHECK, requesterId); + return new RemoteCacheRequest<>(null, RemoteRequestType.ALIVE_CHECK, requesterId); } /** @@ -57,7 +57,7 @@ public class RemoteCacheRequestFactory public static <K, V> RemoteCacheRequest<K, V> createDisposeRequest( final String cacheName, final long requesterId ) { - return createRequest(cacheName, RemoteRequestType.DISPOSE, requesterId); + return new RemoteCacheRequest<>(cacheName, RemoteRequestType.DISPOSE, requesterId); } /** @@ -69,8 +69,8 @@ public class RemoteCacheRequestFactory */ public static RemoteCacheRequest<String, String> createGetKeySetRequest( final String cacheName, final long requesterId ) { - final RemoteCacheRequest<String, String> request = createRequest(cacheName, RemoteRequestType.GET_KEYSET, requesterId); - request.setKey( cacheName ); + final RemoteCacheRequest<String, String> request = + new RemoteCacheRequest<>(cacheName, RemoteRequestType.GET_KEYSET, requesterId); return request; } @@ -85,8 +85,8 @@ public class RemoteCacheRequestFactory */ public static <K, V> RemoteCacheRequest<K, V> createGetMatchingRequest( final String cacheName, final String pattern, final long requesterId ) { - final RemoteCacheRequest<K, V> request = createRequest(cacheName, RemoteRequestType.GET_MATCHING, requesterId); - request.setPattern( pattern ); + final RemoteCacheRequest<K, V> request = new RemoteCacheRequest<>(cacheName, + RemoteRequestType.GET_MATCHING, requesterId, pattern); return request; } @@ -101,8 +101,8 @@ public class RemoteCacheRequestFactory */ public static <K, V> RemoteCacheRequest<K, V> createGetMultipleRequest( final String cacheName, final Set<K> keys, final long requesterId ) { - final RemoteCacheRequest<K, V> request = createRequest(cacheName, RemoteRequestType.GET_MULTIPLE, requesterId); - request.setKeySet(keys); + final RemoteCacheRequest<K, V> request = new RemoteCacheRequest<>(cacheName, + RemoteRequestType.GET_MULTIPLE, requesterId, keys); return request; } @@ -117,8 +117,8 @@ public class RemoteCacheRequestFactory */ public static <K, V> RemoteCacheRequest<K, V> createGetRequest( final String cacheName, final K key, final long requesterId ) { - final RemoteCacheRequest<K, V> request = createRequest(cacheName, RemoteRequestType.GET, requesterId); - request.setKey( key ); + final RemoteCacheRequest<K, V> request = new RemoteCacheRequest<>(cacheName, + RemoteRequestType.GET, requesterId, key); return request; } @@ -132,8 +132,7 @@ public class RemoteCacheRequestFactory */ public static <K, V> RemoteCacheRequest<K, V> createRemoveAllRequest( final String cacheName, final long requesterId ) { - - return createRequest(cacheName, RemoteRequestType.REMOVE_ALL, requesterId); + return new RemoteCacheRequest<>(cacheName, RemoteRequestType.REMOVE_ALL, requesterId); } /** @@ -146,27 +145,8 @@ public class RemoteCacheRequestFactory */ public static <K, V> RemoteCacheRequest<K, V> createRemoveRequest( final String cacheName, final K key, final long requesterId ) { - final RemoteCacheRequest<K, V> request = createRequest(cacheName, RemoteRequestType.REMOVE, requesterId); - request.setKey( key ); - - return request; - } - - /** - * Create generic request - * @param cacheName cache name - * @param requestType type of request - * @param requesterId id of requester - * @return the request - */ - private static <K, V> RemoteCacheRequest<K, V> createRequest(final String cacheName, final RemoteRequestType requestType, final long requesterId) - { - final RemoteCacheRequest<K, V> request = new RemoteCacheRequest<>(); - request.setCacheName( cacheName ); - request.setRequestType( requestType ); - request.setRequesterId( requesterId ); - - log.debug( "Created: {0}", request ); + final RemoteCacheRequest<K, V> request = new RemoteCacheRequest<>(cacheName, + RemoteRequestType.REMOVE, requesterId, key); return request; } @@ -180,15 +160,15 @@ public class RemoteCacheRequestFactory */ public static <K, V> RemoteCacheRequest<K, V> createUpdateRequest( final ICacheElement<K, V> cacheElement, final long requesterId ) { - final RemoteCacheRequest<K, V> request = createRequest(null, RemoteRequestType.UPDATE, requesterId); + final RemoteCacheRequest<K, V> request; if ( cacheElement != null ) { - request.setCacheName( cacheElement.cacheName() ); - request.setCacheElement( cacheElement ); - request.setKey( cacheElement.key() ); + request = new RemoteCacheRequest<>(cacheElement.cacheName(), + RemoteRequestType.UPDATE, requesterId, cacheElement); } else { + request = new RemoteCacheRequest<>(null, RemoteRequestType.UPDATE, requesterId); log.error( "Can't create a proper update request for a null cache element." ); } diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/value/RemoteCacheRequest.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/value/RemoteCacheRequest.java index fe78845d..1012a18e 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/value/RemoteCacheRequest.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/value/RemoteCacheRequest.java @@ -30,143 +30,100 @@ import org.apache.commons.jcs4.engine.behavior.ICacheElement; * Rather than creating sub object types, I created on object that has values for all types of * requests. */ -public class RemoteCacheRequest<K, V> - implements Serializable -{ - /** Don't change. */ - private static final long serialVersionUID = -8858447417390442569L; - - /** The request type specifies the type of request: get, put, remove, . . */ - private RemoteRequestType requestType; - - /** Used to identify the source. Same as listener id on the client side. */ - private long requesterId; - - /** The name of the region */ - private String cacheName; - - /** The key, if this request has a key. */ - private K key; +public record RemoteCacheRequest<K, V>( + /** The name of the region */ + String cacheName, - /** The keySet, if this request has a keySet. Only getMultiple requests. */ - private Set<K> keySet; + /** The request type specifies the type of request: get, put, remove, . . */ + RemoteRequestType requestType, - /** The pattern, if this request uses a pattern. Only getMatching requests. */ - private String pattern; - - /** The ICacheEleemnt, if this request contains a value. Only update requests will have this. */ - private ICacheElement<K, V> cacheElement; - - /** - * @return the cacheElement - */ - public ICacheElement<K, V> getCacheElement() - { - return cacheElement; - } + /** Used to identify the source. Same as listener id on the client side. */ + long requesterId, - /** - * @return the cacheName - */ - public String getCacheName() - { - return cacheName; - } + /** The key, if this request has a key. */ + K key, - /** - * @return the key - */ - public K getKey() - { - return key; - } + /** The keySet, if this request has a keySet. Only getMultiple requests. */ + Set<K> keySet, - /** - * @return the keySet - */ - public Set<K> getKeySet() - { - return keySet; - } + /** The pattern, if this request uses a pattern. Only getMatching requests. */ + String pattern, - /** - * @return the pattern - */ - public String getPattern() - { - return pattern; - } - - /** - * @return the requesterId - */ - public long getRequesterId() - { - return requesterId; - } - - /** - * @return the requestType - */ - public RemoteRequestType getRequestType() - { - return requestType; - } - - /** - * @param cacheElement the cacheElement to set - */ - public void setCacheElement( final ICacheElement<K, V> cacheElement ) - { - this.cacheElement = cacheElement; - } + /** The ICacheEleemnt, if this request contains a value. Only update requests will have this. */ + ICacheElement<K, V> cacheElement +) implements Serializable +{ + /** Don't change. */ + private static final long serialVersionUID = -8858447417390442569L; - /** - * @param cacheName the cacheName to set - */ - public void setCacheName( final String cacheName ) - { - this.cacheName = cacheName; - } /** - * @param key the key to set + * Construct a RemoteCacheRequest + * + * @param cacheName the name of the region + * @param requestType the request type specifies the type of request: get, put, remove, ... + * @param requesterId used to identify the source. Same as listener id on the client side. */ - public void setKey( final K key ) + public RemoteCacheRequest(final String cacheName, final RemoteRequestType requestType, + final long requesterId) { - this.key = key; + this(cacheName, requestType, requesterId, null, null, null, null); } /** - * @param keySet the keySet to set + * Construct a RemoteCacheRequest with key + * + * @param cacheName the name of the region + * @param requestType the request type specifies the type of request: get, put, remove, ... + * @param requesterId used to identify the source. Same as listener id on the client side. + * @param key the key */ - public void setKeySet( final Set<K> keySet ) + public RemoteCacheRequest(final String cacheName, final RemoteRequestType requestType, + final long requesterId, final K key) { - this.keySet = keySet; + this(cacheName, requestType, requesterId, key, null, null, null); } /** - * @param pattern the pattern to set + * Construct a RemoteCacheRequest with KeySet + * + * @param cacheName the name of the region + * @param requestType the request type specifies the type of request: get, put, remove, ... + * @param requesterId used to identify the source. Same as listener id on the client side. + * @param keySet the KeySet */ - public void setPattern( final String pattern ) + public RemoteCacheRequest(final String cacheName, final RemoteRequestType requestType, + final long requesterId, final Set<K> keySet) { - this.pattern = pattern; + this(cacheName, requestType, requesterId, null, keySet, null, null); } /** - * @param requesterId the requesterId to set + * Construct a RemoteCacheRequest with Pattern + * + * @param cacheName the name of the region + * @param requestType the request type specifies the type of request: get, put, remove, ... + * @param requesterId used to identify the source. Same as listener id on the client side. + * @param pattern the Pattern */ - public void setRequesterId( final long requesterId ) + public RemoteCacheRequest(final String cacheName, final RemoteRequestType requestType, + final long requesterId, final String pattern) { - this.requesterId = requesterId; + this(cacheName, requestType, requesterId, null, null, pattern, null); } /** - * @param requestType the requestType to set + * Construct a RemoteCacheRequest with CacheElement + * + * @param cacheName the name of the region + * @param requestType the request type specifies the type of request: get, put, remove, ... + * @param requesterId used to identify the source. Same as listener id on the client side. + * @param cacheElement the CacheElement */ - public void setRequestType( final RemoteRequestType requestType ) + public RemoteCacheRequest(final String cacheName, final RemoteRequestType requestType, + final long requesterId, final ICacheElement<K, V> cacheElement) { - this.requestType = requestType; + this(cacheName, requestType, requesterId, cacheElement.key(), null, null, cacheElement); } /** @return string */ @@ -175,13 +132,13 @@ public class RemoteCacheRequest<K, V> { final StringBuilder buf = new StringBuilder(); buf.append( "\nRemoteHttpCacheRequest" ); - buf.append( "\n requesterId [" + getRequesterId() + "]" ); - buf.append( "\n requestType [" + getRequestType() + "]" ); - buf.append( "\n cacheName [" + getCacheName() + "]" ); - buf.append( "\n key [" + getKey() + "]" ); - buf.append( "\n keySet [" + getKeySet() + "]" ); - buf.append( "\n pattern [" + getPattern() + "]" ); - buf.append( "\n cacheElement [" + getCacheElement() + "]" ); + buf.append( "\n requesterId [" + requesterId() + "]" ); + buf.append( "\n requestType [" + requestType() + "]" ); + buf.append( "\n cacheName [" + cacheName() + "]" ); + buf.append( "\n key [" + key() + "]" ); + buf.append( "\n keySet [" + keySet() + "]" ); + buf.append( "\n pattern [" + pattern() + "]" ); + buf.append( "\n cacheElement [" + cacheElement() + "]" ); return buf.toString(); } } diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/value/RemoteCacheResponse.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/value/RemoteCacheResponse.java index b787b311..a260d0fd 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/value/RemoteCacheResponse.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/value/RemoteCacheResponse.java @@ -25,70 +25,40 @@ import java.io.Serializable; * This is the response wrapper. The servlet wraps all different type of responses in one of these * objects. */ -public class RemoteCacheResponse<T> - implements Serializable +public record RemoteCacheResponse<T>( + /** + * The payload. Typically a key / ICacheElement<K, V> map. A normal get will return a map with one + * record. + */ + T payload, + + /** Was the event processed without error */ + boolean success, + + /** Simple error messaging */ + String errorMessage +) implements Serializable { /** Don't change. */ private static final long serialVersionUID = -8858447417390442568L; - /** Was the event processed without error */ - private boolean success = true; - - /** Simple error messaging */ - private String errorMessage; - - /** - * The payload. Typically a key / ICacheElement<K, V> map. A normal get will return a map with one - * record. - */ - private T payload; - - /** - * @return the errorMessage - */ - public String getErrorMessage() - { - return errorMessage; - } - - /** - * @return the payload - */ - public T getPayload() - { - return payload; - } - - /** - * @return the success - */ - public boolean isSuccess() - { - return success; - } - - /** - * @param errorMessage the errorMessage to set - */ - public void setErrorMessage( final String errorMessage ) - { - this.errorMessage = errorMessage; - } - /** - * @param payload the payload to set + * Construct error message object + * @param succcess + * @param errorMessage */ - public void setPayload( final T payload ) + public RemoteCacheResponse(final boolean success, final String errorMessage) { - this.payload = payload; + this(null, success, errorMessage); } /** - * @param success the success to set + * Construct payload object + * @param payload */ - public void setSuccess( final boolean success ) + public RemoteCacheResponse(final T payload) { - this.success = success; + this(payload, true, "OK"); } /** @return string */ @@ -97,9 +67,9 @@ public class RemoteCacheResponse<T> { final StringBuilder buf = new StringBuilder(); buf.append( "\nRemoteHttpCacheResponse" ); - buf.append( "\n success [" + isSuccess() + "]" ); - buf.append( "\n payload [" + getPayload() + "]" ); - buf.append( "\n errorMessage [" + getErrorMessage() + "]" ); + buf.append( "\n success [" + success() + "]" ); + buf.append( "\n payload [" + payload() + "]" ); + buf.append( "\n errorMessage [" + errorMessage() + "]" ); return buf.toString(); } } diff --git a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/remote/http/client/RemoteHttpCacheClientUnitTest.java b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/remote/http/client/RemoteHttpCacheClientUnitTest.java index dbfdcad3..a34e65c9 100644 --- a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/remote/http/client/RemoteHttpCacheClientUnitTest.java +++ b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/remote/http/client/RemoteHttpCacheClientUnitTest.java @@ -60,7 +60,7 @@ class RemoteHttpCacheClientUnitTest // VERIFY assertEquals( RemoteRequestType.DISPOSE, mockDispatcher.lastRemoteCacheRequest - .getRequestType(), "Wrong type." ); + .requestType(), "Wrong type." ); } /** @@ -84,8 +84,7 @@ class RemoteHttpCacheClientUnitTest final ICacheElement<String, String> expected = new CacheElement<>( cacheName, key, "value" ); final RemoteCacheResponse<ICacheElement<String, String>> remoteHttpCacheResponse = - new RemoteCacheResponse<>(); - remoteHttpCacheResponse.setPayload( expected ); + new RemoteCacheResponse<>(expected); mockDispatcher.setupRemoteCacheResponse = remoteHttpCacheResponse; @@ -95,7 +94,7 @@ class RemoteHttpCacheClientUnitTest // VERIFY assertEquals( expected, result, "Wrong result." ); assertEquals( RemoteRequestType.GET, mockDispatcher.lastRemoteCacheRequest - .getRequestType(), "Wrong type." ); + .requestType(), "Wrong type." ); } /** @@ -125,7 +124,7 @@ class RemoteHttpCacheClientUnitTest // VERIFY assertNull( result, "Wrong result." ); assertEquals( RemoteRequestType.GET, mockDispatcher.lastRemoteCacheRequest - .getRequestType(), "Wrong type." ); + .requestType(), "Wrong type." ); } /** @@ -151,8 +150,7 @@ class RemoteHttpCacheClientUnitTest final Map<String, ICacheElement<String, String>> expectedMap = new HashMap<>(); expectedMap.put( "key", expected ); final RemoteCacheResponse<Map<String, ICacheElement<String, String>>> remoteHttpCacheResponse = - new RemoteCacheResponse<>(); - remoteHttpCacheResponse.setPayload( expectedMap ); + new RemoteCacheResponse<>(expectedMap); mockDispatcher.setupRemoteCacheResponse = remoteHttpCacheResponse; @@ -162,7 +160,7 @@ class RemoteHttpCacheClientUnitTest // VERIFY assertEquals( expected, result.get( "key" ), "Wrong result." ); assertEquals( RemoteRequestType.GET_MATCHING, - mockDispatcher.lastRemoteCacheRequest.getRequestType(), + mockDispatcher.lastRemoteCacheRequest.requestType(), "Wrong type." ); } @@ -189,8 +187,7 @@ class RemoteHttpCacheClientUnitTest final Map<String, ICacheElement<String, String>> expectedMap = new HashMap<>(); expectedMap.put( "key", expected ); final RemoteCacheResponse<Map<String, ICacheElement<String, String>>> remoteHttpCacheResponse = - new RemoteCacheResponse<>(); - remoteHttpCacheResponse.setPayload( expectedMap ); + new RemoteCacheResponse<>(expectedMap); mockDispatcher.setupRemoteCacheResponse = remoteHttpCacheResponse; @@ -200,7 +197,7 @@ class RemoteHttpCacheClientUnitTest // VERIFY assertEquals( expected, result.get( "key" ), "Wrong result." ); assertEquals( RemoteRequestType.GET_MULTIPLE, - mockDispatcher.lastRemoteCacheRequest.getRequestType(), + mockDispatcher.lastRemoteCacheRequest.requestType(), "Wrong type." ); } @@ -228,7 +225,7 @@ class RemoteHttpCacheClientUnitTest // VERIFY assertEquals( RemoteRequestType.REMOVE, mockDispatcher.lastRemoteCacheRequest - .getRequestType(), "Wrong type." ); + .requestType(), "Wrong type." ); } /** @@ -254,7 +251,7 @@ class RemoteHttpCacheClientUnitTest // VERIFY assertEquals( RemoteRequestType.REMOVE_ALL, mockDispatcher.lastRemoteCacheRequest - .getRequestType(), "Wrong type." ); + .requestType(), "Wrong type." ); } /** @@ -282,6 +279,6 @@ class RemoteHttpCacheClientUnitTest // VERIFY assertEquals( RemoteRequestType.UPDATE, mockDispatcher.lastRemoteCacheRequest - .getRequestType(), "Wrong type." ); + .requestType(), "Wrong type." ); } } diff --git a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/remote/http/server/RemoteHttpCacheServletUnitTest.java b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/remote/http/server/RemoteHttpCacheServletUnitTest.java index 92e6a4c6..b4088764 100644 --- a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/remote/http/server/RemoteHttpCacheServletUnitTest.java +++ b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/remote/http/server/RemoteHttpCacheServletUnitTest.java @@ -125,7 +125,7 @@ class RemoteHttpCacheServletUnitTest // VERIFY assertNotNull( result, "Should have a result." ); - assertTrue( result.getErrorMessage().indexOf( "The request is null" ) != -1, + assertTrue( result.errorMessage().indexOf( "The request is null" ) != -1, "Should have 'The request is null' in the errorMessage" ); assertTrue( result.toString().indexOf( "The request is null" ) != -1, "Should have 'The request is null' in the toString" ); diff --git a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/remote/util/RemoteCacheRequestFactoryUnitTest.java b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/remote/util/RemoteCacheRequestFactoryUnitTest.java index a0f3ecc0..880e705e 100644 --- a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/remote/util/RemoteCacheRequestFactoryUnitTest.java +++ b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/remote/util/RemoteCacheRequestFactoryUnitTest.java @@ -49,8 +49,8 @@ class RemoteCacheRequestFactoryUnitTest // VERIFY assertNotNull( result, "Should have a result" ); - assertEquals( cacheName, result.getCacheName(), "Wrong cacheName" ); - assertEquals( RemoteRequestType.GET_MATCHING, result.getRequestType(), "Wrong type" ); + assertEquals( cacheName, result.cacheName(), "Wrong cacheName" ); + assertEquals( RemoteRequestType.GET_MATCHING, result.requestType(), "Wrong type" ); } /** Simple test */ @@ -68,8 +68,8 @@ class RemoteCacheRequestFactoryUnitTest // VERIFY assertNotNull( result, "Should have a result" ); - assertEquals( cacheName, result.getCacheName(), "Wrong cacheName" ); - assertEquals( RemoteRequestType.GET_MULTIPLE, result.getRequestType(), "Wrong type" ); + assertEquals( cacheName, result.cacheName(), "Wrong cacheName" ); + assertEquals( RemoteRequestType.GET_MULTIPLE, result.requestType(), "Wrong type" ); } /** Simple test */ @@ -87,8 +87,8 @@ class RemoteCacheRequestFactoryUnitTest // VERIFY assertNotNull( result, "Should have a result" ); - assertEquals( cacheName, result.getCacheName(), "Wrong cacheName" ); - assertEquals( RemoteRequestType.GET, result.getRequestType(), "Wrong type" ); + assertEquals( cacheName, result.cacheName(), "Wrong cacheName" ); + assertEquals( RemoteRequestType.GET, result.requestType(), "Wrong type" ); } /** Simple test */ @@ -105,8 +105,8 @@ class RemoteCacheRequestFactoryUnitTest // VERIFY assertNotNull( result, "Should have a result" ); - assertEquals( cacheName, result.getCacheName(), "Wrong cacheName" ); - assertEquals( RemoteRequestType.REMOVE_ALL, result.getRequestType(), "Wrong type" ); + assertEquals( cacheName, result.cacheName(), "Wrong cacheName" ); + assertEquals( RemoteRequestType.REMOVE_ALL, result.requestType(), "Wrong type" ); } /** Simple test */ @@ -124,8 +124,8 @@ class RemoteCacheRequestFactoryUnitTest // VERIFY assertNotNull( result, "Should have a result" ); - assertEquals( cacheName, result.getCacheName(), "Wrong cacheName" ); - assertEquals( RemoteRequestType.REMOVE, result.getRequestType(), "Wrong type" ); + assertEquals( cacheName, result.cacheName(), "Wrong cacheName" ); + assertEquals( RemoteRequestType.REMOVE, result.requestType(), "Wrong type" ); } /** Simple test */ @@ -146,7 +146,7 @@ class RemoteCacheRequestFactoryUnitTest // VERIFY assertNotNull( result, "Should have a result" ); - assertEquals( cacheName, result.getCacheName(), "Wrong cacheName" ); - assertEquals( RemoteRequestType.UPDATE, result.getRequestType(), "Wrong type" ); + assertEquals( cacheName, result.cacheName(), "Wrong cacheName" ); + assertEquals( RemoteRequestType.UPDATE, result.requestType(), "Wrong type" ); } }
