commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1719091 [2/2] - /commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/
Date Thu, 10 Dec 2015 15:06:41 GMT
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheNoWait.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheNoWait.java?rev=1719091&r1=1719090&r2=1719091&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheNoWait.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheNoWait.java
Thu Dec 10 15:06:40 2015
@@ -19,6 +19,14 @@ package org.apache.commons.jcs.auxiliary
  * under the License.
  */
 
+import java.io.IOException;
+import java.rmi.UnmarshalException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
 import org.apache.commons.jcs.auxiliary.AbstractAuxiliaryCache;
 import org.apache.commons.jcs.auxiliary.AuxiliaryCacheAttributes;
 import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheClient;
@@ -35,14 +43,6 @@ import org.apache.commons.jcs.engine.sta
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import java.io.IOException;
-import java.rmi.UnmarshalException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
 /**
  * The RemoteCacheNoWait wraps the RemoteCacheClient. The client holds a handle on the
  * RemoteCacheService.
@@ -101,9 +101,12 @@ public class RemoteCacheNoWait<K, V>
         remoteCacheClient = cache;
 
         CacheEventQueueFactory<K, V> factory = new CacheEventQueueFactory<K, V>();
-        this.cacheEventQueue = factory.createCacheEventQueue( new CacheAdaptor<K, V>(
remoteCacheClient ), remoteCacheClient
-            .getListenerId(), remoteCacheClient.getCacheName(), remoteCacheClient.getAuxiliaryCacheAttributes()
-            .getEventQueuePoolName(), remoteCacheClient.getAuxiliaryCacheAttributes().getEventQueueType()
);
+        this.cacheEventQueue = factory.createCacheEventQueue(
+            new CacheAdaptor<K, V>( remoteCacheClient ),
+            remoteCacheClient.getListenerId(),
+            remoteCacheClient.getCacheName(),
+            remoteCacheClient.getAuxiliaryCacheAttributes().getEventQueuePoolName(),
+            remoteCacheClient.getAuxiliaryCacheAttributes().getEventQueueType() );
 
         if ( remoteCacheClient.getStatus() == CacheStatus.ERROR )
         {

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheNoWaitFacade.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheNoWaitFacade.java?rev=1719091&r1=1719090&r2=1719091&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheNoWaitFacade.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheNoWaitFacade.java
Thu Dec 10 15:06:40 2015
@@ -50,8 +50,10 @@ public class RemoteCacheNoWaitFacade<K,
      * @param cacheEventLogger
      * @param elementSerializer
      */
