Author: tv
Date: Tue Mar 22 15:24:51 2016
New Revision: 1736200
URL: http://svn.apache.org/viewvc?rev=1736200&view=rev
Log:
Further simplify API
Modified:
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/AbstractRemoteCacheNoWaitFacade.java
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCache.java
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheAttributes.java
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheFactory.java
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheFailoverRunner.java
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheNoWaitFacade.java
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/behavior/IRemoteCacheAttributes.java
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheFactory.java
Modified:
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/AbstractRemoteCacheNoWaitFacade.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/AbstractRemoteCacheNoWaitFacade.java?rev=1736200&r1=1736199&r2=1736200&view=diff
==============================================================================
---
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/AbstractRemoteCacheNoWaitFacade.java
(original)
+++
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/AbstractRemoteCacheNoWaitFacade.java
Tue Mar 22 15:24:51 2016
@@ -19,11 +19,18 @@ package org.apache.commons.jcs.auxiliary
* under the License.
*/
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
import org.apache.commons.jcs.auxiliary.AbstractAuxiliaryCache;
-import org.apache.commons.jcs.auxiliary.AuxiliaryCache;
-import org.apache.commons.jcs.auxiliary.AuxiliaryCacheAttributes;
import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes;
import org.apache.commons.jcs.engine.CacheStatus;
+import org.apache.commons.jcs.engine.behavior.ICache;
import org.apache.commons.jcs.engine.behavior.ICacheElement;
import org.apache.commons.jcs.engine.behavior.ICompositeCacheManager;
import org.apache.commons.jcs.engine.behavior.IElementSerializer;
@@ -35,13 +42,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.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
/** An abstract base for the No Wait Facade. Different implementations will
failover differently. */
public abstract class AbstractRemoteCacheNoWaitFacade<K, V>
extends AbstractAuxiliaryCache<K, V>
@@ -50,10 +50,7 @@ public abstract class AbstractRemoteCach
private static final Log log = LogFactory.getLog(
AbstractRemoteCacheNoWaitFacade.class );
/** The connection to a remote server, or a zombie. */
- public RemoteCacheNoWait<K, V>[] noWaits; // TODO privatise if possible
-
- /** The cache name */
- private final String cacheName;
+ private List<RemoteCacheNoWait<K, V>> noWaits;
/** holds failover and cluster information */
private IRemoteCacheAttributes remoteCacheAttributes;
@@ -70,7 +67,7 @@ public abstract class AbstractRemoteCach
* @param cacheEventLogger
* @param elementSerializer
*/
- public AbstractRemoteCacheNoWaitFacade( RemoteCacheNoWait<K, V>[] noWaits,
RemoteCacheAttributes rca,
+ public AbstractRemoteCacheNoWaitFacade( List<ICache<K, V>> noWaits,
RemoteCacheAttributes rca,
ICompositeCacheManager cacheMgr,
ICacheEventLogger cacheEventLogger,
IElementSerializer elementSerializer )
{
@@ -78,9 +75,12 @@ public abstract class AbstractRemoteCach
{
log.debug( "CONSTRUCTING NO WAIT FACADE" );
}
- this.noWaits = noWaits;
+ this.noWaits = new ArrayList<RemoteCacheNoWait<K,V>>();
+ for (ICache<K, V> nw : noWaits)
+ {
+ this.noWaits.add((RemoteCacheNoWait<K,V>) nw);
+ }
this.remoteCacheAttributes = rca;
- this.cacheName = rca.getCacheName();
setCompositeCacheManager( cacheMgr );
setCacheEventLogger( cacheEventLogger );
setElementSerializer( elementSerializer );
@@ -98,43 +98,42 @@ public abstract class AbstractRemoteCach
{
if ( log.isDebugEnabled() )
{
- log.debug( "updating through cache facade, noWaits.length = " +
noWaits.length );
+ log.debug( "updating through cache facade, noWaits.length = " +
noWaits.size() );
}
- int i = 0;
- try
+
+ for (RemoteCacheNoWait<K, V> nw : noWaits)
{
- for ( ; i < noWaits.length; i++ )
+ try
{
- noWaits[i].update( ce );
+ nw.update( ce );
// an initial move into a zombie will lock this to primary
// recovery. will not discover other servers until primary
// reconnect
// and subsequent error
}
- }
- catch ( Exception ex )
- {
- String message = "Problem updating no wait. Will initiate
failover if the noWait is in error.";
- log.error( message, ex );
-
- if ( getCacheEventLogger() != null )
+ catch ( IOException ex )
{
- getCacheEventLogger().logError(
- "RemoteCacheNoWaitFacade",
- ICacheEventLogger.UPDATE_EVENT,
- message + ":" +
ex.getMessage() + " REGION: " + ce.getCacheName()
- + " ELEMENT: " + ce );
- }
-
- // can handle failover here? Is it safe to try the others?
- // check to see it the noWait is now a zombie
- // if it is a zombie, then move to the next in the failover list
- // will need to keep them in order or a count
- failover( i );
- // should start a failover thread
- // should probably only failover if there is only one in the noWait
- // list
- // Should start a background thread to restore the original
primary if we are in failover state.
+ String message = "Problem updating no wait. Will initiate
failover if the noWait is in error.";
+ log.error( message, ex );
+
+ if ( getCacheEventLogger() != null )
+ {
+ getCacheEventLogger().logError( "RemoteCacheNoWaitFacade",
+
ICacheEventLogger.UPDATE_EVENT,
+ message + ":" +
ex.getMessage() + " REGION: " + ce.getCacheName()
+ + " ELEMENT: " + ce );
+ }
+
+ // can handle failover here? Is it safe to try the others?
+ // check to see it the noWait is now a zombie
+ // if it is a zombie, then move to the next in the failover
list
+ // will need to keep them in order or a count
+ failover( nw );
+ // should start a failover thread
+ // should probably only failover if there is only one in the
noWait
+ // list
+ // Should start a background thread to restore the original
primary if we are in failover state.
+ }
}
}
@@ -147,11 +146,11 @@ public abstract class AbstractRemoteCach
@Override
public ICacheElement<K, V> get( K key )
{
- for ( int i = 0; i < noWaits.length; i++ )
+ for (RemoteCacheNoWait<K, V> nw : noWaits)
{
try
{
- ICacheElement<K, V> obj = noWaits[i].get( key );
+ ICacheElement<K, V> obj = nw.get( key );
if ( obj != null )
{
return obj;
@@ -177,11 +176,11 @@ public abstract class AbstractRemoteCach
public Map<K, ICacheElement<K, V>> getMatching( String pattern )
throws IOException
{
- for ( int i = 0; i < noWaits.length; i++ )
+ for (RemoteCacheNoWait<K, V> nw : noWaits)
{
try
{
- return noWaits[i].getMatching( pattern );
+ return nw.getMatching( pattern );
}
catch ( IOException ex )
{
@@ -203,11 +202,11 @@ public abstract class AbstractRemoteCach
{
if ( keys != null && !keys.isEmpty() )
{
- for ( int i = 0; i < noWaits.length; i++ )
+ for (RemoteCacheNoWait<K, V> nw : noWaits)
{
try
{
- return noWaits[i].getMultiple( keys );
+ return nw.getMultiple( keys );
}
catch ( IOException ex )
{
@@ -228,12 +227,11 @@ public abstract class AbstractRemoteCach
public Set<K> getKeySet() throws IOException
{
HashSet<K> allKeys = new HashSet<K>();
- for ( int i = 0; i < noWaits.length; i++ )
+ for (RemoteCacheNoWait<K, V> nw : noWaits)
{
- AuxiliaryCache<K, V> aux = noWaits[i];
- if ( aux != null )
+ if ( nw != null )
{
- Set<K> keys = aux.getKeySet();
+ Set<K> keys = nw.getKeySet();
if(keys != null)
{
allKeys.addAll( keys );
@@ -254,12 +252,12 @@ public abstract class AbstractRemoteCach
{
try
{
- for ( int i = 0; i < noWaits.length; i++ )
+ for (RemoteCacheNoWait<K, V> nw : noWaits)
{
- noWaits[i].remove( key );
+ nw.remove( key );
}
}
- catch ( Exception ex )
+ catch ( IOException ex )
{
log.error( ex );
}
@@ -274,12 +272,12 @@ public abstract class AbstractRemoteCach
{
try
{
- for ( int i = 0; i < noWaits.length; i++ )
+ for (RemoteCacheNoWait<K, V> nw : noWaits)
{
- noWaits[i].removeAll();
+ nw.removeAll();
}
}
- catch ( Exception ex )
+ catch ( IOException ex )
{
log.error( ex );
}
@@ -289,16 +287,9 @@ public abstract class AbstractRemoteCach
@Override
public void dispose()
{
- try
+ for (RemoteCacheNoWait<K, V> nw : noWaits)
{
- for ( int i = 0; i < noWaits.length; i++ )
- {
- noWaits[i].dispose();
- }
- }
- catch ( Exception ex )
- {
- log.error( "Problem in dispose.", ex );
+ nw.dispose();
}
}
@@ -346,9 +337,9 @@ public abstract class AbstractRemoteCach
@Override
public CacheStatus getStatus()
{
- for ( int i = 0; i < noWaits.length; i++ )
+ for (RemoteCacheNoWait<K, V> nw : noWaits)
{
- if ( noWaits[i].getStatus() == CacheStatus.ALIVE )
+ if ( nw.getStatus() == CacheStatus.ALIVE )
{
return CacheStatus.ALIVE;
}
@@ -365,22 +356,41 @@ public abstract class AbstractRemoteCach
@Override
public String toString()
{
- return "RemoteCacheNoWaitFacade: " + cacheName + ", rca = " +
remoteCacheAttributes;
+ return "RemoteCacheNoWaitFacade: " +
remoteCacheAttributes.getCacheName() + ", rca = " + remoteCacheAttributes;
}
/**
* Begin the failover process if this is a local cache. Clustered remote
caches do not failover.
* <p>
- * @param i The no wait in error.
+ * @param rcnw The no wait in error.
+ */
+ protected abstract void failover( RemoteCacheNoWait<K, V> rcnw );
+
+ /**
+ * Get the primary server from the list of failovers
+ *
+ * @return a no wait
*/
- abstract void failover( int i );
+ public RemoteCacheNoWait<K, V> getPrimaryServer()
+ {
+ return noWaits.get(0);
+ }
+ /**
+ * restore the primary server in the list of failovers
+ *
+ */
+ public void restorePrimaryServer(RemoteCacheNoWait<K, V> rcnw)
+ {
+ noWaits.clear();
+ noWaits.add(rcnw);
+ }
/**
* @return Returns the AuxiliaryCacheAttributes.
*/
@Override
- public AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
+ public IRemoteCacheAttributes getAuxiliaryCacheAttributes()
{
return this.remoteCacheAttributes;
}
@@ -408,7 +418,7 @@ public abstract class AbstractRemoteCach
if ( noWaits != null )
{
- elems.add(new StatElement<Integer>( "Number of No Waits",
Integer.valueOf(noWaits.length) ) );
+ elems.add(new StatElement<Integer>( "Number of No Waits",
Integer.valueOf(noWaits.size()) ) );
for ( RemoteCacheNoWait<K, V> rcnw : noWaits )
{
@@ -435,29 +445,9 @@ public abstract class AbstractRemoteCach
}
/**
- * Gets the remoteCacheAttributes attribute of the RemoteCacheNoWaitFacade
object
- * <p>
- * @return The remoteCacheAttributes value
- */
- public IRemoteCacheAttributes getRemoteCacheAttributes()
- {
- return remoteCacheAttributes;
- }
-
- /**
- * Sets the remoteCacheAttributes attribute of the RemoteCacheNoWaitFacade
object.
- * <p>
- * @param rca The new remoteCacheAttributes value
- */
- public void setRemoteCacheAttributes( IRemoteCacheAttributes rca )
- {
- this.remoteCacheAttributes = rca;
- }
-
- /**
* @param compositeCacheManager the compositeCacheManager to set
*/
- protected void setCompositeCacheManager( ICompositeCacheManager
compositeCacheManager )
+ private void setCompositeCacheManager( ICompositeCacheManager
compositeCacheManager )
{
this.compositeCacheManager = compositeCacheManager;
}
Modified:
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCache.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCache.java?rev=1736200&r1=1736199&r2=1736200&view=diff
==============================================================================
---
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCache.java
(original)
+++
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCache.java
Tue Mar 22 15:24:51 2016
@@ -136,7 +136,7 @@ public class RemoteCache<K, V>
log.debug( "Initiating failover, rcnwf = " + rcnwf );
}
- if ( rcnwf != null && rcnwf.getRemoteCacheAttributes().getRemoteType()
== RemoteType.LOCAL )
+ if ( rcnwf != null &&
rcnwf.getAuxiliaryCacheAttributes().getRemoteType() == RemoteType.LOCAL )
{
if ( log.isDebugEnabled() )
{
@@ -144,7 +144,7 @@ public class RemoteCache<K, V>
}
// may need to remove the noWait index here. It will be 0 if it is
// local since there is only 1 possible listener.
- rcnwf.failover( 0 );
+ rcnwf.failover( rcnwf.getPrimaryServer() );
}
if ( ex instanceof IOException )
Modified:
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheAttributes.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheAttributes.java?rev=1736200&r1=1736199&r2=1736200&view=diff
==============================================================================
---
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheAttributes.java
(original)
+++
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheAttributes.java
Tue Mar 22 15:24:51 2016
@@ -19,6 +19,8 @@ package org.apache.commons.jcs.auxiliary
* under the License.
*/
+import java.util.List;
+
import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes;
/**
@@ -44,8 +46,8 @@ public class RemoteCacheAttributes
/** what failover server we are connected to. */
private int failoverIndex = 0;
- /** Array of failover server addresses */
- private RemoteLocation[] failovers;
+ /** List of failover server addresses */
+ private List<RemoteLocation> failovers;
/** default name is remote_cache_client */
private String threadPoolName = "remote_cache_client";
@@ -96,7 +98,7 @@ public class RemoteCacheAttributes
* @return The failovers value
*/
@Override
- public RemoteLocation[] getFailovers()
+ public List<RemoteLocation> getFailovers()
{
return this.failovers;
}
@@ -104,12 +106,12 @@ public class RemoteCacheAttributes
/**
* Sets the failovers attribute of the RemoteCacheAttributes object.
* <p>
- * @param f The new failovers value
+ * @param failovers The new failovers value
*/
@Override
- public void setFailovers( RemoteLocation[] f )
+ public void setFailovers( List<RemoteLocation> failovers )
{
- this.failovers = f;
+ this.failovers = failovers;
}
/**
Modified:
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheFactory.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheFactory.java?rev=1736200&r1=1736199&r2=1736200&view=diff
==============================================================================
---
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheFactory.java
(original)
+++
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheFactory.java
Tue Mar 22 15:24:51 2016
@@ -132,7 +132,7 @@ public class RemoteCacheFactory
}
// end if failoverList != null
- rca.setFailovers( failovers.toArray( new RemoteLocation[0] ) );
+ rca.setFailovers( failovers );
break;
case CLUSTER:
@@ -155,10 +155,8 @@ public class RemoteCacheFactory
break;
}
- @SuppressWarnings("unchecked") // No generic arrays in java
- RemoteCacheNoWait<K, V>[] rcnwArray = noWaits.toArray( new
RemoteCacheNoWait[0] );
RemoteCacheNoWaitFacade<K, V> rcnwf =
- new RemoteCacheNoWaitFacade<K, V>(rcnwArray, rca, cacheMgr,
cacheEventLogger, elementSerializer );
+ new RemoteCacheNoWaitFacade<K, V>(noWaits, rca, cacheMgr,
cacheEventLogger, elementSerializer );
facades.put( rca.getCacheName(), rcnwf );
@@ -257,6 +255,7 @@ public class RemoteCacheFactory
}
managers.clear();
+ facades.clear();
if (monitor != null)
{
Modified:
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheFailoverRunner.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheFailoverRunner.java?rev=1736200&r1=1736199&r2=1736200&view=diff
==============================================================================
---
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheFailoverRunner.java
(original)
+++
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/RemoteCacheFailoverRunner.java
Tue Mar 22 15:24:51 2016
@@ -20,8 +20,11 @@ package org.apache.commons.jcs.auxiliary
*/
import java.io.IOException;
+import java.util.List;
+import java.util.ListIterator;
import org.apache.commons.jcs.auxiliary.AbstractAuxiliaryCacheMonitor;
+import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheAttributes;
import org.apache.commons.jcs.engine.CacheStatus;
import org.apache.commons.jcs.engine.behavior.ICache;
import org.apache.commons.jcs.engine.behavior.ICompositeCacheManager;
@@ -110,14 +113,16 @@ public class RemoteCacheFailoverRunner<K
if ( log.isInfoEnabled() )
{
- log.info( "Exiting failover runner. Failover index = " +
facade.getRemoteCacheAttributes().getFailoverIndex() );
- if ( facade.getRemoteCacheAttributes().getFailoverIndex() <= 0 )
+ int failoverIndex =
facade.getAuxiliaryCacheAttributes().getFailoverIndex();
+ log.info( "Exiting failover runner. Failover index = " +
failoverIndex);
+
+ if ( failoverIndex <= 0 )
{
- log.info( "Failover index is <= 0, meaning we are not " +
"connected to a failover server." );
+ log.info( "Failover index is <= 0, meaning we are not
connected to a failover server." );
}
- else if ( facade.getRemoteCacheAttributes().getFailoverIndex() > 0
)
+ else if ( failoverIndex > 0 )
{
- log.info( "Failover index is > 0, meaning we are " +
"connected to a failover server." );
+ log.info( "Failover index is > 0, meaning we are connected to
a failover server." );
}
// log if we are allright or not.
}
@@ -128,9 +133,10 @@ public class RemoteCacheFailoverRunner<K
* continue until the primary is re-connected. If no failovers are defined,
* this will exit automatically.
*/
- @SuppressWarnings("unchecked") // No generic arrays in java
private void connectAndRestore()
{
+ IRemoteCacheAttributes rca0 = facade.getAuxiliaryCacheAttributes();
+
do
{
log.info( "Remote cache FAILOVER RUNNING." );
@@ -140,7 +146,7 @@ public class RemoteCacheFailoverRunner<K
{
// Monitor each RemoteCacheManager instance one after the
other.
// Each RemoteCacheManager corresponds to one remote
connection.
- RemoteLocation[] failovers =
facade.getRemoteCacheAttributes().getFailovers();
+ List<RemoteLocation> failovers = rca0.getFailovers();
// we should probably check to see if there are any failovers,
// even though the caller
// should have already.
@@ -150,94 +156,73 @@ public class RemoteCacheFailoverRunner<K
log.warn( "Remote is misconfigured, failovers was null." );
return;
}
- else if ( failovers.length == 1 )
+ else if ( failovers.size() == 1 )
{
// if there is only the primary, return out of this
log.info( "No failovers defined, exiting failover runner."
);
return;
}
- int fidx =
facade.getRemoteCacheAttributes().getFailoverIndex();
- log.debug( "fidx = " + fidx + " failovers.length = " +
failovers.length );
+ int fidx = rca0.getFailoverIndex();
+ log.debug( "fidx = " + fidx + " failovers.size = " +
failovers.size() );
// shouldn't we see if the primary is backup?
// If we don't check the primary, if it gets connected in the
// background,
// we will disconnect it only to put it right back
- int i = fidx; // + 1; // +1 skips the primary
+ ListIterator<RemoteLocation> i = failovers.listIterator(fidx);
// + 1; // +1 skips the primary
if ( log.isDebugEnabled() )
{
- log.debug( "starting at failover i = " + i );
+ log.debug( "starting at failover i = " + i.nextIndex() );
}
// try them one at a time until successful
- for ( ; i < failovers.length && !allright.get(); i++ )
+ for ( ; i.hasNext() && !allright.get();)
{
- RemoteLocation server = failovers[i];
+ RemoteLocation server = i.next();
if ( log.isDebugEnabled() )
{
log.debug( "Trying server [" + server + "] at failover
index i = " + i );
}
- RemoteCacheAttributes rca = null;
- try
+ RemoteCacheAttributes rca = (RemoteCacheAttributes)
rca0.clone();
+ rca.setRemoteLocation(server);
+ RemoteCacheManager rcm = RemoteCacheFactory.getManager(
rca, cacheMgr,
+ facade.getCacheEventLogger(),
facade.getElementSerializer() );
+
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "RemoteCacheAttributes for failover = " +
rca.toString() );
+ }
+
+ // add a listener if there are none, need to tell rca
+ // what number it is at
+ ICache<K, V> ic = rcm.getCache( rca );
+ if ( ic.getStatus() == CacheStatus.ALIVE )
{
- rca = (RemoteCacheAttributes)
facade.getRemoteCacheAttributes().clone();
- rca.setRemoteLocation(server);
- RemoteCacheManager rcm =
RemoteCacheFactory.getManager( rca, cacheMgr,
- facade.getCacheEventLogger(),
facade.getElementSerializer() );
+ // may need to do this more gracefully
+ log.debug( "resetting no wait" );
+ facade.restorePrimaryServer((RemoteCacheNoWait<K, V>)
ic);
+ rca0.setFailoverIndex( i.nextIndex() );
if ( log.isDebugEnabled() )
{
- log.debug( "RemoteCacheAttributes for failover = "
+ rca.toString() );
- }
-
- // add a listener if there are none, need to tell rca
- // what number it is at
- ICache<K, V> ic = rcm.getCache( rca );
- if ( ic.getStatus() == CacheStatus.ALIVE )
- {
- // may need to do this more gracefully
- log.debug( "resetting no wait" );
- facade.noWaits = new RemoteCacheNoWait[1];
- facade.noWaits[0] = (RemoteCacheNoWait<K, V>) ic;
-
facade.getRemoteCacheAttributes().setFailoverIndex( i );
-
- if ( log.isDebugEnabled() )
+ log.debug( "setting ALLRIGHT to true" );
+ if ( i.hasPrevious() )
{
- log.debug( "setting ALLRIGHT to true" );
- if ( i > 0 )
- {
- log.debug( "Moving to Primary Recovery
Mode, failover index = " + i );
- }
- else
- {
- log.debug( "No need to connect to
failover, the primary server is back up." );
- }
+ log.debug( "Moving to Primary Recovery Mode,
failover index = " + i.nextIndex() );
}
-
- allright.set(true);
-
- if ( log.isInfoEnabled() )
+ else
{
- log.info( "CONNECTED to host = [" +
rca.getRemoteLocation() + "]" );
+ log.debug( "No need to connect to failover,
the primary server is back up." );
}
}
- }
- catch ( Exception ex )
- {
- allright.compareAndSet(true, false);
- // Problem encountered in fixing the caches managed by
a
- // RemoteCacheManager instance.
- // Soldier on to the next RemoteCacheManager instance.
- RemoteLocation location = (rca == null) ? new
RemoteLocation("null", 0) : rca.getRemoteLocation();
- if ( i == 0 )
- {
- log.warn( "FAILED to connect, as expected, to
primary " + location, ex );
- }
- else
+
+ allright.set(true);
+
+ if ( log.isInfoEnabled() )
{
- log.error( "FAILED to connect to failover " +
location, ex );
+ log.info( "CONNECTED to host = [" +
rca.getRemoteLocation() + "]" );
}
}
}
@@ -254,13 +239,13 @@ public class RemoteCacheFailoverRunner<K
if ( log.isInfoEnabled() )
{
log.info( "Failover runner is in primary recovery mode.
Failover index = "
- + facade.getRemoteCacheAttributes().getFailoverIndex()
+ "\n" + "Will now try to reconnect to primary server." );
+ + rca0.getFailoverIndex() + "\n" + "Will now try to
reconnect to primary server." );
}
}
boolean primaryRestoredSuccessfully = false;
// if we are not connected to the primary, try.
- if ( facade.getRemoteCacheAttributes().getFailoverIndex() > 0 )
+ if ( rca0.getFailoverIndex() > 0 )
{
primaryRestoredSuccessfully = restorePrimary();
if ( log.isDebugEnabled() )
@@ -287,7 +272,7 @@ public class RemoteCacheFailoverRunner<K
// try to bring the listener back to the primary
}
- while ( facade.getRemoteCacheAttributes().getFailoverIndex() > 0 ||
!allright.get() );
+ while ( rca0.getFailoverIndex() > 0 || !allright.get() );
// continue if the primary is not restored or if things are not
allright.
}
@@ -301,19 +286,18 @@ public class RemoteCacheFailoverRunner<K
*
* @return boolean value indicating whether the restoration was successful
*/
- @SuppressWarnings("unchecked") // No generic arrays in java
private boolean restorePrimary()
{
+ IRemoteCacheAttributes rca0 = facade.getAuxiliaryCacheAttributes();
// try to move back to the primary
- RemoteLocation[] failovers =
facade.getRemoteCacheAttributes().getFailovers();
- RemoteLocation server = failovers[0];
+ RemoteLocation server = rca0.getFailovers().get(0);
if ( log.isInfoEnabled() )
{
log.info( "Trying to restore connection to primary remote server
[" + server + "]" );
}
- RemoteCacheAttributes rca = (RemoteCacheAttributes)
facade.getRemoteCacheAttributes().clone();
+ RemoteCacheAttributes rca = (RemoteCacheAttributes) rca0.clone();
rca.setRemoteLocation(server);
RemoteCacheManager rcm = RemoteCacheFactory.getManager( rca, cacheMgr,
facade.getCacheEventLogger(), facade.getElementSerializer() );
@@ -336,13 +320,13 @@ public class RemoteCacheFailoverRunner<K
// now.
// this will not result in a loop, only duplication
// stop duplicate listening.
- if ( facade.noWaits[0] != null &&
facade.noWaits[0].getStatus() == CacheStatus.ALIVE )
+ if ( facade.getPrimaryServer() != null &&
facade.getPrimaryServer().getStatus() == CacheStatus.ALIVE )
{
- int fidx =
facade.getRemoteCacheAttributes().getFailoverIndex();
+ int fidx = rca0.getFailoverIndex();
if ( fidx > 0 )
{
- RemoteLocation serverOld = failovers[fidx];
+ RemoteLocation serverOld =
rca0.getFailovers().get(fidx);
if ( log.isDebugEnabled() )
{
@@ -354,7 +338,7 @@ public class RemoteCacheFailoverRunner<K
{
// create attributes that reflect the
// previous failed over configuration.
- RemoteCacheAttributes rcaOld =
(RemoteCacheAttributes) facade.getRemoteCacheAttributes().clone();
+ RemoteCacheAttributes rcaOld =
(RemoteCacheAttributes) rca0.clone();
rcaOld.setRemoteLocation(serverOld);
RemoteCacheManager rcmOld =
RemoteCacheFactory.getManager( rcaOld, cacheMgr,
facade.getCacheEventLogger(),
facade.getElementSerializer() );
@@ -398,12 +382,11 @@ public class RemoteCacheFailoverRunner<K
// Restore primary
// may need to do this more gracefully, letting the failover
finish in the background
- RemoteCacheNoWait<K, V> failoverNoWait = facade.noWaits[0];
+ RemoteCacheNoWait<K, V> failoverNoWait = facade.getPrimaryServer();
// swap in a new one
- facade.noWaits = new RemoteCacheNoWait[1];
- facade.noWaits[0] = (RemoteCacheNoWait<K, V>) ic;
- facade.getRemoteCacheAttributes().setFailoverIndex( 0 );
+ facade.restorePrimaryServer((RemoteCacheNoWait<K, V>) ic);
+ rca0.setFailoverIndex( 0 );
if ( log.isInfoEnabled() )
{
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=1736200&r1=1736199&r2=1736200&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
Tue Mar 22 15:24:51 2016
@@ -19,8 +19,11 @@ package org.apache.commons.jcs.auxiliary
* under the License.
*/
+import java.util.List;
+
import org.apache.commons.jcs.auxiliary.remote.server.behavior.RemoteType;
import org.apache.commons.jcs.engine.CacheStatus;
+import org.apache.commons.jcs.engine.behavior.ICache;
import org.apache.commons.jcs.engine.behavior.ICompositeCacheManager;
import org.apache.commons.jcs.engine.behavior.IElementSerializer;
import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
@@ -50,7 +53,7 @@ public class RemoteCacheNoWaitFacade<K,
* @param cacheEventLogger
* @param elementSerializer
*/
- public RemoteCacheNoWaitFacade( RemoteCacheNoWait<K, V>[] noWaits,
+ public RemoteCacheNoWaitFacade( List<ICache<K, V>> noWaits,
RemoteCacheAttributes rca,
ICompositeCacheManager cacheMgr,
ICacheEventLogger cacheEventLogger,
@@ -62,19 +65,19 @@ public class RemoteCacheNoWaitFacade<K,
/**
* Begin the failover process if this is a local cache. Clustered remote
caches do not failover.
* <p>
- * @param i The no wait in error.
+ * @param rcnw The no wait in error.
*/
@Override
- protected void failover( int i )
+ protected void failover( RemoteCacheNoWait<K, V> rcnw )
{
if ( log.isDebugEnabled() )
{
- log.debug( "in failover for " + i );
+ log.debug( "in failover for " + rcnw );
}
- if ( getRemoteCacheAttributes().getRemoteType() == RemoteType.LOCAL )
+ if ( getAuxiliaryCacheAttributes().getRemoteType() == RemoteType.LOCAL
)
{
- if ( noWaits[i].getStatus() == CacheStatus.ERROR )
+ if ( rcnw.getStatus() == CacheStatus.ERROR )
{
// start failover, primary recovery process
RemoteCacheFailoverRunner<K, V> runner =
@@ -86,7 +89,7 @@ public class RemoteCacheNoWaitFacade<K,
if ( getCacheEventLogger() != null )
{
getCacheEventLogger().logApplicationEvent(
"RemoteCacheNoWaitFacade", "InitiatedFailover",
- noWaits[i] + "
was in error." );
+ rcnw + " was in
error." );
}
}
else
Modified:
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/behavior/IRemoteCacheAttributes.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/behavior/IRemoteCacheAttributes.java?rev=1736200&r1=1736199&r2=1736200&view=diff
==============================================================================
---
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/behavior/IRemoteCacheAttributes.java
(original)
+++
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/behavior/IRemoteCacheAttributes.java
Tue Mar 22 15:24:51 2016
@@ -1,5 +1,7 @@
package org.apache.commons.jcs.auxiliary.remote.behavior;
+import java.util.List;
+
import org.apache.commons.jcs.auxiliary.remote.RemoteLocation;
/*
@@ -65,14 +67,14 @@ public interface IRemoteCacheAttributes
* <p>
* @return The failovers value
*/
- RemoteLocation[] getFailovers();
+ List<RemoteLocation> getFailovers();
/**
* Sets the failovers attribute of the IRemoteCacheAttributes object
* <p>
- * @param f The new failovers value
+ * @param failovers The new failovers value
*/
- void setFailovers( RemoteLocation[] f );
+ void setFailovers( List<RemoteLocation> failovers );
/**
* Gets the localPort attribute of the IRemoteCacheAttributes object
Modified:
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheFactory.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheFactory.java?rev=1736200&r1=1736199&r2=1736200&view=diff
==============================================================================
---
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheFactory.java
(original)
+++
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheFactory.java
Tue Mar 22 15:24:51 2016
@@ -19,10 +19,12 @@ package org.apache.commons.jcs.auxiliary
* under the License.
*/
+import java.util.ArrayList;
+import java.util.HashMap;
+
import org.apache.commons.jcs.auxiliary.AbstractAuxiliaryCacheFactory;
import org.apache.commons.jcs.auxiliary.AuxiliaryCache;
import org.apache.commons.jcs.auxiliary.AuxiliaryCacheAttributes;
-import org.apache.commons.jcs.auxiliary.remote.RemoteCacheNoWait;
import org.apache.commons.jcs.auxiliary.remote.RemoteCacheNoWaitFacade;
import org.apache.commons.jcs.auxiliary.remote.server.behavior.RemoteType;
import org.apache.commons.jcs.engine.behavior.ICache;
@@ -30,9 +32,6 @@ import org.apache.commons.jcs.engine.beh
import org.apache.commons.jcs.engine.behavior.IElementSerializer;
import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
-import java.util.ArrayList;
-import java.util.HashMap;
-
/**
* The RemoteCacheFactory creates remote caches for the cache hub. It returns
a no wait facade which
* is a wrapper around a no wait. The no wait object is either an active
connection to a remote
@@ -73,10 +72,8 @@ public class RemoteHttpCacheFactory
ICache<K, V> ic = rcm.getCache( rca );
noWaits.add( ic );
- @SuppressWarnings("unchecked") // No generic arrays in java
- RemoteCacheNoWait<K, V>[] rcnwArray = noWaits.toArray( new
RemoteCacheNoWait[0] );
RemoteCacheNoWaitFacade<K, V> rcnwf =
- new RemoteCacheNoWaitFacade<K, V>(rcnwArray, rca, cacheMgr,
cacheEventLogger, elementSerializer );
+ new RemoteCacheNoWaitFacade<K, V>(noWaits, rca, cacheMgr,
cacheEventLogger, elementSerializer );
getFacades().put( rca.getCacheName(), rcnwf );