地图的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>
我为evict操作配置了一个监听器。 听众无法持续捕捉驱逐行动。 Hazelcast版本:3.6.5
监听器类实现:
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());
}
}
答案 0 :(得分:0)
以下是建议:
EntryExpiredListener
侦听器,以明确捕获到期事件,但也将在到期期间调用evict事件。示例代码:
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) {
}
}