• Bug
  • Status: Open
  • 2 Major
  • Resolution:
  • ehcache-core
  • Reporter: alexsnaps
  • May 30, 2011
  • 0
  • Watchers: 1
  • May 28, 2013



Maybe introducing a RegisteredEventListeners.getCacheEventListeners(NotificationScope): Set would make sense here...

From the dev ML: Hi everyone,

I’m currently working on using EhCache 2.4.2, and setting up CacheEventListeners to propagate events to different VMs. I’m also using a single cache configuration, which is cloned to create an instance of each of my domain objects.

I noticed that when cloning Cache objects, the CacheEventListeners get cloned, but with the default “ALL” NotificationScope. Here is a simple JUnit test that exhibit this behavior, added to the CacheTest suite: /** * Tests that when cloning a cache, the notification scope for any registered listener is also * applied to the clone. */ @Test public void testCloningCacheKeepsNotificationScope() throws CloneNotSupportedException { // Create the source cache, register a listener Cache cache = new Cache(“testCloningCacheKeepsNotificationScope”, 10, false, false, 100, 200); cache.getCacheEventNotificationService().registerListener(new RemoveCountingListener(), NotificationScope.LOCAL);

// Clone the cache, access the cloned listener Cache cloned = cache.clone(); cloned.setName(“testCloningCacheKeepsNotificationScopeClone”); assertEquals(“The cloned cache should have only one registered listener”, 1, cloned.getCacheEventNotificationService().getCacheEventListeners().size()); RemoveCountingListener clonedListener = (RemoveCountingListener) cloned.getCacheEventNotificationService().getCacheEventListeners().iterator().next();

manager.addCache(cache); manager.addCache(cloned);

// Put an element Element element = new Element(“foo”, “bar”, 1L); cloned.put(element);

// Remove an element - only listeners with notification scope “REMOTE” should be notified cloned.remove(“foo”, true); assertEquals(“The cloned listener was notified of the event even though its scope should be LOCAL”, 0, clonedListener.count); }

The final test fails because the clonedListener instance has been registered with the ALL scope. Did I miss something or is there an issue ?

In the later case, I don’t know if it’s the proper issue reporting process, but I’m attaching a patch I’m using to get around it for now.




Alexander Snaps 2011-05-30

Here’s my quick take on the issue, adding RegisteredEventListeners.getCacheEventListeners(NotificationScope notificationScope): Set Probably needs a finer review though...

Fiona OShea 2011-05-31

Greg, what do you think?

Fiona OShea 2011-05-31

Assigned to Greg for review. We also need a signed contributor agreement from Julien to accept this patch. Do we have his contact information?


Alexander Snaps 2011-06-01

I personally don’t like his patch so much though, I tend to prefer my approach… obviously! ;-) I’ll let Greg decide what the best approach would be. I created this jira based on him mailing the ML, so his contact is there.

Alexander Snaps 2011-06-01

  1. EHC-863.patch is my take on it
  2. scope.diff is his initial patch

He posted two additional patches based on my feedback on the ML as well.

Julien MASSENET 2011-06-06

Attached are two possible updated pacthes:

In addition, I just sent in the completed contributor agreement.

Fiona OShea 2011-12-08

From TimM email 6/6/11 Hi Julien,

Tim McIntyre here, counsel for Terracotta. Welcome to the Terracotta open source project!

To confirm, are the contributions going to be coming from you, or from Patrick Donovan, who signed the form that was sent earlier? If they’re coming from you, we’ll also need a signed Contributor Agreement from you. If you have any questions let me know.