You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by at...@apache.org on 2009/03/11 16:19:54 UTC
svn commit: r752466 - in
/portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container:
EventCoordinationServiceImpl.java EventProviderImpl.java
PortletWindowThread.java
Author: ate
Date: Wed Mar 11 15:19:45 2009
New Revision: 752466
URL: http://svn.apache.org/viewvc?rev=752466&view=rev
Log:
PLUTO-538: New EventCoordinationService and merging EventContainer with PortletContainer
See: https://issues.apache.org/jira/browse/PLUTO-538
- Implementing the new EventCoordinationServiceImpl, based upon the old (now deleted) EventProviderImpl
- *** untested ***
Added:
portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/EventCoordinationServiceImpl.java (contents, props changed)
- copied, changed from r752438, portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/EventProviderImpl.java
Removed:
portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/EventProviderImpl.java
Modified:
portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletWindowThread.java
Copied: portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/EventCoordinationServiceImpl.java (from r752438, portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/EventProviderImpl.java)
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/EventCoordinationServiceImpl.java?p2=portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/EventCoordinationServiceImpl.java&p1=portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/EventProviderImpl.java&r1=752438&r2=752466&rev=752466&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/EventProviderImpl.java (original)
+++ portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/EventCoordinationServiceImpl.java Wed Mar 11 15:19:45 2009
@@ -15,9 +15,6 @@
*/
package org.apache.pluto.driver.services.container;
-import java.io.Serializable;
-import java.io.StringWriter;
-import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -31,18 +28,11 @@
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
import javax.xml.namespace.QName;
-import javax.xml.stream.FactoryConfigurationError;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.pluto.container.Constants;
-import org.apache.pluto.container.EventContainer;
-import org.apache.pluto.container.EventProvider;
+import org.apache.pluto.container.EventCoordinationService;
import org.apache.pluto.container.PortletContainer;
import org.apache.pluto.container.PortletContainerException;
import org.apache.pluto.container.PortletWindow;
@@ -62,173 +52,45 @@
import org.apache.pluto.driver.url.PortalURL;
import org.apache.pluto.driver.url.impl.PortalURLParserImpl;
-public class EventProviderImpl implements org.apache.pluto.container.EventProvider,
- Cloneable {
-
- private static final int DEFAULT_MAPSIZE = 10;
-
+public class EventCoordinationServiceImpl implements EventCoordinationService
+{
/** Logger. */
- private static final Log LOG = LogFactory.getLog(EventProviderImpl.class);
+ private static final Log LOG = LogFactory.getLog(EventCoordinationServiceImpl.class);
private static final long WAITING_CYCLE = 100;
- private HttpServletRequest request;
-
- private HttpServletResponse response;
-
- private PortletContainer container;
-
- private PortletWindow portletWindow;
-
- ThreadGroup threadGroup = new ThreadGroup("FireEventThreads");
-
- private EventList savedEvents = new EventList();
-
- private Map<String, PortletWindowThread> portletWindowThreads = new HashMap<String, PortletWindowThread>();
-
/** PortletRegistryService used to obtain PortletApplicationConfig objects */
private PortletRegistryService portletRegistry;
/** PortletContextService used to obtain PortletContext objects */
private PortletContextService portletContextService;
-
- /**
- * factory method gets the EventProvider out of the Request, or sets a new
- * one
- *
- * @param request
- * The {@link HttpServletRequest} of the EventProvider
- * @param response
- * The {@link HttpServletResponse} of the EventProvider
- * @return The corresponding EventProvierImpl instance
- */
- public static EventProviderImpl getEventProviderImpl(
- HttpServletRequest request, PortletWindow portletWindow) {
- EventProviderImpl eventProvider = (EventProviderImpl) request
- .getAttribute(Constants.PROVIDER);
- if (eventProvider == null) {
- eventProvider = new EventProviderImpl();
- eventProvider.request = request;
- PortalRequestContext context = PortalRequestContext
- .getContext(request);
- eventProvider.response = context.getResponse();
- ServletContext servletContext = context.getServletContext();
- eventProvider.container = (PortletContainer) servletContext
- .getAttribute(AttributeKeys.PORTLET_CONTAINER);
- request.setAttribute(Constants.PROVIDER, eventProvider);
- }
- try {
- eventProvider = (EventProviderImpl) eventProvider.clone();
- } catch (CloneNotSupportedException e) {
- throw new IllegalStateException(e);
- }
- eventProvider.portletWindow = portletWindow;
- return eventProvider;
- }
-
- /**
- * factory method, for accessing the static elements without a request /
- * response FIXME: bad idea
- *
- * @return The EventProvider for accessing the static elements
- */
- public static EventProvider getEventProviderImpl() {
- return new EventProviderImpl();
- }
-
- /**
- * c'tor
- */
- private EventProviderImpl() {
-
- }
-
- /**
- * Register an event, which should be fired within that request
- *
- * @param qname
- * @param value
- * @throws {@link IllegalArgumentException}
- */
- public void registerToFireEvent(QName qname, Serializable value)
- throws IllegalArgumentException {
- if (isDeclaredAsPublishingEvent(qname)) {
-
- if (value != null && !isValueInstanceOfDefinedClass(qname, value))
- throw new IllegalArgumentException(
- "Payload has not the right class");
-
- try {
-
- if (value == null) {
- savedEvents.addEvent(new EventImpl(qname, value));
- } else if (!(value instanceof Serializable)) {
- throw new IllegalArgumentException(
- "Object payload must implement Serializable");
- } else {
-
- Writer out = new StringWriter();
-
- Class clazz = value.getClass();
-
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- try
- {
- Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
- JAXBContext jc = JAXBContext.newInstance(clazz);
-
- Marshaller marshaller = jc.createMarshaller();
-
- JAXBElement<Serializable> element = new JAXBElement<Serializable>(
- qname, clazz, value);
- marshaller.marshal(element, out);
- // marshaller.marshal(value, out);
- }
- finally
- {
- Thread.currentThread().setContextClassLoader(cl);
- }
-
- if (out != null) {
- savedEvents.addEvent(new EventImpl(qname,
- (Serializable) out.toString()));
- } else {
- savedEvents.addEvent(new EventImpl(qname, value));
- }
- }
- } catch (JAXBException e) {
- // maybe there is no valid jaxb binding
- // TODO wsrp:eventHandlingFailed
- LOG.error("Event handling failed", e);
- } catch (FactoryConfigurationError e) {
- LOG.warn(e);
- }
- }
- }
-
- /**
- * Fire all saved events Note, that the order isn't important
- *
- * @see PLT14.3.2
- * @param eventContainer
- * The {@link PortletContainerImpl} to fire the events
- */
- public void fireEvents(EventContainer eventContainer) {
+
+ public void processEvents(PortletContainer container, PortletWindow portletWindow, HttpServletRequest request,
+ HttpServletResponse response, List<Event> events)
+ {
+ if (portletRegistry == null)
+ {
+ portletRegistry = PlutoServices.getServices().getPortletRegistryService();
+ }
+ if (portletContextService == null)
+ {
+ portletContextService = PlutoServices.getServices().getPortletContextService();
+ }
+
ServletContext containerServletContext = PortalRequestContext.getContext(request).getServletContext();
DriverConfiguration driverConfig = (DriverConfiguration) containerServletContext
.getAttribute(AttributeKeys.DRIVER_CONFIG);
PortalURL portalURL = PortalURLParserImpl.getParser().parse(request);
- while (savedEvents.hasMoreEvents()
- && savedEvents.getSize() < Constants.MAX_EVENTS_SIZE) {
-
- Event eActual = getArbitraryEvent();
+ Map<String, PortletWindowThread> portletWindowThreads = new HashMap<String, PortletWindowThread>();
- this.savedEvents.setProcessed(eActual);
+ ThreadGroup threadGroup = new ThreadGroup("FireEventThreads");
+ for (Event event : events)
+ {
List<String> portletNames = getAllPortletsRegisteredForEvent(
- eActual, driverConfig, containerServletContext);
+ event, driverConfig, containerServletContext);
Collection<PortletWindowConfig> portlets = getAllPortlets(driverConfig);
@@ -244,25 +106,25 @@
// for the old to exit
- PortletWindowThread portletWindowThread = getPortletWindowThread(
- eventContainer, config, window, containerServletContext);
+ PortletWindowThread portletWindowThread = getPortletWindowThread(portletWindowThreads,
+ threadGroup, container, config, window, request, response, containerServletContext);
// is this event
- portletWindowThread.addEvent(eActual);
+ portletWindowThread.addEvent(event);
portletWindowThread.start();
}
}
}
}
- waitForEventExecution();
+ waitForEventExecution(threadGroup);
try {
Thread.sleep(WAITING_CYCLE);
} catch (InterruptedException e) {
LOG.warn(e);
}
}
- waitForEventExecution();
+ waitForEventExecution(threadGroup);
}
private List<String> getAllPortletsRegisteredForEvent(Event event,
@@ -271,9 +133,6 @@
List<String> resultList = new ArrayList<String>();
QName eventName = event.getQName();
Collection<PortletWindowConfig> portlets = getAllPortlets(driverConfig);
- if (portletRegistry == null) {
- portletRegistry = PlutoServices.getServices().getPortletRegistryService();
- }
for (PortletWindowConfig portlet : portlets) {
String contextPath = portlet.getContextPath();
@@ -374,49 +233,41 @@
/**
* gets the right PortletWindowThread or makes a new one, if theres none
*
- * @param eventContainer
- * @param config
- * @param window
- * @return
*/
- private PortletWindowThread getPortletWindowThread(
- EventContainer eventContainer, PortletWindowConfig config,
- PortletWindow window, ServletContext containerServletContext) {
- if (portletContextService == null) {
- portletContextService = PlutoServices.getServices().getPortletContextService();
- }
- if (portletContextService != null){
- String windowID = window.getId().getStringId();
- PortletWindowThread portletWindowThread = portletWindowThreads
- .get(windowID);
- if (portletWindowThread == null) {
- portletWindowThread = new PortletWindowThread(threadGroup, config
- .getId(), this, window, eventContainer,portletContextService);
- portletWindowThreads.put(windowID, portletWindowThread);
- } else {
- // a thread could be started twice, so we make a new one,
- // after the old thread stopped
- // try {
- try {
- portletWindowThread.join();
- } catch (InterruptedException e) {
- LOG.warn(e);
- }
- portletWindowThreads.remove(portletWindowThread);
- portletWindowThread = new PortletWindowThread(threadGroup, config
- .getId(), this, window, eventContainer,portletContextService);
- portletWindowThreads.put(windowID, portletWindowThread);
- }
- return portletWindowThread;
- }
- else
- return null;
+ private PortletWindowThread getPortletWindowThread(Map<String, PortletWindowThread> portletWindowThreads, ThreadGroup threadGroup,
+ PortletContainer container, PortletWindowConfig config,
+ PortletWindow window, HttpServletRequest req, HttpServletResponse res, ServletContext containerServletContext)
+ {
+ String windowID = window.getId().getStringId();
+ PortletWindowThread portletWindowThread = portletWindowThreads
+ .get(windowID);
+ if (portletWindowThread == null) {
+ portletWindowThread = new PortletWindowThread(threadGroup, config.getId(),
+ container, window,
+ req, res, portletContextService);
+ portletWindowThreads.put(windowID, portletWindowThread);
+ } else {
+ // a thread could be started twice, so we make a new one,
+ // after the old thread stopped
+ // try {
+ try {
+ portletWindowThread.join();
+ } catch (InterruptedException e) {
+ LOG.warn(e);
+ }
+ portletWindowThreads.remove(portletWindowThread);
+ portletWindowThread = new PortletWindowThread(threadGroup, config.getId(),
+ container, window,
+ req, res, portletContextService);
+ portletWindowThreads.put(windowID, portletWindowThread);
+ }
+ return portletWindowThread;
}
/**
* Wait for event execution.
*/
- private void waitForEventExecution() {
+ private void waitForEventExecution(ThreadGroup threadGroup) {
long counter = 0;
while (threadGroup.activeCount() > 0) {
try {
@@ -432,150 +283,25 @@
}
/**
- * gets an arbitrary event, which is not processed yet.
- *
- * @return the arbitrary event
- */
- private Event getArbitraryEvent() {
- Event eActual = null;
- for (Event event : this.savedEvents.getEvents()) {
- if (this.savedEvents.isNotProcessed(event)) {
- eActual = event;
- }
- }
- return eActual;
- }
-
- /**
*
*/
- private Collection<PortletWindowConfig> getAllPortlets(
- DriverConfiguration driverConfig) {
+ private Collection<PortletWindowConfig> getAllPortlets(DriverConfiguration driverConfig)
+ {
Collection<PortletWindowConfig> portlets = new ArrayList<PortletWindowConfig>();
- ServletContext servletContext = PortalRequestContext
- .getContext(request).getServletContext();
-// if (portletRegistry == null) {
-// portletRegistry = ((PortletContainer) servletContext
-// .getAttribute(AttributeKeys.PORTLET_CONTAINER))
-// .getOptionalContainerServices().getPortletRegistryService();
-// }
-// if (portletRegistry != null){
- Collection pages = driverConfig.getPages();
- if (pages != null){
- Iterator iPages = pages.iterator();
- while(iPages.hasNext()){
- PageConfig pageConfig = (PageConfig) iPages.next();
- Collection portletIDs = pageConfig.getPortletIds();
- if (portletIDs != null){
- Iterator iPortletIDs = portletIDs.iterator();
- while(iPortletIDs.hasNext()){
- portlets.add(PortletWindowConfig.fromId(iPortletIDs.next().toString()));
- }
- }
- }
- }
-
-// PortletWindowConfig.fromId(((PageConfig)driverConfig.getPages().iterator().next()).getPortletIds().iterator().next().toString());
-// Iterator i = portletRegistry.getRegisteredPortletApplications();
-// while(i.hasNext()){
-// portlets.addAll(((PortletAppDD)portletRegistry.getRegisteredPortletApplications().next()).getPortlets());
-// }
-// }
-
- // Collection<PortletApplicationConfig> apps =
- // driverConfig.getPortletApplications();
-
- // for (PortletApplicationConfig app : apps) {
- // portlets.addAll(app.getPortlets());
- // }
- return portlets;
- }
-
- /**
- * @return the request
- */
- public HttpServletRequest getRequest() {
- return request;
- }
-
- /**
- * @return the response
- */
- public HttpServletResponse getResponse() {
- return response;
- }
-
- /**
- * Gets the saved events.
- *
- * @return the saved events
- */
- public EventList getSavedEvents() {
- return savedEvents;
- }
-
- private boolean isDeclaredAsPublishingEvent(QName qname) {
- ServletContext servletContext = PortalRequestContext
- .getContext(request).getServletContext();
- String applicationId = PortletWindowConfig
- .parseContextPath(portletWindow.getId().getStringId());
- String applicationName = applicationId;
- if (applicationId.length() >0 )
- {
- applicationName = applicationId.substring(1);
- }
-
- String portletName = PortletWindowConfig
- .parsePortletName(portletWindow.getId().getStringId());
- if (portletRegistry == null) {
- portletRegistry = PlutoServices.getServices().getPortletRegistryService();
- }
- List<? extends EventDefinitionReference> events = null;
- try {
- events = portletRegistry.getPortlet(applicationName,
- portletName).getSupportedPublishingEvents();
- } catch (PortletContainerException e1) {
- e1.printStackTrace();
- }
- if (events != null) {
- String defaultNamespace = portletWindow.getPortletEntity().getPortletDefinition().getApplication().getDefaultNamespace();
- for (EventDefinitionReference ref : events) {
- QName name = ref.getQualifiedName(defaultNamespace);
- if (name == null)
- {
- continue;
- }
- if (qname.equals(name)) {
- return true;
- }
- }
- }
- return false;
- }
-
- private boolean isValueInstanceOfDefinedClass(QName qname,
- Serializable value) {
- PortletApplicationDefinition app = portletWindow.getPortletEntity().getPortletDefinition().getApplication();
- List<? extends EventDefinition> events = app.getEventDefinitions();
- if (events != null) {
-
-
- for (EventDefinition def : events){
- if (def.getQName() != null){
- if (def.getQName().equals(qname))
- return value.getClass().getName().equals(
- def.getValueType());
- }
- else{
- QName tmp = new QName(app.getDefaultNamespace(),def.getName());
- if (tmp.equals(qname))
- return value.getClass().getName().equals(
- def.getValueType());
+ Collection pages = driverConfig.getPages();
+ if (pages != null){
+ Iterator iPages = pages.iterator();
+ while(iPages.hasNext()){
+ PageConfig pageConfig = (PageConfig) iPages.next();
+ Collection portletIDs = pageConfig.getPortletIds();
+ if (portletIDs != null){
+ Iterator iPortletIDs = portletIDs.iterator();
+ while(iPortletIDs.hasNext()){
+ portlets.add(PortletWindowConfig.fromId(iPortletIDs.next().toString()));
+ }
}
}
}
- // event not declared
- return true;
+ return portlets;
}
-
}
Propchange: portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/EventCoordinationServiceImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletWindowThread.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletWindowThread.java?rev=752466&r1=752465&r2=752466&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletWindowThread.java (original)
+++ portals/pluto/trunk/pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/services/container/PortletWindowThread.java Wed Mar 11 15:19:45 2009
@@ -37,7 +37,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.pluto.container.EventContainer;
+import org.apache.pluto.container.PortletContainer;
import org.apache.pluto.container.PortletContainerException;
import org.apache.pluto.container.PortletWindow;
import org.apache.pluto.container.driver.PortletContextService;
@@ -50,11 +50,12 @@
/** Logger. */
private static final Log LOG = LogFactory.getLog(PortletWindowThread.class);
- private EventProviderImpl eventProvider;
-
+ private PortletContainer container;
+
private PortletWindow portletWindow;
- private EventContainer eventContainer;
+ private HttpServletRequest request;
+ private HttpServletResponse response;
/** PortletRegistryService used to obtain PortletApplicationConfig objects */
private PortletContextService portletContextService;
@@ -62,11 +63,15 @@
private List<Event> events = new ArrayList<Event>();
public PortletWindowThread(ThreadGroup group, String name,
- EventProviderImpl eventProvider, PortletWindow window, EventContainer eventContainer, PortletContextService portletContextService) {
+ PortletContainer container, PortletWindow window,
+ HttpServletRequest request, HttpServletResponse response,
+ PortletContextService portletContextService)
+ {
super(group, name);
- this.eventProvider = eventProvider;
+ this.request = request;
+ this.response = response;
this.portletWindow = window;
- this.eventContainer = eventContainer;
+ this.container = container;
this.portletContextService = portletContextService;
}
@@ -77,8 +82,7 @@
public void run() {
super.run();
while (events.size() > 0) {
- HttpServletRequest req = new PortalServletRequest(eventProvider.getRequest(), this.portletWindow);
- HttpServletResponse res = eventProvider.getResponse();
+ HttpServletRequest req = new PortalServletRequest(this.request, this.portletWindow);
try {
// synchronized (this) {
Event event = events.remove(0);
@@ -126,7 +130,7 @@
throw new IllegalStateException(e);
}
}
- eventContainer.fireEvent(req, res, portletWindow, event);
+ container.doEvent(portletWindow, req, response, event);
// }
} catch (PortletException e) {
LOG.warn(e);
@@ -142,7 +146,7 @@
this.events.add(event);
}
- private EventDefinition getEventDefintion(QName name) throws PortletContainerException {
+ private EventDefinition getEventDefintion(QName name) {
PortletApplicationDefinition appDD = portletWindow.getPortletEntity().getPortletDefinition().getApplication();
for (EventDefinition def : appDD.getEventDefinitions()){
if (def.getQName() != null){
@@ -157,5 +161,4 @@
}
throw new IllegalStateException();
}
-
}