2
* Copyright 2003-2010 Terracotta, Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
package net.sf.ehcache.event;
19
import java.util.concurrent.ConcurrentHashMap;
20
import java.util.concurrent.ConcurrentMap;
22
import net.sf.ehcache.CacheException;
23
import net.sf.ehcache.Ehcache;
24
import net.sf.ehcache.Element;
25
import net.sf.ehcache.Status;
26
import net.sf.ehcache.distribution.CacheReplicator;
29
* Creates a wrapper for sending out cache events through the Terracotta cluster
32
* @version $Id: TerracottaCacheEventReplication.java 2249 2010-04-15 07:12:57Z gbevin $
34
public class TerracottaCacheEventReplication implements CacheReplicator {
35
private Status status = Status.STATUS_ALIVE;
37
private final ConcurrentMap<Ehcache, CacheEventListener> replicators = new ConcurrentHashMap<Ehcache, CacheEventListener>();
42
public void notifyElementRemoved(Ehcache cache, Element element) throws CacheException {
43
createCacheEventReplicator(cache).notifyElementRemoved(cache, element);
49
public void notifyElementPut(Ehcache cache, Element element) throws CacheException {
50
createCacheEventReplicator(cache).notifyElementPut(cache, element);
56
public void notifyElementUpdated(Ehcache cache, Element element) throws CacheException {
57
createCacheEventReplicator(cache).notifyElementUpdated(cache, element);
63
public void notifyElementExpired(Ehcache cache, Element element) {
64
createCacheEventReplicator(cache).notifyElementExpired(cache, element);
70
public void notifyElementEvicted(Ehcache cache, Element element) {
71
createCacheEventReplicator(cache).notifyElementEvicted(cache, element);
77
public void notifyRemoveAll(Ehcache cache) {
78
createCacheEventReplicator(cache).notifyRemoveAll(cache);
81
private CacheEventListener createCacheEventReplicator(Ehcache cache) {
82
// the race is not a problem here, since the event replicator will only be created once in the clustered instance factory
83
// this replicator map is simply a locally cached version, several puts for the same cache will result in the same value being put
84
CacheEventListener replicator = replicators.get(cache);
85
if (null == replicator) {
86
replicator = cache.getCacheManager().createTerracottaEventReplicator(cache);
87
replicators.put(cache, replicator);
97
public TerracottaCacheEventReplication clone() throws CloneNotSupportedException {
98
return (TerracottaCacheEventReplication) super.clone();
104
public boolean isReplicateUpdatesViaCopy() {
111
public final boolean notAlive() {
118
public final boolean alive() {
119
return status != null && (status.equals(Status.STATUS_ALIVE));
125
public void dispose() {
126
status = Status.STATUS_SHUTDOWN;
b'\\ No newline at end of file'