-    public RemoteCacheNoWaitFacade( RemoteCacheNoWait<K, V>[] noWaits, RemoteCacheAttributes
rca,
-                                    ICompositeCacheManager cacheMgr, ICacheEventLogger cacheEventLogger,
+    public RemoteCacheNoWaitFacade( RemoteCacheNoWait<K, V>[] noWaits,
+                                    RemoteCacheAttributes rca,
+                                    ICompositeCacheManager cacheMgr,
+                                    ICacheEventLogger cacheEventLogger,
                                     IElementSerializer elementSerializer )
     {
         super( noWaits, rca, cacheMgr, cacheEventLogger, elementSerializer );
@@ -67,7 +69,7 @@ public class RemoteCacheNoWaitFacade<K,
     {
         if ( log.isDebugEnabled() )
         {
-            log.info( "in failover for " + i );
+            log.debug( "in failover for " + i );
         }
 
         if ( getRemoteCacheAttributes().getRemoteType() == RemoteType.LOCAL )
@@ -76,12 +78,10 @@ public class RemoteCacheNoWaitFacade<K,
             {
                 // start failover, primary recovery process
                 RemoteCacheFailoverRunner<K, V> runner =
-                    new RemoteCacheFailoverRunner<K, V>( this, getCompositeCacheManager(),
-                      super.getCacheEventLogger(), super.getElementSerializer() );
+                    new RemoteCacheFailoverRunner<K, V>( this, getCompositeCacheManager()
);
+                runner.setDaemon( true );
+                runner.start();
                 runner.notifyError();
-                Thread t = new Thread( runner );
-                t.setDaemon( true );
-                t.start();
 
                 if ( getCacheEventLogger() != null )
                 {

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheRestore.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheRestore.java?rev=1719091&r1=1719090&r2=1719091&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheRestore.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheRestore.java
Thu Dec 10 15:06:40 2015
@@ -19,16 +19,16 @@ package org.apache.commons.jcs.auxiliary
  * under the License.
  */
 
+import java.io.IOException;
+import java.rmi.Naming;
+import java.rmi.NotBoundException;
+
 import org.apache.commons.jcs.engine.behavior.ICacheObserver;
 import org.apache.commons.jcs.engine.behavior.ICacheRestore;
 import org.apache.commons.jcs.engine.behavior.ICacheServiceNonLocal;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import java.io.IOException;
-import java.rmi.Naming;
-import java.rmi.NotBoundException;
-
 /**
  * Used to repair the remote caches managed by the associated instance of RemoteCacheManager.
  * <p>
@@ -78,7 +78,9 @@ public class RemoteCacheRestore
         {
             return canFix;
         }
-        String registry = RemoteUtils.getNamingURL(remoteCacheManager.host, remoteCacheManager.port,
remoteCacheManager.service);
+
+        String registry = remoteCacheManager.getRegistryURL();
+
         if ( log.isInfoEnabled() )
         {
             log.info( "looking up server [" + registry + "]" );
@@ -93,12 +95,12 @@ public class RemoteCacheRestore
         }
         catch (IOException e)
         {
-            log.error( "host=" + remoteCacheManager.host + "; port" + remoteCacheManager.port
+ "; service=" + remoteCacheManager.service );
+            log.error( "Registry=" + registry, e );
             canFix = false;
         }
         catch (NotBoundException e)
         {
-            log.error( "host=" + remoteCacheManager.host + "; port" + remoteCacheManager.port
+ "; service=" + remoteCacheManager.service );
+            log.error( "Registry=" + registry, e );
             canFix = false;
         }
 
@@ -119,9 +121,7 @@ public class RemoteCacheRestore
 
         if ( log.isInfoEnabled() )
         {
-            String msg = "Remote connection to "
-                    + RemoteUtils.getNamingURL(remoteCacheManager.host, remoteCacheManager.port,
remoteCacheManager.service)
-                    + " resumed.";
+            String msg = "Remote connection to " + remoteCacheManager.getRegistryURL() +
" resumed.";
             remoteCacheManager.logApplicationEvent( "RemoteCacheRestore", "fix", msg );
             log.info( msg );
         }

Added: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteLocation.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteLocation.java?rev=1719091&view=auto
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteLocation.java
(added)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteLocation.java
Thu Dec 10 15:06:40 2015
@@ -0,0 +1,144 @@
+package org.apache.commons.jcs.auxiliary.remote;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/*
+ * 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.
+ */
+
+/**
+ * Location of the RMI registry.
+ */
+public final class RemoteLocation
+{
+    /** The logger. */
+    private static final Log log = LogFactory.getLog( RemoteLocation.class );
+
+    /** Pattern for parsing server:port */
+    private static final Pattern SERVER_COLON_PORT = Pattern.compile("(\\S+)\\s*:\\s*(\\d+)");
+
+    /** Host name */
+    private final String host;
+
+    /** Port */
+    private final int port;
+
+    /**
+     * Constructor for the Location object
+     * <p>
+     * @param host
+     * @param port
+     */
+    public RemoteLocation( String host, int port )
+    {
+        this.host = host;
+        this.port = port;
+    }
+
+    /**
+     * @return the host
+     */
+    public String getHost()
+    {
+        return host;
+    }
+
+    /**
+     * @return the port
+     */
+    public int getPort()
+    {
+        return port;
+    }
+
+    /**
+     * @param obj
+     * @return true if the host and port are equal
+     */
+    @Override
+    public boolean equals( Object obj )
+    {
+        if ( obj == this )
+        {
+            return true;
+        }
+        if ( obj == null || !( obj instanceof RemoteLocation ) )
+        {
+            return false;
+        }
+        RemoteLocation l = (RemoteLocation) obj;
+        if ( this.host == null )
+        {
+            return l.host == null && port == l.port;
+        }
+        return host.equals( l.host ) && port == l.port;
+    }
+
+    /**
+     * @return int
+     */
+    @Override
+    public int hashCode()
+    {
+        return host == null ? port : host.hashCode() ^ port;
+    }
+
+    /**
+     * @see java.lang.Object#toString()
+     */
+    @Override
+    public String toString()
+    {
+        StringBuilder sb = new StringBuilder();
+        if (this.host != null)
+        {
+            sb.append(this.host);
+        }
+        sb.append(':').append(this.port);
+
+        return sb.toString();
+    }
+
+    /**
+     * Parse remote server and port from the string representation server:port and store
them in
+     * a RemoteLocation object
+     *
+     * @param server the input string
+     * @returns the remote location object
+     */
+    public static RemoteLocation parseServerAndPort(final String server)
+    {
+        Matcher match = SERVER_COLON_PORT.matcher(server);
+
+        if (match.find() && match.groupCount() == 2)
+        {
+            RemoteLocation location = new RemoteLocation( match.group(1), Integer.parseInt(
match.group(2) ) );
+            return location;
+        }
+        else
+        {
+            log.error("Invalid server descriptor: " + server);
+        }
+
+        return null;
+    }
+}
\ No newline at end of file

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

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteUtils.java?rev=1719091&r1=1719090&r2=1719091&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteUtils.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteUtils.java
Thu Dec 10 15:06:40 2015
@@ -30,8 +30,6 @@ import java.rmi.registry.Registry;
 import java.rmi.server.RMISocketFactory;
 import java.util.Enumeration;
 import java.util.Properties;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -194,7 +192,7 @@ public class RemoteUtils
                 } );
             }
         }
-        catch ( Exception e )
+        catch ( IOException e )
         {
             // Only try to do it once. Otherwise we
             // Generate errors for each region on construction.
@@ -210,6 +208,18 @@ public class RemoteUtils
     /**
      * Get the naming url used for RMI registration
      *
+     * @param location the remote location
+     * @param serviceName
+     * @return
+     */
+    public static String getNamingURL(final RemoteLocation location, final String serviceName)
+    {
+        return getNamingURL(location.getHost(), location.getPort(), serviceName);
+    }
+
+    /**
+     * Get the naming url used for RMI registration
+     *
      * @param registryHost
      * @param registryPort
      * @param serviceName
@@ -223,29 +233,4 @@ public class RemoteUtils
         final String registryURL = "//" + registryHost + ":" + registryPort + "/" + serviceName;
         return registryURL;
     }
-
-    /** Pattern for parsing server:port */
-    private static final Pattern SERVER_COLON_PORT = Pattern.compile("(\\S+)\\s*:\\s*(\\d+)");
-
-    /**
-     * Parse remote server and port from the string representation server:port and store
them in
-     * the RemoteCacheAttributes
-     *
-     * @param server the input string
-     * @param rca the target attribute object
-     */
-    public static void parseServerAndPort(final String server, final RemoteCacheAttributes
rca)
-    {
-        Matcher match = SERVER_COLON_PORT.matcher(server);
-
-        if (match.find() && match.groupCount() == 2)
-        {
-            rca.setRemoteHost( match.group(1) );
-            rca.setRemotePort( Integer.parseInt( match.group(2) ) );
-        }
-        else
-        {
-            log.error("Invalid server descriptor: " + server);
-        }
-    }
 }



Mime
View raw message