package org.apache.commons.jcs3.auxiliary.remote; /* * 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. */ import java.io.IOException; import java.util.ArrayList; import org.apache.commons.jcs3.auxiliary.remote.behavior.IRemoteCacheAttributes; import org.apache.commons.jcs3.auxiliary.remote.behavior.IRemoteCacheListener; import org.apache.commons.jcs3.auxiliary.remote.server.behavior.RemoteType; import org.apache.commons.jcs3.engine.ZombieCacheServiceNonLocal; import org.apache.commons.jcs3.engine.behavior.ICacheServiceNonLocal; import org.apache.commons.jcs3.engine.stats.StatElement; import org.apache.commons.jcs3.engine.stats.Stats; import org.apache.commons.jcs3.engine.stats.behavior.IStatElement; import org.apache.commons.jcs3.engine.stats.behavior.IStats; import org.apache.commons.jcs3.log.Log; import org.apache.commons.jcs3.log.LogManager; /** * Client proxy for an RMI remote cache. *
* This handles gets, updates, and removes. It also initiates failover recovery when an error is
* encountered.
*/
public class RemoteCache
* @param cattr the cache configuration
* @param remote the remote cache server handle
* @param listener a listener
* @param monitor the cache monitor
*/
public RemoteCache( final IRemoteCacheAttributes cattr,
final ICacheServiceNonLocal
* @param ex
* @param msg
* @param eventName
* @throws IOException
*/
@Override
protected void handleException( final Exception ex, final String msg, final String eventName )
throws IOException
{
final String message = "Disabling remote cache due to error: " + msg;
logError( cacheName, "", message );
log.error( message, ex );
// we should not switch if the existing is a zombie.
if ( !( getRemoteCacheService() instanceof ZombieCacheServiceNonLocal ) )
{
// TODO make configurable
setRemoteCacheService( new ZombieCacheServiceNonLocal<>( getRemoteCacheAttributes().getZombieQueueMaxSize() ) );
}
// may want to flush if region specifies
// Notify the cache monitor about the error, and kick off the recovery
// process.
monitor.notifyError();
log.debug( "Initiating failover, rcnwf = {0}", facade );
if ( facade != null && facade.getAuxiliaryCacheAttributes().getRemoteType() == RemoteType.LOCAL )
{
log.debug( "Found facade, calling failover" );
// may need to remove the noWait index here. It will be 0 if it is
// local since there is only 1 possible listener.
facade.failover( facade.getPrimaryServer() );
}
if ( ex instanceof IOException )
{
throw (IOException) ex;
}
throw new IOException( ex );
}
/**
* Debugging info.
*
* @return basic info about the RemoteCache
*/
@Override
public String toString()
{
return "RemoteCache: " + cacheName + " attributes = " + getRemoteCacheAttributes();
}
/**
* Gets the extra info for the event log.
*
* @return disk location
*/
@Override
public String getEventLoggingExtraInfo()
{
return getIPAddressForService();
}
/**
* IP address for the service, if one is stored.
*
* Protected for testing.
*
* @return String
*/
protected String getIPAddressForService()
{
String ipAddress = "(null)";
if (this.getRemoteCacheAttributes().getRemoteLocation() != null)
{
ipAddress = this.getRemoteCacheAttributes().getRemoteLocation().toString();
}
return ipAddress;
}
}