List of usage examples for org.apache.commons.collections.map LinkedMap nextKey
public Object nextKey(Object key)
From source file:de.innovationgate.wgpublisher.webtml.EventScript.java
/** * Searches the fired events queue for events of a name, beginning at a specified index * @param name The event name to search for * @param index The start index in the queue * @return a list of found events/* w w w. java 2 s . c o m*/ * @throws WGAPIException */ private List<PortletEvent> findEventsOfName(String name, Long index) throws WGAPIException { List<PortletEvent> foundEvents = new ArrayList<PortletEvent>(); HttpSession session = getPageContext().getSession(); LinkedMap events = TMLPortlet.getFiredEventsQueue(session); if (events.size() == 0) { return foundEvents; } // Find the start index. This is either the index after the last processed index, or - if the last processed // index is not available in the queue - the first index in the queue. if (events.containsKey(index)) { index = (Long) events.nextKey(index); } else { index = (Long) events.firstKey(); } synchronized (events) { PortletEvent event; while (index != null) { event = (PortletEvent) events.get(index); String targetPortletKey = event.getTargetPortletKey(); if (targetPortletKey == null || targetPortletKey.equals(getTMLContext().getportlet().getportletkey())) { if (event.getName().equalsIgnoreCase(name)) { foundEvents.add(event); } } index = (Long) events.nextKey(index); } } return foundEvents; }
From source file:de.innovationgate.wgpublisher.webtml.portlet.TMLPortlet.java
public void prepareEventProcessing(Base tag) throws WGAPIException { TMLPortletState sessionContext = getState(); LinkedMap list = TMLPortlet.getFiredEventsQueue(tag.getPageContext().getSession()); // Look if the event queue proceeded since the last processed event if (list.size() > 0) { PortletEvent lastEvent = (PortletEvent) list.get(list.lastKey()); if (lastEvent != null) { if (lastEvent.getIndex() > sessionContext.getLastProcessedEventIndex()) { // Find the start index for processing new events Long startIndex;/*from w w w .j a v a2 s .c o m*/ Long lastProcessedIndex = new Long(sessionContext.getLastProcessedEventIndex()); if (list.containsKey(lastProcessedIndex)) { startIndex = (Long) list.nextKey(lastProcessedIndex); } else { startIndex = (Long) list.firstKey(); } // Set start index as WebTML option tag.getStatus().setOption(Base.OPTION_PORTLET_EVENT_STARTINDEX, new Long(sessionContext.getLastProcessedEventIndex()), TMLOption.SCOPE_GLOBAL); // Update last processed event index to be the newest event's index sessionContext.setLastProcessedEventIndex(lastEvent.getIndex()); } } } }