public class NewOrderSessionListener implements EntryRemovedListener<String, SessionState> { @Override public void entryRemoved(EntryEvent<String, SessionState> event) { SessionState state = event.getOldValue(); Map<String, Data> map = state.getAttributes(); Data orderData = map.get("order"); if (orderData != null) { // Backup all data processed by order }
@Override public Object process(Map.Entry<String, SessionState> entry) { SessionState sessionState = entry.getValue(); if (sessionState == null) { sessionState = new SessionState(); } for (Map.Entry<String, Data> attribute : attributes.entrySet()) { String name = attribute.getKey(); Data value = attribute.getValue(); if (value == null) { sessionState.getAttributes().remove(name); } else { sessionState.getAttributes().put(name, value); } } entry.setValue(sessionState); return Boolean.TRUE; }
private IdentifiedDataSerializable getIdentifiedDataSerializable(int typeId) { IdentifiedDataSerializable dataSerializable; switch (typeId) { case SESSION_UPDATE: dataSerializable = new SessionUpdateEntryProcessor(); break; case SESSION_DELETE: dataSerializable = new DeleteSessionEntryProcessor(); break; case GET_ATTRIBUTE: dataSerializable = new GetAttributeEntryProcessor(); break; case GET_ATTRIBUTE_NAMES: dataSerializable = new GetAttributeNamesEntryProcessor(); break; case GET_SESSION_STATE: dataSerializable = new GetSessionStateEntryProcessor(); break; case SESSION_STATE: dataSerializable = new SessionState(); break; default: dataSerializable = null; } return dataSerializable; }
private IdentifiedDataSerializable getIdentifiedDataSerializable(int typeId) { IdentifiedDataSerializable dataSerializable; switch (typeId) { case SESSION_UPDATE: dataSerializable = new SessionUpdateEntryProcessor(); break; case SESSION_DELETE: dataSerializable = new DeleteSessionEntryProcessor(); break; case GET_ATTRIBUTE: dataSerializable = new GetAttributeEntryProcessor(); break; case GET_ATTRIBUTE_NAMES: dataSerializable = new GetAttributeNamesEntryProcessor(); break; case GET_SESSION_STATE: dataSerializable = new GetSessionStateEntryProcessor(); break; case SESSION_STATE: dataSerializable = new SessionState(); break; default: dataSerializable = null; } return dataSerializable; }
@Override public Data process(Map.Entry<String, SessionState> entry) { SessionState sessionState = entry.getValue(); if (sessionState == null) { return null; } entry.setValue(sessionState); return sessionState.getAttributes().get(attributeName); }
@Override public Object process(Map.Entry<String, SessionState> entry) { SessionState sessionState = entry.getValue(); if (sessionState == null) { sessionState = new SessionState(); } for (Map.Entry<String, Data> attribute : attributes.entrySet()) { String name = attribute.getKey(); Data value = attribute.getValue(); if (value == null) { sessionState.getAttributes().remove(name); } else { sessionState.getAttributes().put(name, value); } } entry.setValue(sessionState); return Boolean.TRUE; }
@Override public Data process(Map.Entry<String, SessionState> entry) { SessionState sessionState = entry.getValue(); if (sessionState == null) { return null; } entry.setValue(sessionState); return sessionState.getAttributes().get(attributeName); }
@Override public Object process(Map.Entry<String, SessionState> entry) { SessionState sessionState = entry.getValue(); if (sessionState == null) { return null; } entry.setValue(sessionState); return new HashSet<String>(sessionState.getAttributes().keySet()); }
@Override public Object process(Map.Entry<String, SessionState> entry) { SessionState sessionState = entry.getValue(); if (sessionState == null) { return null; } entry.setValue(sessionState); return new HashSet<String>(sessionState.getAttributes().keySet()); }
/** * Gets attributes. * * @param sessionId the session id * @return the attributes * @throws Exception the exception */ Set<Map.Entry<String, Object>> getAttributes(String sessionId) throws Exception { GetSessionStateEntryProcessor entryProcessor = new GetSessionStateEntryProcessor(); SessionState sessionState = (SessionState) executeOnKey(sessionId, entryProcessor); if (sessionState == null) { return null; } Map<String, Data> dataAttributes = sessionState.getAttributes(); Set<Map.Entry<String, Object>> attributes = new HashSet<Map.Entry<String, Object>>(dataAttributes.size()); for (Map.Entry<String, Data> entry : dataAttributes.entrySet()) { String key = entry.getKey(); Object value = sss.getSerializationService().toObject(entry.getValue()); attributes.add(new MapEntrySimple<String, Object>(key, value)); } return attributes; }
/** * Gets attributes. * * @param sessionId the session id * @return the attributes * @throws Exception the exception */ Set<Map.Entry<String, Object>> getAttributes(String sessionId) throws Exception { GetSessionStateEntryProcessor entryProcessor = new GetSessionStateEntryProcessor(); SessionState sessionState = (SessionState) executeOnKey(sessionId, entryProcessor); if (sessionState == null) { return null; } Map<String, Data> dataAttributes = sessionState.getAttributes(); Set<Map.Entry<String, Object>> attributes = new HashSet<Map.Entry<String, Object>>(dataAttributes.size()); for (Map.Entry<String, Data> entry : dataAttributes.entrySet()) { String key = entry.getKey(); Object value = sss.getSerializationService().toObject(entry.getValue()); attributes.add(new MapEntrySimple<String, Object>(key, value)); } return attributes; }
/** * <p>A mapping function to reduce a {@link com.hazelcast.map.journal.EventJournalMapEvent * EventJournalMapEvent} down to parts we are interested in. * </p> * <p>At the point this is called, for {@code UPDATE} events only, we can be sure that * old and new values exist so don't bother to test for them being null. * </p> * * @param eventJournalMapEvent A change record for an {@link com.hazelcast.core.IMap IMap} * @return A pair of baskets, one each from before and after */ private static Tuple2<Map<String, Integer>, Map<String, Integer>> beforeAndAfterBaskets(EventJournalMapEvent<String, SessionState> eventJournalMapEvent) { @SuppressWarnings("unchecked") Map<String, Integer> before = (Map<String, Integer>) SERIALIZATION_SERVICE.toObject(eventJournalMapEvent.getOldValue().getAttributes() .get(Constants.SESSION_ATTRIBUTE_BASKET)); @SuppressWarnings("unchecked") Map<String, Integer> after = (Map<String, Integer>) SERIALIZATION_SERVICE.toObject(eventJournalMapEvent.getNewValue().getAttributes() .get(Constants.SESSION_ATTRIBUTE_BASKET)); return Tuple2.tuple2(before, after); }