Discussions
Categories
- 17.9K All Categories
- 3.4K Industry Applications
- 3.3K Intelligent Advisor
- 63 Insurance
- 535.7K On-Premises Infrastructure
- 138.1K Analytics Software
- 38.6K Application Development Software
- 5.6K Cloud Platform
- 109.3K Database Software
- 17.5K Enterprise Manager
- 8.8K Hardware
- 71K Infrastructure Software
- 105.2K Integration
- 41.5K Security Software
How to use EventInterceptor with LifecycleEvent?

I want to create all cache indexes when our standalone Coherence cluster starts.
So I wrote a simple event listener listening on LifecycleEvent based on 12.2.1.2.0 documentation: Using Live Events
public class LifeCycleEventInterceptor implements EventInterceptor<LifecycleEvent> {
public void onEvent(LifecycleEvent event) {
if(event.getType() == LifecycleEvent.Type.ACTIVATED) {
// set all indexes here
}
}
}
And added the interceptor decalaration in our cache config file:
<?xml version='1.0'?>
<cache-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.oracle.com/coherence/coherence-cache-config"
xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-cache-config
coherence-cache-config.xsd">
<interceptors>
<interceptor>
<instance>
<class-name>my.LifeCycleEventInterceptor</class-name>
</instance>
</interceptor>
</interceptors>
...
But the interceptor is never triggered. Any ideas why?
Best Answer
-
It is a bug in coherence common, fixed in 13.0.0
Answers
-
Are you sure the correct cache config has been loaded?
Check the log file for this:
Loaded cache configuration from
Thanks
Tim
-
I have tested the same and should work fine.
if you put System.out in your onEvent(0 method, do you see output?
If you see the output, is your addIndex() , not working?
Thanks
Tim
-
Hi Tim,
I am a bit puzzled, straightforward code and no index created, no trace in standard out or log4j. Tested with multiple Coherence versions, not related since none worked.
Obviously I am missing something but can't find it.
I will create an SR so I can upload my test code and get Coherence support for it.
Tks.
-
Created SR 3-15321003091
-
How about registering the interceptor at service level, within distributed-scheme?
Does it make any difference?
PF
-
Will try, and actually makes more sense at service level since it gives more specific context to indexes being created - only for caches associated with this distributed service.
-
Listener on distributed service works fine. Indexes are added, I can see traces/log msgs.
I do get the following message:
WARN 2017-07-13 16:40:10,481 [com.tangosol.coherence.component.util.logOutput.Log4j] - 2017-07-13 16:40:10.481/39.662 Oracle Coherence GE 12.2.1.2.0 <Warning> (thread=DistributedCache:DistributedService-Spike:EventDispatcher, member=3): Application code running on "DistributedService-Spike" service thread(s) should not call ensureCache as this may result in deadlock. The most common case is a CacheFactory call from a custom CacheStore implementation.
Assuming this is normal since in the listener I add indexes to cache part of service being initialized...not sure how to avoid this warning.
Still puzzles me why global listener on LifecycleEvent does not work. Will follow-up SR.
Tks
-
After additional tests, the problem lies in the usage of coherence-common of Coherence incubator project (12.5.0) - include directive in cache config.
When the listener is declared in a config file that is included, it is not triggered. When it is declared in the root cache config file, it is.
I will try to find out why it does not work with the include directive of incubator...
-
It is a bug in coherence common, fixed in 13.0.0