Author: julien(a)jboss.com
Date: 2008-02-18 08:08:46 -0500 (Mon, 18 Feb 2008)
New Revision: 10018
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletRequestHandler.java
modules/portlet/trunk/controller/src/test/java/org/jboss/portal/portlet/controller/PortletControllerTestCase.java
Log:
- correctly implement the new controller event dispatching options.
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletRequestHandler.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletRequestHandler.java 2008-02-18
12:32:40 UTC (rev 10017)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletRequestHandler.java 2008-02-18
13:08:46 UTC (rev 10018)
@@ -107,46 +107,39 @@
UpdateNavigationalStateResponse stateResponse =
(UpdateNavigationalStateResponse)response;
// Create event list and feed it with the events that may have been produced
- LinkedList<Event> eventQueue = new LinkedList<Event>();
+ LinkedList<Event> srcEventQueue = new LinkedList<Event>();
for (UpdateNavigationalStateResponse.Event portletEvent :
stateResponse.getEvents())
{
Event producedEvent = new Event(portletEvent.getName(),
portletEvent.getPayload(), portletRequest.getWindowId());
- List<Event> consumedEvents = eventCC.getConsumedEvents(producedEvent);
- eventQueue.addAll(consumedEvents);
+ srcEventQueue.add(producedEvent);
}
// Deliver events
- while (eventQueue.size() > 0)
+ while (srcEventQueue.size() > 0)
{
- Event event = eventQueue.removeFirst();
+ Event srcEvent = srcEventQueue.removeFirst();
//
- String targetId = event.getWindowId();
+ String srcId = srcEvent.getWindowId();
//
- PortletInfo targetPortletInfo = context.getPortletInfo(targetId);
+ PortletInfo srcPortletInfo = context.getPortletInfo(srcId);
//
- if (targetPortletInfo == null)
+ if (srcPortletInfo == null)
{
- if (log.isTraceEnabled())
- {
- log.trace("Cannot deliver event " + event +" because the
target of the event does not have a portlet info");
- }
+ log.trace("Cannot deliver event " + srcEvent +" because the
source does not have portlet info");
//
continue;
}
//
- if (!controller.getDistributeNonConsumableEvents())
+ if (!controller.getDistributeNonProduceableEvents())
{
- if
(!targetPortletInfo.getEventing().getConsumedEvents().containsKey(event.getName()))
+ if
(!srcPortletInfo.getEventing().getProducedEvents().containsKey(srcEvent.getName()))
{
- if (log.isTraceEnabled())
- {
- log.trace("Cannot deliver event " + event +" because
the target of the event does not accept the event name");
- }
+ log.trace("Cannot deliver event " + srcEvent +" because
the source of the event does not produce the event name");
//
continue;
@@ -154,39 +147,77 @@
}
//
- PortletInvocationResponse eventResponse = deliverEvent(context, event,
pageState, requestProperties.getCookies());
+ List<Event> dstEvents = eventCC.getConsumedEvents(srcEvent);
//
- if (eventResponse instanceof UpdateNavigationalStateResponse)
+ for (Event dstEvent : dstEvents)
{
- UpdateNavigationalStateResponse eventStateResponse =
(UpdateNavigationalStateResponse)eventResponse;
+ String dstId = dstEvent.getWindowId();
- // Update ns
- updateNavigationalState(context, event.getWindowId(), eventStateResponse,
pageState);
+ //
+ PortletInfo dstPortletInfo = context.getPortletInfo(dstId);
- // Add events if any
- for (UpdateNavigationalStateResponse.Event portletEvent :
eventStateResponse.getEvents())
+
+ //
+ if (dstPortletInfo == null)
{
- Event producedEvent = new Event(portletEvent.getName(),
portletEvent.getPayload(), event.getWindowId());
- List<Event> consumedEvents =
eventCC.getConsumedEvents(producedEvent);
- eventQueue.addAll(consumedEvents);
+ if (log.isTraceEnabled())
+ {
+ log.trace("Cannot deliver event " + srcEvent +"
because the target of the event does not have a portlet info");
+ }
+
+ //
+ continue;
}
//
- ResponseProperties updateProperties = eventStateResponse.getProperties();
- if (updateProperties != null)
+ if (!controller.getDistributeNonConsumableEvents())
{
- requestProperties.append(updateProperties);
+ if
(!dstPortletInfo.getEventing().getConsumedEvents().containsKey(dstEvent.getName()))
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("Cannot deliver event " + srcEvent +"
because the target of the event does not accept the event name");
+ }
+
+ //
+ continue;
+ }
}
+
+ //
+ PortletInvocationResponse eventResponse = deliverEvent(context, dstEvent,
pageState, requestProperties.getCookies());
+
+ //
+ if (eventResponse instanceof UpdateNavigationalStateResponse)
+ {
+ UpdateNavigationalStateResponse eventStateResponse =
(UpdateNavigationalStateResponse)eventResponse;
+
+ // Update ns
+ updateNavigationalState(context, dstEvent.getWindowId(),
eventStateResponse, pageState);
+
+ // Add events to source event queue
+ for (UpdateNavigationalStateResponse.Event portletEvent :
eventStateResponse.getEvents())
+ {
+ srcEventQueue.add(new Event(portletEvent.getName(),
portletEvent.getPayload(), dstEvent.getWindowId()));
+ }
+
+ //
+ ResponseProperties updateProperties =
eventStateResponse.getProperties();
+ if (updateProperties != null)
+ {
+ requestProperties.append(updateProperties);
+ }
+ }
+ else if (eventResponse instanceof ErrorResponse)
+ {
+ // Do something here !!!!
+ }
+ else
+ {
+ // Do something here !!!!
+ }
}
- else if (eventResponse instanceof ErrorResponse)
- {
- // Do something here !!!!
- }
- else
- {
- // Do something here !!!!
- }
}
//
Modified:
modules/portlet/trunk/controller/src/test/java/org/jboss/portal/portlet/controller/PortletControllerTestCase.java
===================================================================
---
modules/portlet/trunk/controller/src/test/java/org/jboss/portal/portlet/controller/PortletControllerTestCase.java 2008-02-18
12:32:40 UTC (rev 10017)
+++
modules/portlet/trunk/controller/src/test/java/org/jboss/portal/portlet/controller/PortletControllerTestCase.java 2008-02-18
13:08:46 UTC (rev 10018)
@@ -139,8 +139,8 @@
PortletSupport barPortlet = invoker.addPortlet("bar");
//
- EventProducerAction fooEventProducer = new EventProducerAction(srcName);
- NoOpEventProcessor fooEventConsumer = new NoOpEventProcessor();
+ EventProducerAction eventProducer = new EventProducerAction(srcName);
+ NoOpEventProcessor eventConsumer = new NoOpEventProcessor();
// Create wire
context.getEventControllerContext().createWire(srcName, "foo", dstName,
"bar");
@@ -155,16 +155,18 @@
);
//
+ controller.setDistributeNonProduceableEvents(true);
controller.setDistributeNonConsumableEvents(true);
- fooPortlet.addHandler(fooEventProducer);
- barPortlet.addHandler(fooEventConsumer);
+ fooPortlet.addHandler(eventProducer);
+ barPortlet.addHandler(eventConsumer);
controller.process(context, request);
fooPortlet.assertInvocationCountIs(1);
barPortlet.assertInvocationCountIs(1);
//
+ controller.setDistributeNonProduceableEvents(true);
controller.setDistributeNonConsumableEvents(false);
- fooPortlet.addHandler(fooEventProducer);
+ fooPortlet.addHandler(eventProducer);
controller.process(context, request);
fooPortlet.assertInvocationCountIs(2);
barPortlet.assertInvocationCountIs(1);
@@ -173,20 +175,59 @@
barPortlet.getInfo().getEventing().addConsumedEvent(new
EventInfoSupport(dstName));
//
+ controller.setDistributeNonProduceableEvents(true);
controller.setDistributeNonConsumableEvents(true);
- fooPortlet.addHandler(fooEventProducer);
- barPortlet.addHandler(fooEventConsumer);
+ fooPortlet.addHandler(eventProducer);
+ barPortlet.addHandler(eventConsumer);
controller.process(context, request);
fooPortlet.assertInvocationCountIs(3);
barPortlet.assertInvocationCountIs(2);
//
+ controller.setDistributeNonProduceableEvents(true);
controller.setDistributeNonConsumableEvents(false);
- fooPortlet.addHandler(fooEventProducer);
- barPortlet.addHandler(fooEventConsumer);
+ fooPortlet.addHandler(eventProducer);
+ barPortlet.addHandler(eventConsumer);
controller.process(context, request);
fooPortlet.assertInvocationCountIs(4);
barPortlet.assertInvocationCountIs(3);
+
+ //
+ controller.setDistributeNonProduceableEvents(false);
+ controller.setDistributeNonConsumableEvents(true);
+ fooPortlet.addHandler(eventProducer);
+ controller.process(context, request);
+ fooPortlet.assertInvocationCountIs(5);
+ barPortlet.assertInvocationCountIs(3);
+
+ //
+ controller.setDistributeNonProduceableEvents(false);
+ controller.setDistributeNonConsumableEvents(false);
+ fooPortlet.addHandler(eventProducer);
+ controller.process(context, request);
+ fooPortlet.assertInvocationCountIs(6);
+ barPortlet.assertInvocationCountIs(3);
+
+ //
+ fooPortlet.getInfo().getEventing().addProducedEvent(new
EventInfoSupport(srcName));
+
+ //
+ controller.setDistributeNonProduceableEvents(false);
+ controller.setDistributeNonConsumableEvents(true);
+ fooPortlet.addHandler(eventProducer);
+ barPortlet.addHandler(eventConsumer);
+ controller.process(context, request);
+ fooPortlet.assertInvocationCountIs(7);
+ barPortlet.assertInvocationCountIs(4);
+
+ //
+ controller.setDistributeNonProduceableEvents(false);
+ controller.setDistributeNonConsumableEvents(false);
+ fooPortlet.addHandler(eventProducer);
+ barPortlet.addHandler(eventConsumer);
+ controller.process(context, request);
+ fooPortlet.assertInvocationCountIs(8);
+ barPortlet.assertInvocationCountIs(5);
}
private static class EventProducerAction extends PortletSupport.ActionHandler
Show replies by date