package org.apache.commons.jcs3.engine; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.IOException; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentLinkedQueue; import org.apache.commons.jcs3.engine.behavior.ICacheElement; import org.apache.commons.jcs3.engine.behavior.ICacheServiceNonLocal; import org.apache.commons.jcs3.log.Log; import org.apache.commons.jcs3.log.LogManager; import org.apache.commons.jcs3.utils.timing.ElapsedTimer; /** * Zombie adapter for the non local cache services. It just balks if there is no queue configured. *
* If a queue is configured, then events will be added to the queue. The idea is that when proper * operation is restored, the non local cache will walk the queue. The queue must be bounded so it * does not eat memory. *
* This originated in the remote cache.
*/
public class ZombieCacheServiceNonLocal
* @param maxQueueSize
*/
public ZombieCacheServiceNonLocal( final int maxQueueSize )
{
this();
this.maxQueueSize = maxQueueSize;
}
/**
* Gets the number of items on the queue.
*
* @return size of the queue.
*/
public int getQueueSize()
{
return queue.size();
}
private void addQueue(final ZombieEvent event)
{
queue.add(event);
if (queue.size() > maxQueueSize)
{
queue.poll(); // drop oldest entry
}
}
/**
* Adds an update event to the queue if the maxSize is greater than 0;
*
* @param item ICacheElement
* @param listenerId - identifies the caller.
*/
@Override
public void update( final ICacheElement
* @param cacheName - region name
* @param key - item key
* @param listenerId - identifies the caller.
*/
@Override
public void remove( final String cacheName, final K key, final long listenerId )
{
if ( maxQueueSize > 0 )
{
final RemoveEvent
* @param cacheName - name of the region
* @param listenerId - identifies the caller.
*/
@Override
public void removeAll( final String cacheName, final long listenerId )
{
if ( maxQueueSize > 0 )
{
final RemoveAllEvent event = new RemoveAllEvent( cacheName, listenerId );
addQueue( event );
}
// Zombies have no inner life
}
/**
* Does nothing. Gets are synchronous and cannot be added to a queue.
*
* @param cacheName - region name
* @param key - item key
* @param requesterId - identifies the caller.
* @return null
* @throws IOException
*/
@Override
public ICacheElement
* @param cacheName
* @param pattern
* @param requesterId
* @return empty map
* @throws IOException
*/
@Override
public Map
* @param cacheName - region name
* @return empty set
*/
@Override
public Set
* @param service
* @throws Exception
*/
public synchronized void propagateEvents( final ICacheServiceNonLocal