简体   繁体   English

HazelCast max-idle-seconds:退出侦听器不起作用

[英]HazelCast max-idle-seconds :evict listener is not working

hazelcast configuration for the map is 该地图的hazelcast配置为

    <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 Hazelcast版本: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());
    }

}

Below are the recommendations: 以下是建议:

  1. Include Eviction policy configurations in your map config. 在地图配置中包括驱逐策略配置。 Right now eviction is happening only based on max-idle-seconds. 目前,驱逐仅基于max-idle-seconds进行。
  2. Implement all the methods from EntryListener interface which inturn extends other interfaces. 从EntryListener接口实现所有方法,从而扩展其他接口。
  3. Implement EntryExpiredListener listener also, to catch the expiry events explicitly though evict event also will be called during expiry. 还实现EntryExpiredListener侦听器,以显式捕获到期事件,尽管在到期期间也将调用evict事件。

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

    }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM