| 1 |
package org.apache.commons.jcs3.auxiliary.remote.http.client; |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
import java.io.IOException; |
| 23 |
|
| 24 |
import org.apache.commons.jcs3.auxiliary.remote.AbstractRemoteAuxiliaryCache; |
| 25 |
import org.apache.commons.jcs3.auxiliary.remote.behavior.IRemoteCacheListener; |
| 26 |
import org.apache.commons.jcs3.engine.ZombieCacheServiceNonLocal; |
| 27 |
import org.apache.commons.jcs3.engine.behavior.ICacheServiceNonLocal; |
| 28 |
import org.apache.commons.jcs3.log.Log; |
| 29 |
import org.apache.commons.jcs3.log.LogManager; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public class RemoteHttpCache<K, V> |
| 35 |
extends AbstractRemoteAuxiliaryCache<K, V> |
| 36 |
{ |
| 37 |
|
| 38 |
private static final Log log = LogManager.getLog( RemoteHttpCache.class ); |
| 39 |
|
| 40 |
|
| 41 |
private final RemoteHttpCacheMonitor monitor; |
| 42 |
|
| 43 |
|
| 44 |
private final RemoteHttpCacheAttributes remoteHttpCacheAttributes; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
public RemoteHttpCache( final RemoteHttpCacheAttributes remoteHttpCacheAttributes, final ICacheServiceNonLocal<K, V> remote, |
| 58 |
final IRemoteCacheListener<K, V> listener, final RemoteHttpCacheMonitor monitor ) |
| 59 |
{ |
| 60 |
super( remoteHttpCacheAttributes, remote, listener ); |
| 61 |
|
| 62 |
this.remoteHttpCacheAttributes = remoteHttpCacheAttributes; |
| 63 |
this.monitor = monitor; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
@Override |
| 75 |
protected void handleException( final Exception ex, final String msg, final String eventName ) |
| 76 |
throws IOException |
| 77 |
{ |
| 78 |
|
| 79 |
if ( !( getRemoteCacheService() instanceof ZombieCacheServiceNonLocal ) ) |
| 80 |
{ |
| 81 |
final String message = "Disabling remote cache due to error: " + msg; |
| 82 |
logError( cacheName, "", message ); |
| 83 |
log.error( message, ex ); |
| 84 |
|
| 85 |
setRemoteCacheService( new ZombieCacheServiceNonLocal<>( getRemoteCacheAttributes().getZombieQueueMaxSize() ) ); |
| 86 |
|
| 87 |
monitor.notifyError( this ); |
| 88 |
} |
| 89 |
|
| 90 |
if ( ex instanceof IOException ) |
| 91 |
{ |
| 92 |
throw (IOException) ex; |
| 93 |
} |
| 94 |
throw new IOException( ex.getMessage() ); |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
@Override |
| 101 |
public String getEventLoggingExtraInfo() |
| 102 |
{ |
| 103 |
return null; |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
public RemoteHttpCacheAttributes getRemoteHttpCacheAttributes() |
| 110 |
{ |
| 111 |
return remoteHttpCacheAttributes; |
| 112 |
} |
| 113 |
} |