Example usage for org.apache.commons.collections.map LinkedMap firstKey

List of usage examples for org.apache.commons.collections.map LinkedMap firstKey

Introduction

In this page you can find the example usage for org.apache.commons.collections.map LinkedMap firstKey.

Prototype

public Object firstKey() 

Source Link

Document

Gets the first key in the map, which is the most recently inserted.

Usage

From source file:de.innovationgate.wgpublisher.webtml.portlet.TMLPortlet.java

protected static void addEventToQueue(PortletEvent event, HttpSession session) {

    LinkedMap events = getFiredEventsQueue(session);

    synchronized (events) {
        event.retrieveIndex();//  w w w .  ja  v  a  2s  .  c  o  m
        events.put(new Long(event.getIndex()), event);
        while (events.size() > EVENTQUEUE_MAX_SIZE) {
            events.remove(events.firstKey());
        }
    }

}

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 ww . ja v a 2s.c  om
 * @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   ww  w . j  a  v  a 2s .  co 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());
            }
        }
    }
}