1 package com.atlassian.cache.ehcache.replication.rmi;
2
3 import java.io.Serializable;
4
5 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory;
7
8 import net.sf.ehcache.CacheException;
9 import net.sf.ehcache.Ehcache;
10 import net.sf.ehcache.Element;
11
12
13
14
15
16
17 public class RMISynchronousCacheReplicator extends net.sf.ehcache.distribution.RMISynchronousCacheReplicator
18 {
19
20 private static final Logger LOG =
21 LoggerFactory.getLogger(net.sf.ehcache.distribution.RMISynchronousCacheReplicator.class);
22
23
24
25
26
27
28
29
30
31
32 public RMISynchronousCacheReplicator(final boolean replicatePuts, final boolean replicatePutsViaCopy,
33 final boolean replicateUpdates, final boolean replicateUpdatesViaCopy, final boolean replicateRemovals)
34 {
35 super(replicatePuts, replicatePutsViaCopy, replicateUpdates, replicateUpdatesViaCopy, replicateRemovals);
36 }
37
38
39 @Override
40 public void notifyElementPut(final Ehcache cache, final Element element) throws CacheException {
41 if (notAlive() || !replicatePuts)
42 {
43 return;
44 }
45
46 if (replicatePutsViaCopy)
47 {
48 replicateViaCopy(cache, element);
49 }
50 else
51 {
52 replicateViaKeyInvalidation(cache, element);
53 }
54 }
55
56 private void replicateViaCopy(final Ehcache cache, final Element element)
57 {
58 if (element.isSerializable())
59 {
60 replicatePutNotification(cache, element);
61 return;
62 }
63 if (!element.isKeySerializable())
64 {
65 logUnserializableKey(element);
66 }
67 if (LOG.isWarnEnabled() && !(element.getObjectValue() instanceof Serializable))
68 {
69 LOG.error("Value class {} is not Serializable => cannot be replicated",
70 element.getObjectValue().getClass().getName());
71 }
72 }
73
74 private void replicateViaKeyInvalidation(final Ehcache cache, final Element element)
75 {
76 if (element.isKeySerializable())
77 {
78 replicateRemovalNotification(cache, (Serializable) element.getObjectKey());
79 return;
80 }
81 logUnserializableKey(element);
82 }
83
84 private void logUnserializableKey(final Element element)
85 {
86 if (LOG.isWarnEnabled())
87 {
88 LOG.error("Key class {} is not Serializable => cannot be replicated",
89 element.getObjectKey().getClass().getName());
90 }
91 }
92 }