Author: chris.laprun(a)jboss.com
Date: 2009-09-30 09:49:17 -0400 (Wed, 30 Sep 2009)
New Revision: 215
Added:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ProducerHolder.java
Removed:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/endpoints/
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ServiceDescriptionHandler.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPProducerImpl.java
components/wsrp/trunk/wsrp-producer-war/src/main/java/org/gatein/wsrp/endpoints/WSRPBaseEndpoint.java
Log:
- Changed mechanism to inject WSRPProducer into endpoints. Producer is now a singleton.
Might need to revisit this solution in the future, notably when clustering is required.
- Move ProducerHolder to producer package.
Copied:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ProducerHolder.java
(from rev 212,
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/endpoints/ProducerHolder.java)
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ProducerHolder.java
(rev 0)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ProducerHolder.java 2009-09-30
13:49:17 UTC (rev 215)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.wsrp.producer;
+
+/**
+ * Holds the current WSRPProducer as configured for a particular portlet container.
+ *
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class ProducerHolder
+{
+ private ProducerHolder()
+ {
+ }
+
+ public static WSRPProducer getProducer()
+ {
+ return getProducer(false);
+ }
+
+ public static WSRPProducer getProducer(boolean allowUnstartedProducer)
+ {
+ if (allowUnstartedProducer || WSRPProducerImpl.isProducerStarted())
+ {
+ return WSRPProducerImpl.getInstance();
+ }
+ else
+ {
+ throw new IllegalStateException("Attempting to access a non-started
producer!");
+ }
+ }
+}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ServiceDescriptionHandler.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ServiceDescriptionHandler.java 2009-09-29
22:55:57 UTC (rev 214)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ServiceDescriptionHandler.java 2009-09-30
13:49:17 UTC (rev 215)
@@ -66,7 +66,8 @@
* @version $Revision: 12017 $
* @since 2.4
*/
-class ServiceDescriptionHandler extends ServiceHandler implements
ServiceDescriptionInterface
+class
+ ServiceDescriptionHandler extends ServiceHandler implements
ServiceDescriptionInterface
{
// JBPORTAL-1220: force call to initCookie... Required so that BEA version < 9.2
will behave properly as a Consumer
private final CookieProtocol BEA_8_CONSUMER_FIX = CookieProtocol.PER_USER;
@@ -97,7 +98,10 @@
// get the portlet descriptions based on registration information
List<PortletDescription> offeredPortlets =
getPortletDescriptions(gs.getDesiredLocales(), registration);
- serviceDescription.getOfferedPortlets().addAll(offeredPortlets);
+ if (offeredPortlets != null)
+ {
+ serviceDescription.getOfferedPortlets().addAll(offeredPortlets);
+ }
// if we don't have registration information but a registration is required,
send registration props information
if (registration == null && requirements.isRegistrationRequired())
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPProducerImpl.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPProducerImpl.java 2009-09-29
22:55:57 UTC (rev 214)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPProducerImpl.java 2009-09-30
13:49:17 UTC (rev 215)
@@ -100,28 +100,43 @@
private PortletInvoker invoker;
/** Handles Markup interface calls. */
- private MarkupHandler markupHandler;
+ private final MarkupHandler markupHandler;
/** Handles ServiceDescription interface calls. */
- private ServiceDescriptionHandler serviceDescriptionHandler;
+ private final ServiceDescriptionHandler serviceDescriptionHandler;
/** Handles Registration interface calls. */
- private RegistrationHandler registrationHandler;
+ private final RegistrationHandler registrationHandler;
/** Handles Portlet Management interface calls. */
- private PortletManagementHandler portletManagementHandler;
+ private final PortletManagementHandler portletManagementHandler;
/** Registration Manager */
- private RegistrationManager registrationManager;
+ private RegistrationManager registrationManager; //todo: make sure it's
multi-thread safe
- /** Supported locales. */
- private List<String> supportedLocales = WSRPConstants.getDefaultLocales();
-
/** configuration service */
- private ProducerConfigurationService configurationService;
+ private ProducerConfigurationService configurationService; //todo: make sure it's
multi-thread safe
- public WSRPProducerImpl()
+ private boolean started = false;
+
+ // On-demand class holder Singleton pattern (multi-thread safe)
+ private static final class InstanceHolder
{
+ public static final WSRPProducerImpl producer = new WSRPProducerImpl();
+ }
+
+ static WSRPProducer getInstance()
+ {
+ return InstanceHolder.producer;
+ }
+
+ static boolean isProducerStarted()
+ {
+ return InstanceHolder.producer.started;
+ }
+
+ private WSRPProducerImpl()
+ {
markupHandler = new MarkupHandler(this);
serviceDescriptionHandler = new ServiceDescriptionHandler(this);
registrationHandler = new RegistrationHandler(this);
@@ -289,31 +304,41 @@
return configurationService;
}
- public void start()
+ public synchronized void start()
{
- ProducerConfiguration configuration = configurationService.getConfiguration();
+ if (!started)
+ {
+ ProducerConfiguration configuration = configurationService.getConfiguration();
- // register to listen to changes in configuration and get initial state
- configuration.addChangeListener(this);
- usingStrictModeChangedTo(configuration.isUsingStrictMode());
+ // register to listen to changes in configuration and get initial state
+ configuration.addChangeListener(this);
+ usingStrictModeChangedTo(configuration.isUsingStrictMode());
- ProducerRegistrationRequirements registrationRequirements =
getProducerRegistrationRequirements();
- registrationRequirements.addRegistrationPolicyChangeListener(registrationManager);
-
registrationRequirements.addRegistrationPropertyChangeListener(registrationManager);
+ ProducerRegistrationRequirements registrationRequirements =
getProducerRegistrationRequirements();
+
registrationRequirements.addRegistrationPolicyChangeListener(registrationManager);
+
registrationRequirements.addRegistrationPropertyChangeListener(registrationManager);
- if (registrationRequirements.isRegistrationRequired())
- {
- registrationManager.setPolicy(registrationRequirements.getPolicy());
+ if (registrationRequirements.isRegistrationRequired())
+ {
+ registrationManager.setPolicy(registrationRequirements.getPolicy());
+ }
+
+ started = true;
}
}
- public void stop()
+ public synchronized void stop()
{
- ProducerRegistrationRequirements registrationRequirements =
getProducerRegistrationRequirements();
-
registrationRequirements.removeRegistrationPropertyChangeListener(registrationManager);
-
registrationRequirements.removeRegistrationPolicyChangeListener(registrationManager);
+ if (started)
+ {
+ ProducerRegistrationRequirements registrationRequirements =
getProducerRegistrationRequirements();
+
registrationRequirements.removeRegistrationPropertyChangeListener(registrationManager);
+
registrationRequirements.removeRegistrationPolicyChangeListener(registrationManager);
- getProducerConfiguration().removeChangeListener(this);
+ getProducerConfiguration().removeChangeListener(this);
+
+ started = false;
+ }
}
int getExpirationTime()
@@ -441,7 +466,7 @@
public List<String> getSupportedLocales()
{
- return supportedLocales; // todo: avoid hardcoding this at some point...
+ return WSRPConstants.getDefaultLocales(); // todo: avoid hardcoding this at some
point...
}
public void usingStrictModeChangedTo(boolean strictMode)
Modified:
components/wsrp/trunk/wsrp-producer-war/src/main/java/org/gatein/wsrp/endpoints/WSRPBaseEndpoint.java
===================================================================
---
components/wsrp/trunk/wsrp-producer-war/src/main/java/org/gatein/wsrp/endpoints/WSRPBaseEndpoint.java 2009-09-29
22:55:57 UTC (rev 214)
+++
components/wsrp/trunk/wsrp-producer-war/src/main/java/org/gatein/wsrp/endpoints/WSRPBaseEndpoint.java 2009-09-30
13:49:17 UTC (rev 215)
@@ -23,6 +23,7 @@
package org.gatein.wsrp.endpoints;
+import org.gatein.wsrp.producer.ProducerHolder;
import org.gatein.wsrp.producer.WSRPProducer;
import org.gatein.wsrp.servlet.ServletAccess;