/** * The most commonly used factory method. * <p> * @param listener * @param listenerId * @param cacheName * @param threadPoolName * @param poolType - SINGLE, POOLED * @return ICacheEventQueue */ public ICacheEventQueue<K, V> createCacheEventQueue( ICacheListener<K, V> listener, long listenerId, String cacheName, String threadPoolName, ICacheEventQueue.QueueType poolType ) { return createCacheEventQueue( listener, listenerId, cacheName, 10, 500, threadPoolName, poolType ); }
/** * Construct the abstract disk cache, create event queues and purgatory. Child classes should * set the alive flag to true after they are initialized. * * @param attr */ protected AbstractDiskCache( IDiskCacheAttributes attr ) { this.diskCacheAttributes = attr; this.cacheName = attr.getCacheName(); // create queue CacheEventQueueFactory<K, V> fact = new CacheEventQueueFactory<K, V>(); this.cacheEventQueue = fact.createCacheEventQueue( new MyCacheListener(), CacheInfo.listenerId, cacheName, diskCacheAttributes.getEventQueuePoolName(), diskCacheAttributes.getEventQueueType() ); // create purgatory initPurgatory(); }
/** * Construct the abstract disk cache, create event queues and purgatory. Child classes should * set the alive flag to true after they are initialized. * <p> * @param attr */ public AbstractDiskCache( IDiskCacheAttributes attr ) { this.diskCacheAttributes = attr; this.cacheName = attr.getCacheName(); // create queue CacheEventQueueFactory<K, V> fact = new CacheEventQueueFactory<K, V>(); this.cacheEventQueue = fact.createCacheEventQueue( new MyCacheListener(), CacheInfo.listenerId, cacheName, diskCacheAttributes.getEventQueuePoolName(), diskCacheAttributes.getEventQueueType() ); // create purgatory initPurgatory(); }
/** * Create a cache event queue from the parameters of the remote client * @param client the remote client */ private ICacheEventQueue<K, V> createCacheEventQueue( IRemoteCacheClient<K, V> client ) { CacheEventQueueFactory<K, V> factory = new CacheEventQueueFactory<K, V>(); ICacheEventQueue<K, V> ceq = factory.createCacheEventQueue( new CacheAdaptor<K, V>( client ), client.getListenerId(), client.getCacheName(), client.getAuxiliaryCacheAttributes().getEventQueuePoolName(), client.getAuxiliaryCacheAttributes().getEventQueueType() ); return ceq; }
/** * The most commonly used factory method. * <p> * @param listener * @param listenerId * @param cacheName * @param threadPoolName * @param poolType - SINGLE, POOLED * @return ICacheEventQueue */ public ICacheEventQueue<K, V> createCacheEventQueue( ICacheListener<K, V> listener, long listenerId, String cacheName, String threadPoolName, ICacheEventQueue.QueueType poolType ) { return createCacheEventQueue( listener, listenerId, cacheName, 10, 500, threadPoolName, poolType ); }
/** Test create */ public void testCreateCacheEventQueue_Single() { // SETUP QueueType eventQueueType = QueueType.SINGLE; ICacheListener<String, String> listener = new MockRemoteCacheListener<String, String>(); long listenerId = 1; CacheEventQueueFactory<String, String> factory = new CacheEventQueueFactory<String, String>(); // DO WORK ICacheEventQueue<String, String> result = factory.createCacheEventQueue( listener, listenerId, "cacheName", "threadPoolName", eventQueueType ); // VERIFY assertNotNull( "Should have a result", result ); assertTrue( "Wrong type", result instanceof CacheEventQueue ); }
/** * Resets the event q by first destroying the existing one and starting up new one. */ public void resetEventQ() { if ( eventQueue.isWorking() ) { eventQueue.destroy(); } CacheEventQueueFactory<K, V> fact = new CacheEventQueueFactory<K, V>(); this.eventQueue = fact.createCacheEventQueue( new CacheAdaptor<K, V>( cache ), CacheInfo.listenerId, cache .getCacheName(), cache.getAuxiliaryCacheAttributes().getEventQueuePoolName(), cache .getAuxiliaryCacheAttributes().getEventQueueType() ); }
/** Test create */ public void testCreateCacheEventQueue_Pooled() { // SETUP QueueType eventQueueType = QueueType.POOLED; ICacheListener<String, String> listener = new MockRemoteCacheListener<String, String>(); long listenerId = 1; CacheEventQueueFactory<String, String> factory = new CacheEventQueueFactory<String, String>(); // DO WORK ICacheEventQueue<String, String> result = factory.createCacheEventQueue( listener, listenerId, "cacheName", "threadPoolName", eventQueueType ); // VERIFY assertNotNull( "Should have a result", result ); assertTrue( "Wrong type", result instanceof PooledCacheEventQueue ); } }
/** Test create */ public void testCreateCacheEventQueue_Pooled() { // SETUP QueueType eventQueueType = QueueType.POOLED; ICacheListener<String, String> listener = new MockRemoteCacheListener<String, String>(); long listenerId = 1; CacheEventQueueFactory<String, String> factory = new CacheEventQueueFactory<String, String>(); // DO WORK ICacheEventQueue<String, String> result = factory.createCacheEventQueue( listener, listenerId, "cacheName", "threadPoolName", eventQueueType ); // VERIFY assertNotNull( "Should have a result", result ); assertTrue( "Wrong type", result instanceof PooledCacheEventQueue ); } }
/** * Resets the event q by first destroying the existing one and starting up new one. */ public void resetEventQ() { if ( eventQueue.isWorking() ) { eventQueue.destroy(); } CacheEventQueueFactory<K, V> fact = new CacheEventQueueFactory<K, V>(); this.eventQueue = fact.createCacheEventQueue( new CacheAdaptor<K, V>( cache ), CacheInfo.listenerId, cache .getCacheName(), cache.getAuxiliaryCacheAttributes().getEventQueuePoolName(), cache .getAuxiliaryCacheAttributes().getEventQueueType() ); }
/** Test create */ public void testCreateCacheEventQueue_Single() { // SETUP QueueType eventQueueType = QueueType.SINGLE; ICacheListener<String, String> listener = new MockRemoteCacheListener<String, String>(); long listenerId = 1; CacheEventQueueFactory<String, String> factory = new CacheEventQueueFactory<String, String>(); // DO WORK ICacheEventQueue<String, String> result = factory.createCacheEventQueue( listener, listenerId, "cacheName", "threadPoolName", eventQueueType ); // VERIFY assertNotNull( "Should have a result", result ); assertTrue( "Wrong type", result instanceof CacheEventQueue ); }
/** * Constructs with the given lateral cache, and fires up an event queue for asynchronous * processing. * <p> * @param cache */ public LateralCacheNoWait( LateralCache<K, V> cache ) { this.cache = cache; if ( log.isDebugEnabled() ) { log.debug( "Constructing LateralCacheNoWait, LateralCache = [" + cache + "]" ); } CacheEventQueueFactory<K, V> fact = new CacheEventQueueFactory<K, V>(); this.eventQueue = fact.createCacheEventQueue( new CacheAdaptor<K, V>( cache ), CacheInfo.listenerId, cache .getCacheName(), cache.getAuxiliaryCacheAttributes().getEventQueuePoolName(), cache .getAuxiliaryCacheAttributes().getEventQueueType() ); // need each no wait to handle each of its real updates and removes, // since there may // be more than one per cache? alternative is to have the cache // perform updates using a different method that specifies the listener // this.q = new CacheEventQueue(new CacheAdaptor(this), // LateralCacheInfo.listenerId, cache.getCacheName()); if ( cache.getStatus() == CacheStatus.ERROR ) { eventQueue.destroy(); } }
CacheEventQueueFactory<KK, VV> fact = new CacheEventQueueFactory<KK, VV>(); ICacheEventQueue<KK, VV> q = fact.createCacheEventQueue( listener, id, cacheName, remoteCacheServerAttributes .getEventQueuePoolName(), remoteCacheServerAttributes.getEventQueueType() );
/** * Constructs with the given lateral cache, and fires up an event queue for asynchronous * processing. * <p> * @param cache */ public LateralCacheNoWait( LateralCache<K, V> cache ) { this.cache = cache; if ( log.isDebugEnabled() ) { log.debug( "Constructing LateralCacheNoWait, LateralCache = [" + cache + "]" ); } CacheEventQueueFactory<K, V> fact = new CacheEventQueueFactory<K, V>(); this.eventQueue = fact.createCacheEventQueue( new CacheAdaptor<K, V>( cache ), CacheInfo.listenerId, cache .getCacheName(), cache.getAuxiliaryCacheAttributes().getEventQueuePoolName(), cache .getAuxiliaryCacheAttributes().getEventQueueType() ); // need each no wait to handle each of its real updates and removes, // since there may // be more than one per cache? alternative is to have the cache // perform updates using a different method that specifies the listener // this.q = new CacheEventQueue(new CacheAdaptor(this), // LateralCacheInfo.listenerId, cache.getCacheName()); if ( cache.getStatus() == CacheStatus.ERROR ) { eventQueue.destroy(); } }
CacheEventQueueFactory<KK, VV> fact = new CacheEventQueueFactory<KK, VV>(); ICacheEventQueue<KK, VV> q = fact.createCacheEventQueue( listener, id, cacheName, remoteCacheServerAttributes .getEventQueuePoolName(), remoteCacheServerAttributes.getEventQueueType() );
/** * Resets the event q by first destroying the existing one and starting up new one. * <p> * There may be no good reason to kill the existing queue. We will sometimes need to set a new * listener id, so we should create a new queue. We should let the old queue drain. If we were * Connected to the failover, it would be best to finish sending items. */ public void resetEventQ() { ICacheEventQueue<K, V> previousQueue = cacheEventQueue; CacheEventQueueFactory<K, V> fact = new CacheEventQueueFactory<K, V>(); this.cacheEventQueue = fact.createCacheEventQueue( new CacheAdaptor<K, V>( remoteCacheClient ), remoteCacheClient .getListenerId(), remoteCacheClient.getCacheName(), remoteCacheClient.getAuxiliaryCacheAttributes() .getEventQueuePoolName(), remoteCacheClient.getAuxiliaryCacheAttributes().getEventQueueType() ); if ( previousQueue.isWorking() ) { // we don't expect anything, it would have all gone to the zombie if ( log.isInfoEnabled() ) { log.info( "resetEventQ, previous queue has [" + previousQueue.size() + "] items queued up." ); } previousQueue.destroy(); } }
/** * Constructs with the given remote cache, and fires up an event queue for asynchronous * processing. * <p> * @param cache */ public RemoteCacheNoWait( IRemoteCacheClient<K, V> cache ) { remoteCacheClient = cache; CacheEventQueueFactory<K, V> factory = new CacheEventQueueFactory<K, V>(); this.cacheEventQueue = factory.createCacheEventQueue( new CacheAdaptor<K, V>( remoteCacheClient ), remoteCacheClient .getListenerId(), remoteCacheClient.getCacheName(), remoteCacheClient.getAuxiliaryCacheAttributes() .getEventQueuePoolName(), remoteCacheClient.getAuxiliaryCacheAttributes().getEventQueueType() ); if ( remoteCacheClient.getStatus() == CacheStatus.ERROR ) { cacheEventQueue.destroy(); } }