Search in sources :

Example 1 with IPortletExecutionWorker

use of org.apereo.portal.portlet.rendering.worker.IPortletExecutionWorker in project uPortal by Jasig.

the class PortletExecutionManager method doPortletEvents.

public void doPortletEvents(PortletEventQueue eventQueue, HttpServletRequest request, HttpServletResponse response) {
    if (eventQueue.getUnresolvedEvents().isEmpty()) {
        return;
    }
    final Map<IPortletWindowId, IPortletExecutionWorker<Long>> eventWorkers = new LinkedHashMap<IPortletWindowId, IPortletExecutionWorker<Long>>();
    //TODO what to do if we hit the max iterations?
    int iteration = 0;
    for (; iteration < this.maxEventIterations; iteration++) {
        //Make sure all queued events have been resolved
        this.eventCoordinationService.resolvePortletEvents(request, eventQueue);
        //Create and submit an event worker for each window with a queued event
        for (final IPortletWindowId eventWindowId : eventQueue) {
            if (eventWorkers.containsKey(eventWindowId)) {
                /*
                     * PLT.15.2.5 says that event processing per window must be serialized, if there
                     * is already a working in the map for the window ID skip it for now. we'll get back to it eventually
                     */
                continue;
            }
            final QueuedEvent queuedEvent = eventQueue.pollEvent(eventWindowId);
            if (queuedEvent != null) {
                final Event event = queuedEvent.getEvent();
                final IPortletExecutionWorker<Long> portletEventExecutionWorker = this.portletWorkerFactory.createEventWorker(request, response, eventWindowId, event);
                eventWorkers.put(eventWindowId, portletEventExecutionWorker);
                portletEventExecutionWorker.submit();
            }
        }
        //If no event workers exist we're done with event processing!
        if (eventWorkers.isEmpty()) {
            return;
        }
        //See if any of the events have completed
        int completedEventWorkers = 0;
        final Set<Entry<IPortletWindowId, IPortletExecutionWorker<Long>>> entrySet = eventWorkers.entrySet();
        for (final Iterator<Entry<IPortletWindowId, IPortletExecutionWorker<Long>>> eventWorkerEntryItr = entrySet.iterator(); eventWorkerEntryItr.hasNext(); ) {
            final Entry<IPortletWindowId, IPortletExecutionWorker<Long>> eventWorkerEntry = eventWorkerEntryItr.next();
            final IPortletExecutionWorker<Long> eventWorker = eventWorkerEntry.getValue();
            if (eventWorker.isComplete()) {
                final IPortletWindowId portletWindowId = eventWorkerEntry.getKey();
                //TODO return number of new queued events, use to break the loop earlier
                waitForEventWorker(request, eventQueue, eventWorker, portletWindowId);
                eventWorkerEntryItr.remove();
                completedEventWorkers++;
            }
        }
        /*
             * If no event workers have completed without waiting wait for the first one and then loop again
             * Not waiting for all events since each event may spawn more events and we want to start them
             * processing as soon as possible
             */
        if (completedEventWorkers == 0) {
            final Iterator<Entry<IPortletWindowId, IPortletExecutionWorker<Long>>> eventWorkerEntryItr = entrySet.iterator();
            final Entry<IPortletWindowId, IPortletExecutionWorker<Long>> eventWorkerEntry = eventWorkerEntryItr.next();
            eventWorkerEntryItr.remove();
            final IPortletWindowId portletWindowId = eventWorkerEntry.getKey();
            final IPortletExecutionWorker<Long> eventWorker = eventWorkerEntry.getValue();
            waitForEventWorker(request, eventQueue, eventWorker, portletWindowId);
        }
    }
    if (iteration == this.maxEventIterations) {
        this.logger.error("The Event dispatching iteration maximum of " + this.maxEventIterations + " was hit, consider either raising this limit or reviewing the portlets that use events to reduce the number of events spawned");
    }
}
Also used : IPortletExecutionWorker(org.apereo.portal.portlet.rendering.worker.IPortletExecutionWorker) LinkedHashMap(java.util.LinkedHashMap) Entry(java.util.Map.Entry) Event(javax.portlet.Event) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId)

Example 2 with IPortletExecutionWorker

use of org.apereo.portal.portlet.rendering.worker.IPortletExecutionWorker in project uPortal by Jasig.

the class JacksonPortalEventTest method verifyOutputFormat.

