protected <K, V> LateralCacheNoWait<K, V> createCacheNoWait( ITCPLateralCacheAttributes lca, ICacheEventLogger cacheEventLogger, IElementSerializer elementSerializer ) { ICacheServiceNonLocal<K, V> lateralService = getCSNLInstance(lca); LateralCache<K, V> cache = new LateralCache<K, V>( lca, lateralService, this.monitor ); cache.setCacheEventLogger( cacheEventLogger ); cache.setElementSerializer( elementSerializer ); if ( log.isDebugEnabled() ) { log.debug( "Created cache for noWait, cache [" + cache + "]" ); } LateralCacheNoWait<K, V> lateralNoWait = new LateralCacheNoWait<K, V>( cache ); lateralNoWait.setCacheEventLogger( cacheEventLogger ); lateralNoWait.setElementSerializer( elementSerializer ); if ( log.isInfoEnabled() ) { log.info( "Created LateralCacheNoWait for [" + lca + "] LateralCacheNoWait = [" + lateralNoWait + "]" ); } return lateralNoWait; }
/** Adds a dispose request to the lateral cache. */ @Override public void dispose() { try { if ( listener != null ) { listener.dispose(); listener = null; } for ( int i = 0; i < noWaits.length; i++ ) { noWaits[i].dispose(); } } catch ( Exception ex ) { log.error( ex ); } finally { disposed = true; } }
if ( c.getStatus() == CacheStatus.ERROR ) ITCPLateralCacheAttributes lca = (ITCPLateralCacheAttributes)c.getAuxiliaryCacheAttributes(); c.fixCache(cacheService);
/** * Remove a no wait from an unknown facade. */ public void testRemoveNoWait_FacadeNotInList() { // SETUP String cacheName = "testRemoveNoWaitFacade_FacadeNotInList"; ILateralCacheAttributes cattr = new LateralCacheAttributes(); cattr.setCacheName( cacheName ); LateralCache<String, String> cache = new LateralCache<String, String>( cattr ); LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<String, String>( cache ); // DO WORK boolean result = listener.removeNoWait( noWait ); // VERIFY assertFalse( "Should not have removed the no wait.", result ); }
for (int i = 0; i < noWaits.length; i++) statii[i] = noWaits[i].getStatus();
/** * Allows us to see if the facade is present and if it has the no wait. * <p> * @param cacheName - facades are for a region * @param noWait - is this no wait in the facade * @return do we contain the no wait. true if so */ public <K, V> boolean containsNoWait( String cacheName, LateralCacheNoWait<K, V> noWait ) { @SuppressWarnings("unchecked") // Need to cast because of common map for all facades LateralCacheNoWaitFacade<K, V> facade = (LateralCacheNoWaitFacade<K, V>)facades.get( noWait.getCacheName() ); if ( facade == null ) { return false; } return facade.containsNoWait( noWait ); }
/** * getStats * @return String */ @Override public String getStats() { return getStatistics().toString(); }
/** * Synchronously reads from the lateral cache. * <p> * @param key * @return ICacheElement */ @Override public ICacheElement<K, V> get( K key ) { for ( int i = 0; i < noWaits.length; i++ ) { try { ICacheElement<K, V> obj = noWaits[i].get( key ); if ( obj != null ) { // TODO: return after first success // could do this simultaneously // serious blocking risk here return obj; } } catch ( Exception ex ) { log.error( "Failed to get", ex ); } } return null; }
/** * Adds a remove request to the lateral cache. * <p> * @param key * @return always false. */ @Override public boolean remove( K key ) { try { for ( int i = 0; i < noWaits.length; i++ ) { noWaits[i].remove( key ); } } catch ( Exception ex ) { log.error( ex ); } return false; }
/** * Synchronously reads from the lateral cache. Get a response from each! This will be slow. * Merge them. * <p> * @param pattern * @return ICacheElement */ @Override public Map<K, ICacheElement<K, V>> getMatching(String pattern) { Map<K, ICacheElement<K, V>> elements = new HashMap<K, ICacheElement<K, V>>(); for ( int i = 0; i < noWaits.length; i++ ) { try { elements.putAll( noWaits[i].getMatching( pattern ) ); } catch ( Exception ex ) { log.error( "Failed to get", ex ); } } return elements; }
/** * Add a no wait from an unknown facade. */ public void testAddNoWait_FacadeNotInList() { // SETUP String cacheName = "testAddNoWaitFacade_FacadeInList"; ILateralCacheAttributes cattr = new LateralCacheAttributes(); cattr.setCacheName( cacheName ); LateralCache<String, String> cache = new LateralCache<String, String>( cattr ); LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<String, String>( cache ); // DO WORK boolean result = listener.addNoWait( noWait ); // VERIFY assertFalse( "Should not have added the no wait.", result ); }
for (int i = 0; i < noWaits.length; i++) statii[i] = noWaits[i].getStatus();
LateralCacheNoWaitFacade<K, V> facade = (LateralCacheNoWaitFacade<K, V>)facades.get( noWait.getCacheName() ); if ( log.isDebugEnabled() ) log.debug( "removeNoWait > Got facade for " + noWait.getCacheName() + " = " + facade ); if ( !knownDifferentlyConfiguredRegions.contains( noWait.getCacheName() ) ) + noWait.getCacheName() + "] is not yet used on this side. " ); knownDifferentlyConfiguredRegions.add( noWait.getCacheName() );
/** * getStats * @return String */ @Override public String getStats() { return getStatistics().toString(); }
/** * Synchronously reads from the lateral cache. * <p> * @param key * @return ICacheElement */ @Override public ICacheElement<K, V> get( K key ) { for ( int i = 0; i < noWaits.length; i++ ) { try { ICacheElement<K, V> obj = noWaits[i].get( key ); if ( obj != null ) { // TODO: return after first success // could do this simultaneously // serious blocking risk here return obj; } } catch ( Exception ex ) { log.error( "Failed to get", ex ); } } return null; }
/** * Adds a remove request to the lateral cache. * <p> * @param key * @return always false. */ @Override public boolean remove( K key ) { try { for ( int i = 0; i < noWaits.length; i++ ) { noWaits[i].remove( key ); } } catch ( Exception ex ) { log.error( ex ); } return false; }
/** * Synchronously reads from the lateral cache. Get a response from each! This will be slow. * Merge them. * <p> * @param pattern * @return ICacheElement */ @Override public Map<K, ICacheElement<K, V>> getMatching(String pattern) { Map<K, ICacheElement<K, V>> elements = new HashMap<K, ICacheElement<K, V>>(); for ( int i = 0; i < noWaits.length; i++ ) { try { elements.putAll( noWaits[i].getMatching( pattern ) ); } catch ( Exception ex ) { log.error( "Failed to get", ex ); } } return elements; }
/** * Add a no wait from an unknown facade. */ public void testAddNoWait_FacadeNotInList() { // SETUP String cacheName = "testAddNoWaitFacade_FacadeInList"; ILateralCacheAttributes cattr = new LateralCacheAttributes(); cattr.setCacheName( cacheName ); LateralCache<String, String> cache = new LateralCache<String, String>( cattr ); LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<String, String>( cache ); // DO WORK boolean result = listener.addNoWait( noWait ); // VERIFY assertFalse( "Should not have added the no wait.", result ); }
protected <K, V> LateralCacheNoWait<K, V> createCacheNoWait( ITCPLateralCacheAttributes lca, ICacheEventLogger cacheEventLogger, IElementSerializer elementSerializer ) { ICacheServiceNonLocal<K, V> lateralService = getCSNLInstance(lca); LateralCache<K, V> cache = new LateralCache<K, V>( lca, lateralService, this.monitor ); cache.setCacheEventLogger( cacheEventLogger ); cache.setElementSerializer( elementSerializer ); if ( log.isDebugEnabled() ) { log.debug( "Created cache for noWait, cache [" + cache + "]" ); } LateralCacheNoWait<K, V> lateralNoWait = new LateralCacheNoWait<K, V>( cache ); lateralNoWait.setCacheEventLogger( cacheEventLogger ); lateralNoWait.setElementSerializer( elementSerializer ); if ( log.isInfoEnabled() ) { log.info( "Created LateralCacheNoWait for [" + lca + "] LateralCacheNoWait = [" + lateralNoWait + "]" ); } return lateralNoWait; }
LateralCacheNoWait<Serializable, Serializable> c = (LateralCacheNoWait<Serializable, Serializable>) entry.getValue(); if ( c.getStatus() == CacheStatus.ERROR ) ITCPLateralCacheAttributes lca = (ITCPLateralCacheAttributes)c.getAuxiliaryCacheAttributes(); c.fixCache(cacheService);