in commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheFactory.java [65:146]
public <K, V> AuxiliaryCache<K, V> createCache(
final AuxiliaryCacheAttributes iaca, final ICompositeCacheManager cacheMgr,
final ICacheEventLogger cacheEventLogger, final IElementSerializer elementSerializer )
{
final RemoteCacheAttributes rca = (RemoteCacheAttributes) iaca;
final ArrayList<RemoteCacheNoWait<K,V>> noWaits = new ArrayList<>();
switch (rca.getRemoteType())
{
case LOCAL:
// a list to be turned into an array of failover server information
final ArrayList<RemoteLocation> failovers = new ArrayList<>();
// not necessary if a failover list is defined
// REGISTER PRIMARY LISTENER
// if it is a primary
if ( rca.getRemoteLocation() != null )
{
failovers.add( rca.getRemoteLocation() );
final RemoteCacheManager rcm = getManager( rca, cacheMgr, cacheEventLogger, elementSerializer );
noWaits.add(rcm.getCache(rca));
}
// GET HANDLE BUT DON'T REGISTER A LISTENER FOR FAILOVERS
final String failoverList = rca.getFailoverServers();
if (failoverList != null && !failoverList.isEmpty())
{
final String[] failoverServers = failoverList.split("\\s*,\\s*");
for (String server : failoverServers)
{
final RemoteLocation location = RemoteLocation.parseServerAndPort(server);
if (location != null)
{
failovers.add( location );
final RemoteCacheAttributes frca = (RemoteCacheAttributes) rca.clone();
frca.setRemoteLocation(location);
final RemoteCacheManager rcm = getManager( frca, cacheMgr, cacheEventLogger, elementSerializer );
// add a listener if there are none, need to tell rca what
// number it is at
if (noWaits.isEmpty())
{
frca.setFailoverIndex(0);
noWaits.add(rcm.getCache(frca));
}
}
}
// end for
}
// end if failoverList != null
rca.setFailovers( failovers );
break;
case CLUSTER:
// REGISTER LISTENERS FOR EACH SYSTEM CLUSTERED CACHEs
final String[] clusterServers = rca.getClusterServers().split("\\s*,\\s*");
for (String server: clusterServers)
{
if (server.isEmpty())
{
continue;
}
final RemoteLocation location = RemoteLocation.parseServerAndPort(server);
if (location != null)
{
final RemoteCacheAttributes crca = (RemoteCacheAttributes) rca.clone();
crca.setRemoteLocation(location);
final RemoteCacheManager rcm = getManager( crca, cacheMgr, cacheEventLogger, elementSerializer );
crca.setRemoteType( RemoteType.CLUSTER );
noWaits.add(rcm.getCache(crca));
}
}
break;
}
return new RemoteCacheNoWaitFacade<>(noWaits, rca, cacheEventLogger, elementSerializer, this);
}