/** * Adds a no wait to the list if it isn't already in the list. * <p> * @param noWait * @return true if it wasn't already contained */ public synchronized boolean addNoWait( LateralCacheNoWait<K, V> noWait ) { if ( noWait == null ) { return false; } if ( containsNoWait( noWait ) ) { if ( log.isDebugEnabled() ) { log.debug( "No Wait already contained, [" + noWait + "]" ); } return false; } @SuppressWarnings("unchecked") // No generic arrays in java LateralCacheNoWait<K, V>[] newArray = new LateralCacheNoWait[noWaits.length + 1]; System.arraycopy( noWaits, 0, newArray, 0, noWaits.length ); // set the last position to the new noWait newArray[noWaits.length] = noWait; noWaits = newArray; return true; }
/** * Adds a no wait to the list if it isn't already in the list. * <p> * @param noWait * @return true if it wasn't already contained */ public synchronized boolean addNoWait( LateralCacheNoWait<K, V> noWait ) { if ( noWait == null ) { return false; } if ( containsNoWait( noWait ) ) { if ( log.isDebugEnabled() ) { log.debug( "No Wait already contained, [" + noWait + "]" ); } return false; } @SuppressWarnings("unchecked") // No generic arrays in java LateralCacheNoWait<K, V>[] newArray = new LateralCacheNoWait[noWaits.length + 1]; System.arraycopy( noWaits, 0, newArray, 0, noWaits.length ); // set the last position to the new noWait newArray[noWaits.length] = noWait; noWaits = newArray; return true; }
/** * 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 ); }
/** * 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 ); }
/** * Verify that we can remove an item. */ public void testAddThenRemoveNoWait_InListSize2() { // SETUP @SuppressWarnings("unchecked") LateralCacheNoWait<String, String>[] noWaits = new LateralCacheNoWait[0]; ILateralCacheAttributes cattr = new LateralCacheAttributes(); cattr.setCacheName( "testCache1" ); LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<String, String>( null, noWaits, cattr ); LateralCache<String, String> cache = new LateralCache<String, String>( cattr ); LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<String, String>( cache ); LateralCacheNoWait<String, String> noWait2 = new LateralCacheNoWait<String, String>( cache ); // DO WORK facade.addNoWait( noWait ); facade.addNoWait( noWait2 ); // VERIFY assertEquals( "Should have 2", 2, facade.noWaits.length ); assertTrue( "Should be in the list.", facade.containsNoWait( noWait ) ); assertTrue( "Should be in the list.", facade.containsNoWait( noWait2 ) ); // DO WORK facade.removeNoWait( noWait ); // VERIFY assertEquals( "Should only have 1", 1, facade.noWaits.length ); assertFalse( "Should not be in the list. ", facade.containsNoWait( noWait ) ); assertTrue( "Should be in the list.", facade.containsNoWait( noWait2 ) ); }
/** * Verify that we can remove an item. */ public void testAddThenRemoveNoWait_InListSize2() { // SETUP @SuppressWarnings("unchecked") LateralCacheNoWait<String, String>[] noWaits = new LateralCacheNoWait[0]; ILateralCacheAttributes cattr = new LateralCacheAttributes(); cattr.setCacheName( "testCache1" ); LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<String, String>( null, noWaits, cattr ); LateralCache<String, String> cache = new LateralCache<String, String>( cattr ); LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<String, String>( cache ); LateralCacheNoWait<String, String> noWait2 = new LateralCacheNoWait<String, String>( cache ); // DO WORK facade.addNoWait( noWait ); facade.addNoWait( noWait2 ); // VERIFY assertEquals( "Should have 2", 2, facade.noWaits.length ); assertTrue( "Should be in the list.", facade.containsNoWait( noWait ) ); assertTrue( "Should be in the list.", facade.containsNoWait( noWait2 ) ); // DO WORK facade.removeNoWait( noWait ); // VERIFY assertEquals( "Should only have 1", 1, facade.noWaits.length ); assertFalse( "Should not be in the list. ", facade.containsNoWait( noWait ) ); assertTrue( "Should be in the list.", facade.containsNoWait( noWait2 ) ); }
/** * Verify that we can remove an item. */ public void testAddThenRemoveNoWait_InList() { // SETUP @SuppressWarnings("unchecked") LateralCacheNoWait<String, String>[] noWaits = new LateralCacheNoWait[0]; ILateralCacheAttributes cattr = new LateralCacheAttributes(); cattr.setCacheName( "testCache1" ); LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<String, String>( null, noWaits, cattr ); LateralCache<String, String> cache = new LateralCache<String, String>( cattr ); LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<String, String>( cache ); // DO WORK facade.addNoWait( noWait ); // VERIFY assertTrue( "Should be in the list.", facade.containsNoWait( noWait ) ); // DO WORK facade.removeNoWait( noWait ); // VERIFY assertEquals( "Should have 0", 0, facade.noWaits.length ); assertFalse( "Should not be in the list. ", facade.containsNoWait( noWait ) ); }
/** * Verify that we can remove an item. */ public void testAddThenRemoveNoWait_InList() { // SETUP @SuppressWarnings("unchecked") LateralCacheNoWait<String, String>[] noWaits = new LateralCacheNoWait[0]; ILateralCacheAttributes cattr = new LateralCacheAttributes(); cattr.setCacheName( "testCache1" ); LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<String, String>( null, noWaits, cattr ); LateralCache<String, String> cache = new LateralCache<String, String>( cattr ); LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<String, String>( cache ); // DO WORK facade.addNoWait( noWait ); // VERIFY assertTrue( "Should be in the list.", facade.containsNoWait( noWait ) ); // DO WORK facade.removeNoWait( noWait ); // VERIFY assertEquals( "Should have 0", 0, facade.noWaits.length ); assertFalse( "Should not be in the list. ", facade.containsNoWait( noWait ) ); }
/** * Verify that we can remove an item. */ public void testAddThenRemoveNoWait_NotInList() { // SETUP @SuppressWarnings("unchecked") LateralCacheNoWait<String, String>[] noWaits = new LateralCacheNoWait[0]; ILateralCacheAttributes cattr = new LateralCacheAttributes(); cattr.setCacheName( "testCache1" ); LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<String, String>( null, noWaits, cattr ); LateralCache<String, String> cache = new LateralCache<String, String>( cattr ); LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<String, String>( cache ); // DO WORK facade.removeNoWait( noWait ); // VERIFY assertFalse( "Should not be in the list.", facade.containsNoWait( noWait ) ); } }
/** * Verify that we can remove an item. */ public void testAddThenRemoveNoWait_NotInList() { // SETUP @SuppressWarnings("unchecked") LateralCacheNoWait<String, String>[] noWaits = new LateralCacheNoWait[0]; ILateralCacheAttributes cattr = new LateralCacheAttributes(); cattr.setCacheName( "testCache1" ); LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<String, String>( null, noWaits, cattr ); LateralCache<String, String> cache = new LateralCache<String, String>( cattr ); LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<String, String>( cache ); // DO WORK facade.removeNoWait( noWait ); // VERIFY assertFalse( "Should not be in the list.", facade.containsNoWait( noWait ) ); } }
/** * Verify that we can remove an item. */ public void testAdd_InList() { // SETUP @SuppressWarnings("unchecked") LateralCacheNoWait<String, String>[] noWaits = new LateralCacheNoWait[0]; ILateralCacheAttributes cattr = new LateralCacheAttributes(); cattr.setCacheName( "testCache1" ); LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<String, String>( null, noWaits, cattr ); LateralCache<String, String> cache = new LateralCache<String, String>( cattr ); LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<String, String>( cache ); // DO WORK facade.addNoWait( noWait ); facade.addNoWait( noWait ); // VERIFY assertTrue( "Should be in the list.", facade.containsNoWait( noWait ) ); assertEquals( "Should only have 1", 1, facade.noWaits.length ); }
/** * Verify that we can remove an item. */ public void testAdd_InList() { // SETUP @SuppressWarnings("unchecked") LateralCacheNoWait<String, String>[] noWaits = new LateralCacheNoWait[0]; ILateralCacheAttributes cattr = new LateralCacheAttributes(); cattr.setCacheName( "testCache1" ); LateralCacheNoWaitFacade<String, String> facade = new LateralCacheNoWaitFacade<String, String>( null, noWaits, cattr ); LateralCache<String, String> cache = new LateralCache<String, String>( cattr ); LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<String, String>( cache ); // DO WORK facade.addNoWait( noWait ); facade.addNoWait( noWait ); // VERIFY assertTrue( "Should be in the list.", facade.containsNoWait( noWait ) ); assertEquals( "Should only have 1", 1, facade.noWaits.length ); }