//
if (response instanceof UpdateNavigationalStateResponse)
{
// Update portlet NS
UpdateNavigationalStateResponse updateResponse = (UpdateNavigationalStateResponse)response;
//
updateNavigationalState(context, portletRequest.getWindowId(), updateResponse, pageNavigationalState);
//
ResponseProperties update = updateResponse.getProperties();
if (update != null)
{
requestProperties.append(update);
}
//
EventControllerContext eventCC = context.getEventControllerContext();
//
EventPhaseContext phaseContext = new EventPhaseContext(controller, context, log);
// Feed session it with the events that may have been produced
for (UpdateNavigationalStateResponse.Event portletEvent : updateResponse.getEvents())
{
if (!phaseContext.push(new WindowEvent(portletEvent.getName(), portletEvent.getPayload(), portletRequest.getWindowId())))
{
return new PageUpdateResponse(updateResponse, requestProperties, pageNavigationalState, PortletResponse.INTERRUPTED);
}
}
// Deliver events
while (phaseContext.hasNext())
{
WindowEvent toConsumeEvent = phaseContext.next();
// Apply consumed event quota if necessary
int consumedEventThreshold = controller.getConsumedEventThreshold();
if (consumedEventThreshold >= 0)
{
if (phaseContext.consumedEventSize + 1 > consumedEventThreshold)
{
log.trace("Event distribution interrupted because the maximum number of consumed event is reached");
safeInvoker.eventDiscarded(eventCC, phaseContext, toConsumeEvent, EventControllerContext.CONSUMED_EVENT_FLOODED);
return new PageUpdateResponse(updateResponse, requestProperties, pageNavigationalState, PortletResponse.INTERRUPTED);
}
}
//
PortletInvocationResponse eventResponse;
try
{
eventResponse = deliverEvent(context, toConsumeEvent, pageNavigationalState, requestProperties.getCookies());
}
catch (Exception e)
{
log.trace("Event delivery of " + toConsumeEvent + " failed", e);
safeInvoker.eventFailed(eventCC, phaseContext, toConsumeEvent, e);
continue;
}
// Now it is consumed
phaseContext.consumedEventSize++;
// Update nav state if needed
if (eventResponse instanceof UpdateNavigationalStateResponse)
{
UpdateNavigationalStateResponse eventStateResponse = (UpdateNavigationalStateResponse)eventResponse;
// Update ns
updateNavigationalState(context, toConsumeEvent.getWindowId(), eventStateResponse, pageNavigationalState);
// Add events to source event queue
for (UpdateNavigationalStateResponse.Event portletEvent : eventStateResponse.getEvents())
{
WindowEvent toRouteEvent = new WindowEvent(portletEvent.getName(), portletEvent.getPayload(), toConsumeEvent.getWindowId());
//
if (!phaseContext.push(toConsumeEvent, toRouteEvent))
{
return new PageUpdateResponse(updateResponse, requestProperties, pageNavigationalState, PortletResponse.INTERRUPTED);
}
}
//
ResponseProperties updateProperties = eventStateResponse.getProperties();
if (updateProperties != null)
{
requestProperties.append(updateProperties);
}
}