@Test
public void verifyOutputFormat() throws Exception {
    final String sessionId = "1234567890123_system_AAAAAAAAAAA";
    final PortalEvent.PortalEventBuilder eventBuilder = new PortalEvent.PortalEventBuilder(this, "example.com", sessionId, SystemPerson.INSTANCE, null);
    final PortletExecutionEvent.PortletExecutionEventBuilder portletExecutionEventBuilder = new PortletExecutionEvent.PortletExecutionEventBuilder(eventBuilder, new MockPortletWindowId("pw1"), "fname", 12345, Collections.EMPTY_MAP, WindowState.NORMAL, PortletMode.VIEW);
    PortalEvent event;
    //TODO: Will uncomment once we add in attribute swapper event processing.
    /*event = new AttributeSwapEvent(eventBuilder, Collections.EMPTY_MAP);
        assertEventJsonEquals("{\"@c\":\".AttributeSwapEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"swappedAttributes\":{}}", event);

        event = new AttributeSwapResetEvent(eventBuilder);
        assertEventJsonEquals("{\"@c\":\".AttributeSwapResetEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\"}", event);

        event = new IdentitySwapStartEvent(eventBuilder, "originalUserName", "originalEventSessionId");
        assertEventJsonEquals("{\"@c\":\".IdentitySwapStartEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"originalUserName\":\"originalUserName\",\"originalEventSessionId\":\"originalEventSessionId\"}", event);

        event = new IdentitySwapStopEvent(eventBuilder, "targetUserName");
        assertEventJsonEquals("{\"@c\":\".IdentitySwapStopEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"targetUserName\":\"targetUserName\"}", event);
        */
    event = new FolderAddedToLayoutPortalEvent(eventBuilder, SystemPerson.INSTANCE, 1, "newFolderId");
    assertEventJsonEquals("{\"@c\":\".FolderAddedToLayoutPortalEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"layoutId\":1,\"layoutOwner\":\"system\",\"newFolderId\":\"newFolderId\"}", event);
    event = new FolderDeletedFromLayoutPortalEvent(eventBuilder, SystemPerson.INSTANCE, 1, "oldParentFolderId", "deletedFolderId", "deletedFolderName");
    assertEventJsonEquals("{\"@c\":\".FolderDeletedFromLayoutPortalEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"layoutId\":1,\"layoutOwner\":\"system\",\"oldParentFolderId\":\"oldParentFolderId\",\"deletedFolderId\":\"deletedFolderId\",\"deletedFolderName\":\"deletedFolderName\"}", event);
    event = new FolderMovedInLayoutPortalEvent(eventBuilder, SystemPerson.INSTANCE, 1, "oldParentFolderId", "movedFolderId");
    assertEventJsonEquals("{\"@c\":\".FolderMovedInLayoutPortalEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"layoutId\":1,\"layoutOwner\":\"system\",\"oldParentFolderId\":\"oldParentFolderId\",\"movedFolderId\":\"movedFolderId\"}", event);
    event = new PortletAddedToLayoutPortalEvent(eventBuilder, SystemPerson.INSTANCE, 1, "parentFolderId", "fname");
    assertEventJsonEquals("{\"@c\":\".PortletAddedToLayoutPortalEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"layoutId\":1,\"layoutOwner\":\"system\",\"fname\":\"fname\",\"parentFolderId\":\"parentFolderId\"}", event);
    event = new PortletDeletedFromLayoutPortalEvent(eventBuilder, SystemPerson.INSTANCE, 1, "oldParentFolderId", "fname");
    assertEventJsonEquals("{\"@c\":\".PortletDeletedFromLayoutPortalEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"layoutId\":1,\"layoutOwner\":\"system\",\"fname\":\"fname\",\"oldParentFolderId\":\"oldParentFolderId\"}", event);
    event = new PortletMovedInLayoutPortalEvent(eventBuilder, SystemPerson.INSTANCE, 1, "oldParentFolderId", "newParentFolderId", "fname");
    assertEventJsonEquals("{\"@c\":\".PortletMovedInLayoutPortalEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"layoutId\":1,\"layoutOwner\":\"system\",\"fname\":\"fname\",\"oldParentFolderId\":\"oldParentFolderId\",\"newParentFolderId\":\"newParentFolderId\"}", event);
    event = new LoginEvent(eventBuilder, Collections.EMPTY_SET, Collections.EMPTY_MAP);
    assertEventJsonEquals("{\"@c\":\".LoginEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"groups\":[],\"attributes\":{}}", event);
    event = new LogoutEvent(eventBuilder);
    assertEventJsonEquals("{\"@c\":\".LogoutEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\"}", event);
    event = new PortalRenderEvent(eventBuilder, "requestPathInfo", 12345, UrlState.NORMAL, UrlType.RENDER, Collections.EMPTY_MAP, "targetedLayoutNodeId");
    assertEventJsonEquals("{\"@c\":\".PortalRenderEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"requestPathInfo\":\"requestPathInfo\",\"urlState\":\"NORMAL\",\"urlType\":\"RENDER\",\"parameters\":{},\"targetedLayoutNodeId\":\"targetedLayoutNodeId\",\"executionTimeNano\":12345}", event);
    event = new PortletActionExecutionEvent(portletExecutionEventBuilder);
    assertEventJsonEquals("{\"@c\":\".PortletActionExecutionEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"fname\":\"fname\",\"windowState\":\"normal\",\"portletMode\":\"view\",\"executionTimeNano\":12345,\"parameters\":{}}", event);
    event = new PortletEventExecutionEvent(portletExecutionEventBuilder, new QName("http://example.com/uri", "EventName"));
    assertEventJsonEquals("{\"@c\":\".PortletEventExecutionEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"fname\":\"fname\",\"windowState\":\"normal\",\"portletMode\":\"view\",\"executionTimeNano\":12345,\"parameters\":{},\"eventName\":\"{http://example.com/uri}EventName\"}", event);
    event = new PortletRenderExecutionEvent(portletExecutionEventBuilder, true, false);
    assertEventJsonEquals("{\"@c\":\".PortletRenderExecutionEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"fname\":\"fname\",\"windowState\":\"normal\",\"portletMode\":\"view\",\"executionTimeNano\":12345,\"parameters\":{},\"targeted\":true,\"usedPortalCache\":false}", event);
    event = new PortletRenderHeaderExecutionEvent(portletExecutionEventBuilder, true, false);
    assertEventJsonEquals("{\"@c\":\".PortletRenderHeaderExecutionEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"fname\":\"fname\",\"windowState\":\"normal\",\"portletMode\":\"view\",\"executionTimeNano\":12345,\"parameters\":{},\"targeted\":true,\"cached\":false}", event);
    event = new PortletResourceExecutionEvent(portletExecutionEventBuilder, "resourceId", false, false);
    assertEventJsonEquals("{\"@c\":\".PortletResourceExecutionEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"fname\":\"fname\",\"windowState\":\"normal\",\"portletMode\":\"view\",\"executionTimeNano\":12345,\"parameters\":{},\"resourceId\":\"resourceId\",\"usedBrowserCache\":false,\"usedPortalCache\":false}", event);
    final IPortletExecutionWorker hungWorker = mock(IPortletExecutionWorker.class);
    when(hungWorker.getPortletFname()).thenReturn("fname");
    event = new PortletHungCompleteEvent(eventBuilder, hungWorker);
    assertEventJsonEquals("{\"@c\":\".PortletHungCompleteEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"fname\":\"fname\"}", event);
    event = new PortletHungEvent(eventBuilder, hungWorker);
    assertEventJsonEquals("{\"@c\":\".PortletHungEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"fname\":\"fname\"}", event);
    final ITenant tenant = new ITenant() {

        private static final long serialVersionUID = 1L;

        @Override
        public int compareTo(ITenant o) {
            return 0;
        }

        @Override
        public long getId() {
            return 1L;
        }

        @Override
        public String getName() {
            return "Mordor";
        }

        @Override
        public void setName(String name) {
        }

        @Override
        public String getFname() {
            return "mordor";
        }

        @Override
        public void setFname(String fname) {
        }

        @Override
        public String getAttribute(String name) {
            return null;
        }

        @Override
        public void setAttribute(String name, String value) {
        }

        @Override
        public Map<String, String> getAttributesMap() {
            return Collections.emptyMap();
        }
    };
    event = new TenantCreatedTenantEvent(eventBuilder, tenant);
    assertEventJsonEquals("{\"@c\":\".TenantCreatedTenantEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\"}", event);
    event = new TenantUpdatedTenantEvent(eventBuilder, tenant);
    assertEventJsonEquals("{\"@c\":\".TenantUpdatedTenantEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\"}", event);
    event = new TenantRemovedTenantEvent(eventBuilder, tenant);
    assertEventJsonEquals("{\"@c\":\".TenantRemovedTenantEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\"}", event);
}
Also used : ITenant(org.apereo.portal.tenants.ITenant) IPortletExecutionWorker(org.apereo.portal.portlet.rendering.worker.IPortletExecutionWorker) QName(javax.xml.namespace.QName) MockPortletWindowId(org.apereo.portal.mock.portlet.om.MockPortletWindowId) Test(org.junit.Test)

Aggregations

IPortletExecutionWorker (org.apereo.portal.portlet.rendering.worker.IPortletExecutionWorker)2 LinkedHashMap (java.util.LinkedHashMap)1 Entry (java.util.Map.Entry)1 Event (javax.portlet.Event)1 QName (javax.xml.namespace.QName)1 MockPortletWindowId (org.apereo.portal.mock.portlet.om.MockPortletWindowId)1 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)1 ITenant (org.apereo.portal.tenants.ITenant)1 Test (org.junit.Test)1