[portal-commits] JBoss Portal SVN: r5789 - in trunk: core/src/main/org/jboss/portal/core/impl/portlet/state portlet/src/main/org/jboss/portal/portlet/aspects/portlet

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Sun Dec 10 20:49:53 EST 2006


Author: julien at jboss.com
Date: 2006-12-10 20:49:48 -0500 (Sun, 10 Dec 2006)
New Revision: 5789

Added:
   trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/StateManagementPolicyImpl.java
   trunk/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/LocalInterceptor.java
Log:
- LocalInterceptor which denotes invocation from local portal
- StateManagementPolicy implementation whose decision is based on LocalInterceptor and RegistrationLocal

Added: trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/StateManagementPolicyImpl.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/StateManagementPolicyImpl.java	2006-12-11 01:32:38 UTC (rev 5788)
+++ trunk/core/src/main/org/jboss/portal/core/impl/portlet/state/StateManagementPolicyImpl.java	2006-12-11 01:49:48 UTC (rev 5789)
@@ -0,0 +1,55 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2006, 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.jboss.portal.core.impl.portlet.state;
+
+import org.jboss.portal.portlet.state.StateManagementPolicy;
+import org.jboss.portal.portlet.aspects.portlet.LocalInterceptor;
+import org.jboss.portal.wsrp.producer.registration.RegistrationLocal;
+import org.jboss.portal.wsrp.producer.registration.api.Registration;
+
+/**
+ * An implementation that rely on thread local context to make up its decision. State is locally persisted
+ * only for the local portal or for wsrp invocations in the context of a registration.
+ *
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class StateManagementPolicyImpl implements StateManagementPolicy
+{
+   public boolean persistLocally()
+   {
+      boolean local = LocalInterceptor.isLocal();
+
+      // If this is a local call we persist locally
+      if (local)
+      {
+         return true;
+      }
+
+      // Otherwise the optional registration from the wsrp layer
+      Registration registration = RegistrationLocal.getRegistration();
+
+      // And persist locally only in the scope of an existing registration
+      return registration != null;
+   }
+}

Added: trunk/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/LocalInterceptor.java
===================================================================
--- trunk/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/LocalInterceptor.java	2006-12-11 01:32:38 UTC (rev 5788)
+++ trunk/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/LocalInterceptor.java	2006-12-11 01:49:48 UTC (rev 5789)
@@ -0,0 +1,58 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2006, 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.jboss.portal.portlet.aspects.portlet;
+
+import org.jboss.portal.portlet.invocation.PortletInterceptor;
+import org.jboss.portal.portlet.invocation.PortletInvocation;
+import org.jboss.portal.common.invocation.InvocationException;
+
+/**
+ * An interceptor whose purpose is to detect invocation from the local portal.
+ *
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class LocalInterceptor extends PortletInterceptor
+{
+
+   /** . */
+   private static final ThreadLocal local = new ThreadLocal();
+
+   public static boolean isLocal()
+   {
+      return Boolean.TRUE.equals(local.get());
+   }
+
+   protected Object invoke(PortletInvocation invocation) throws Exception, InvocationException
+   {
+      try
+      {
+         local.set(Boolean.TRUE);
+         return invocation.invokeNext();
+      }
+      finally
+      {
+         local.set(null);
+      }
+   }
+}




More information about the portal-commits mailing list