/** * Default. */ public ZombieCacheServiceNonLocal() { queue = new BoundedQueue<ZombieEvent>( 0 ); }
/** * Gets the number of items on the queue. * <p> * @return size of the queue. */ public int getQueueSize() { return queue.size(); }
/** * Verify that the queue returns the number of elements and the it does not exceed the max. */ public void testSize() { // SETUP int maxSize = 10; BoundedQueue<String> queue = new BoundedQueue<String>( maxSize ); // DO WORK for ( int i = 0; i < maxSize * 2; i++ ) { queue.add( "adfadsf sad " + i ); } int result = queue.size(); // VERIFY assertEquals( "Result size not as expected", maxSize, result ); }
/** * Verify that the items come back in the order put in. */ public void testFIFOOrderedTake() { // SETUP int maxSize = 10; BoundedQueue<String> queue = new BoundedQueue<String>( maxSize ); // DO WORK for ( int i = 0; i < maxSize; i++ ) { queue.add( String.valueOf( i ) ); } // VERIFY for ( int i = 0; i < maxSize; i++ ) { String result = queue.take(); assertEquals( "Result not as expected", String.valueOf( i ) , result ); } } }
/** * Verify null returned for empty. */ public void testTakeLastEmpty() { // SETUP int maxSize = 10; BoundedQueue<Object> queue = new BoundedQueue<Object>( maxSize ); // DO WORK Object result = queue.take(); // VERIFY assertNull( "Result should be null", result ); }
/** * Adds a removeAll event to the queue if the maxSize is greater than 0; * <p> * @param cacheName - region name * @param key - item key * @param listenerId - identifies the caller. */ @Override public void remove( String cacheName, K key, long listenerId ) { if ( maxQueueSize > 0 ) { RemoveEvent<K> event = new RemoveEvent<K>( cacheName, key, listenerId ); queue.add( event ); } // Zombies have no inner life }
/** * Adds an update event to the queue if the maxSize is greater than 0; * <p> * @param item ICacheElement * @param listenerId - identifies the caller. */ @Override public void update( ICacheElement<K, V> item, long listenerId ) { if ( maxQueueSize > 0 ) { PutEvent<K, V> event = new PutEvent<K, V>( item, listenerId ); queue.add( event ); } // Zombies have no inner life }
/** * Adds a removeAll event to the queue if the maxSize is greater than 0; * <p> * @param cacheName - name of the region * @param listenerId - identifies the caller. */ @Override public void removeAll( String cacheName, long listenerId ) { if ( maxQueueSize > 0 ) { RemoveAllEvent event = new RemoveAllEvent( cacheName, listenerId ); queue.add( event ); } // Zombies have no inner life }
/** * Sets the maximum number of items that will be allowed on the queue. * <p> * @param maxQueueSize */ public ZombieCacheServiceNonLocal( int maxQueueSize ) { this.maxQueueSize = maxQueueSize; queue = new BoundedQueue<ZombieEvent>( maxQueueSize ); }