2

hazelcast configuration for the map is

    <map name="test">
      <max-idle-seconds>120</max-idle-seconds>
    <entry-listeners>
        <entry-listener include-value="true" local="false">com.test.listener.SessionListener</entry-listener>
    </entry-listeners>
   </map>

I have a listener configured for the evict action. Listener is not able to catch the evict action consistently . Hazelcast Version : 3.6.5

Listener Class Implemetation:

public class SessionListener implements EntryListener<String, Object> {
@Override
public void entryEvicted(EntryEvent<String, Object> evictData) {

    try {
        Session sessionObjValue = (Session) evictData.getOldValue();
        String sessionId = sessionObjValue.getSessionId();
        String userName = sessionObjValue.getUsername();

        JSONObject inputJSON = new JSONObject();
        inputJSON.put(Constants.SESSIONID, sessionId);
        inputJSON.put(Constants.USER_NAME, userName);
        //Operations to be performed based on the JSON Value


    } catch (Exception exception) {
        LOGGER.logDebug(Constants.ERROR, methodName, exception.toString());
    }

}
Vik Gamov
  • 5,446
  • 1
  • 26
  • 46
Vishnu Prabhakar
  • 310
  • 4
  • 17

1 Answers1

0

Below are the recommendations:

  1. Include Eviction policy configurations in your map config. Right now eviction is happening only based on max-idle-seconds.
  2. Implement all the methods from EntryListener interface which inturn extends other interfaces.
  3. Implement EntryExpiredListener listener also, to catch the expiry events explicitly though evict event also will be called during expiry.

Sample code:

    public class MapEntryListernerTest implements EntryListener, EntryExpiredListener {


    @Override
    public void entryAdded(EntryEvent event) {

    }

    @Override
    public void entryEvicted(EntryEvent event) {

    }

    @Override
    public void entryRemoved(EntryEvent event) {

    }

    @Override
    public void entryUpdated(EntryEvent event) {

    }

    @Override
    public void mapCleared(MapEvent event) {

    }

    @Override
    public void mapEvicted(MapEvent event) {

    }

    @Override
    public void entryExpired(EntryEvent event) {

    }
    }
A.K.Desai
  • 1,274
  • 1
  • 10
  • 16
  • Thanks.Issue : Listener is not working consistently.Most of the time, evict listener is not able to catch the event or evict of the particular key in the map after idle timeout is not working – Vishnu Prabhakar Oct 18 '16 at 10:17
  • Can you write a test class to replicate the issue? – A.K.Desai Oct 18 '16 at 10:21
  • 2
    After many trail and error,Found that,value is getting evicted:but evict listener is not able to catch that event after predefined timeout.Listener is able to catch that event after some time. – Vishnu Prabhakar Oct 31 '16 at 12:18