/** * @see org.apache.commons.jcs.auxiliary.AbstractAuxiliaryCacheFactory#initialize() */ @Override public void initialize() { super.initialize(); monitor = new RemoteHttpCacheMonitor(this); monitor.setDaemon(true); monitor.start(); }
/** * Notifies the cache monitor that an error occurred, and kicks off the error recovery process. * <p> * @param remoteCache */ public void notifyError( RemoteHttpCache<?, ?> remoteCache ) { if ( log.isInfoEnabled() ) { log.info( "Notified of an error. " + remoteCache ); } remoteHttpCaches.put( remoteCache, remoteCache ); notifyError(); }
/** * Notifies the cache monitor that an error occurred, and kicks off the error recovery process. * <p> * @param remoteCache */ public void notifyError( RemoteHttpCache<?, ?> remoteCache ) { if ( log.isInfoEnabled() ) { log.info( "Notified of an error. " + remoteCache ); } bad(); synchronized ( this ) { remoteHttpCaches.add( remoteCache ); notify(); } }
/** * @see org.apache.commons.jcs.auxiliary.AbstractAuxiliaryCacheFactory#dispose() */ @Override public void dispose() { if (monitor != null) { monitor.notifyShutdown(); try { monitor.join(5000); } catch (InterruptedException e) { // swallow } monitor = null; } super.dispose(); } }
/** * Nothing right now. This should setup a zombie and initiate recovery. * <p> * @param ex * @param msg * @param eventName * @throws IOException */ @Override protected void handleException( Exception ex, String msg, String eventName ) throws IOException { // we should not switch if the existing is a zombie. if ( !( getRemoteCacheService() instanceof ZombieCacheServiceNonLocal ) ) { String message = "Disabling remote cache due to error: " + msg; logError( cacheName, "", message ); log.error( message, ex ); setRemoteCacheService( new ZombieCacheServiceNonLocal<K, V>( getRemoteCacheAttributes().getZombieQueueMaxSize() ) ); RemoteHttpCacheMonitor.getInstance().notifyError( this ); } if ( ex instanceof IOException ) { throw (IOException) ex; } throw new IOException( ex.getMessage() ); }
/** * Returns the singleton instance. * <p> * @return The instance value */ static RemoteHttpCacheMonitor getInstance() { synchronized ( RemoteHttpCacheMonitor.class ) { if ( instance == null ) { return instance = new RemoteHttpCacheMonitor(); } } return instance; }
/** * Constructor for the RemoteCacheMonitor object * * @param factory the factory to set */ public RemoteHttpCacheMonitor(RemoteHttpCacheFactory factory) { super("JCS-RemoteHttpCacheMonitor"); this.factory = factory; this.remoteHttpCaches = new ConcurrentHashMap<RemoteHttpCache<?, ?>, RemoteHttpCache<?, ?>>(); setIdlePeriod(3000L); }
monitor = RemoteHttpCacheMonitor.getInstance();
/** * Nothing right now. This should setup a zombie and initiate recovery. * <p> * @param ex * @param msg * @param eventName * @throws IOException */ @Override protected void handleException( Exception ex, String msg, String eventName ) throws IOException { // we should not switch if the existing is a zombie. if ( !( getRemoteCacheService() instanceof ZombieCacheServiceNonLocal ) ) { String message = "Disabling remote cache due to error: " + msg; logError( cacheName, "", message ); log.error( message, ex ); setRemoteCacheService( new ZombieCacheServiceNonLocal<K, V>( getRemoteCacheAttributes().getZombieQueueMaxSize() ) ); monitor.notifyError( this ); } if ( ex instanceof IOException ) { throw (IOException) ex; } throw new IOException( ex.getMessage() ); }