portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r743949 - in /portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container: providers/EventProviderImpl.java services/JetspeedPortalCallbackServices.java
Date Fri, 13 Feb 2009 01:47:31 GMT
Author: taylor
Date: Fri Feb 13 01:47:30 2009
New Revision: 743949

URL: http://svn.apache.org/viewvc?rev=743949&view=rev
Log:
https://issues.apache.org/jira/browse/JS2-927
Events now firing. this is a first implementation of basic interportlet communication. Refinements:
* Event Queue - there is a static Hashmap to represent the Event Queue. I will be replacing
this with a more robust event queue.
* Advanced Algorithms - default algorithm only notifies portlets on the same page
* refine service api - introduce EventCoordinationService
* support for container initiated events
* Threading

Tested with Sun's EventingMap example (continents) 

Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/providers/EventProviderImpl.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/services/JetspeedPortalCallbackServices.java

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/providers/EventProviderImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/providers/EventProviderImpl.java?rev=743949&r1=743948&r2=743949&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/providers/EventProviderImpl.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/providers/EventProviderImpl.java
Fri Feb 13 01:47:30 2009
@@ -20,8 +20,10 @@
 import java.io.StringWriter;
 import java.io.Writer;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
 
 import javax.portlet.Event;
 import javax.servlet.http.HttpServletRequest;
@@ -60,11 +62,13 @@
 public class EventProviderImpl implements EventProvider, Cloneable
 {
     private static Log log = LogFactory.getLog(EventProviderImpl.class);
-    private final PortletWindow portletWindow;
-    private EventList savedEvents = new EventList();
+    private final PortletWindow portletWindow;    
     private final RequestContext rc;
     private final PortletWindowAccessor windowAccessor;
     
+    // IMPROVEME: (a lot) this is a simple-non-production implementation of an event queue
+    private static Map<String, EventList> eventQueue = new HashMap<String, EventList>();
+    
     public EventProviderImpl()
     {
         windowAccessor = null;
@@ -83,6 +87,7 @@
             throws IllegalArgumentException
     {
         System.out.println("registering to fire events");
+        EventList savedEvents = new EventList();        
         if (isDeclaredAsPublishingEvent(qname)) 
         {
             if (value != null && !isValueInstanceOfDefinedClass(qname, value))
@@ -119,6 +124,7 @@
                     {
                         Thread.currentThread().setContextClassLoader(cl);
                     }
+                    out = null;
                     if (out != null) 
                     {
                         savedEvents.addEvent(new EventImpl(qname,
@@ -140,19 +146,23 @@
                 log.warn(e);
             }
         }
+        eventQueue.put(this.portletWindow.getId().toString(), savedEvents);
     }
     
     public static final int MAX_EVENTS_SIZE = 10; // TODO
     
     public void fireEvents(EventContainer eventContainer)
     {
-        System.out.println("firing events");
-
+        String eventTargetWindow = this.portletWindow.getId().toString();
+        System.out.println("firing events for " + eventTargetWindow);
+        EventList savedEvents = this.eventQueue.get(eventTargetWindow);
+        if (savedEvents == null)
+            return;
         while (savedEvents.hasMoreEvents()
                 && savedEvents.getSize() < MAX_EVENTS_SIZE) 
         {
-            Event event = getArbitraryEvent();
-            this.savedEvents.setProcessed(event);
+            Event event = getArbitraryEvent(savedEvents);
+            savedEvents.setProcessed(event);
             
             List<PortletWindow> windows = getAllPortletsRegisteredForEvent(event);
 
@@ -175,7 +185,7 @@
                     // TODO: handle
                     e.printStackTrace();
                 }
-                    
+                this.eventQueue.remove(eventTargetWindow);    
 // TODO: threading                
 //                PortletWindow window = new PortletWindowImpl(container, config, portalURL);
 //                if (portletNames != null) {
@@ -198,6 +208,7 @@
 //                    }
                 }
             }
+        
 //            waitForEventExecution();
 //            try {
 //                Thread.sleep(WAITING_CYCLE);
@@ -259,12 +270,12 @@
         return true;
     }
     
-    private Event getArbitraryEvent() 
+    private Event getArbitraryEvent(EventList savedEvents) 
     {
         Event eActual = null;
-        for (Event event : this.savedEvents.getEvents()) 
+        for (Event event : savedEvents.getEvents()) 
         {
-            if (this.savedEvents.isNotProcessed(event)) 
+            if (savedEvents.isNotProcessed(event)) 
             {
                 eActual = event;
             }

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/services/JetspeedPortalCallbackServices.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/services/JetspeedPortalCallbackServices.java?rev=743949&r1=743948&r2=743949&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/services/JetspeedPortalCallbackServices.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/container/services/JetspeedPortalCallbackServices.java
Fri Feb 13 01:47:30 2009
@@ -93,13 +93,7 @@
             org.apache.pluto.PortletWindow portletWindow)
     {   
         RequestContext rc = (RequestContext) request.getAttribute(PortalReservedParameters.REQUEST_CONTEXT_ATTRIBUTE);
-        EventProvider provider = (EventProvider)rc.getObjects().get(PER_REQUEST_EVENT_PROVIDER);
-        if (provider == null)
-        {
-            provider  = new EventProviderImpl(rc, portletWindow, this.windowAccessor);
-            rc.getObjects().put(PER_REQUEST_EVENT_PROVIDER, provider);
-        }
-        return provider;
+        return new EventProviderImpl(rc, portletWindow, this.windowAccessor);
     }
 
     public EventProvider getEventProvider()



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message