Forum Stats

  • 3,815,836 Users
  • 2,259,099 Discussions
  • 7,893,275 Comments

Discussions

How to use EventInterceptor with LifecycleEvent?

962259
962259 Member Posts: 55
edited Nov 22, 2017 12:03PM in Coherence Support

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> {

@Override

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

Answers

  • Tmiddlet-Oracle
    Tmiddlet-Oracle Member Posts: 125
    edited Jul 12, 2017 12:00AM

    Are you sure the correct cache config has been loaded?

    Check the log file for this:

    Loaded cache configuration from

    Thanks

    Tim

  • Tmiddlet-Oracle
    Tmiddlet-Oracle Member Posts: 125
    edited Jul 12, 2017 1:36AM

    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

  • 962259
    962259 Member Posts: 55
    edited Jul 12, 2017 10:02AM

    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.

  • 962259
    962259 Member Posts: 55
    edited Jul 12, 2017 10:49AM

    Created SR 3-15321003091

  • pfurtado-Oracle
    pfurtado-Oracle Member Posts: 7 Employee
    edited Jul 13, 2017 6:32AM

    How about registering the interceptor at service level, within distributed-scheme?

    Does it make any difference?

    PF

  • 962259
    962259 Member Posts: 55
    edited Jul 13, 2017 11:47AM

    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.

  • 962259
    962259 Member Posts: 55
    edited Jul 13, 2017 4:51PM

    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

  • 962259
    962259 Member Posts: 55
    edited Jul 28, 2017 10:18AM

    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...

  • 962259
    962259 Member Posts: 55
    edited Nov 22, 2017 12:03PM Answer ✓

    It is a bug in coherence common, fixed in 13.0.0

This discussion has been closed.