Author: drobiazko
Date: Wed May 26 07:05:38 2010
New Revision: 948348

URL: http://svn.apache.org/viewvc?rev=948348&view=rev
Log:
TAP5-978: Provide remote management of the page pool settings

Added:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MBeanSupport.java
   (with props)
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MBeanSupportImpl.java
   (with props)
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePoolImplMBean.java
   (with props)
    
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/RemotePoolManagement.tml
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/RemotePoolManagement.java
   (with props)
Modified:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalModule.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePoolImpl.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalModule.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalModule.java?rev=948348&r1=948347&r2=948348&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalModule.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/InternalModule.java
 Wed May 26 07:05:38 2010
@@ -14,6 +14,7 @@
 
 package org.apache.tapestry5.internal.services;
 
+import javax.management.ObjectName;
 import javax.servlet.http.Cookie;
 
 import org.apache.tapestry5.SymbolConstants;
@@ -36,6 +37,7 @@ import org.apache.tapestry5.ioc.services
 import org.apache.tapestry5.ioc.services.ClasspathURLConverter;
 import org.apache.tapestry5.ioc.services.PerthreadManager;
 import org.apache.tapestry5.ioc.services.PropertyShadowBuilder;
+import org.apache.tapestry5.ioc.services.RegistryShutdownHub;
 import org.apache.tapestry5.services.*;
 import org.apache.tapestry5.services.templates.ComponentTemplateLocator;
 import org.slf4j.Logger;
@@ -170,7 +172,9 @@ public class InternalModule
     InvalidationEventHub templatesHub,
 
     @ComponentMessages
-    InvalidationEventHub messagesHub)
+    InvalidationEventHub messagesHub,
+    
+    MBeanSupport managedBeanSupport)
     {
         // This covers invalidations due to changes to classes
 
@@ -188,6 +192,29 @@ public class InternalModule
 
         updateListenerHub.addUpdateListener(service);
 
+        final ObjectName objectName = 
buildObjectName("org.apache.tapestry5:type=PagePool");
+        
+        managedBeanSupport.register(service, objectName);
+
+        return service;
+    }
+    
+    private ObjectName buildObjectName(String name)
+    {
+        try
+        {
+            return new ObjectName(name);
+        }
+        catch (Exception e)
+        {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public MBeanSupport buildMBeanSupport(RegistryShutdownHub shutdownHub, 
@Autobuild MBeanSupportImpl service)
+    {
+        shutdownHub.addRegistryShutdownListener(service);
+        
         return service;
     }
 

Added: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MBeanSupport.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MBeanSupport.java?rev=948348&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MBeanSupport.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MBeanSupport.java
 Wed May 26 07:05:38 2010
@@ -0,0 +1,42 @@
+// Copyright 20010 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.internal.services;
+
+import javax.management.ObjectName;
+
+/**
+ * Creates an MBean server and registers MBeans with the created server. The 
registered MBeans are unregistered when Registry is shut down.
+ * 
+ * @since 5.2.0
+ */
+public interface MBeanSupport 
+{
+
+    /**
+     * Registers the specified MBean with the server.
+     * 
+     * @param bean the MBean instance
+     * @param objectName the name for the MBean
+     */
+    void register(final Object bean, final ObjectName objectName);
+
+    /**
+     * Unregisters the specified MBean from the server.
+     * 
+     * @param objectName the name for the MBean
+     */
+    void unregister(final ObjectName objectName);
+
+}
\ No newline at end of file

Propchange: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MBeanSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MBeanSupport.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MBeanSupportImpl.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MBeanSupportImpl.java?rev=948348&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MBeanSupportImpl.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MBeanSupportImpl.java
 Wed May 26 07:05:38 2010
@@ -0,0 +1,101 @@
+// Copyright 20010 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.internal.services;
+
+import static java.lang.String.format;
+
+import java.lang.management.ManagementFactory;
+import java.util.List;
+import java.util.Set;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+
+import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry5.ioc.services.RegistryShutdownListener;
+import org.slf4j.Logger;
+
+public class MBeanSupportImpl implements MBeanSupport, RegistryShutdownListener
+{
+    private Logger logger;
+
+    private MBeanServer server;
+
+    private final Set<ObjectName> registeredBeans = CollectionFactory.newSet();
+
+    public MBeanSupportImpl(Logger logger)
+    {
+        this.logger = logger;
+        
+        // TODO: Agent Id should be configurable
+        final List<MBeanServer> servers = 
MBeanServerFactory.findMBeanServer(null);
+
+        if (servers != null && 0 <  servers.size())
+        {
+            this.server = servers.get(0);
+        }
+
+        if (this.server == null)
+        {
+            this.server = ManagementFactory.getPlatformMBeanServer();
+        }
+    }
+
+    public void register(final Object object, final ObjectName objectName)
+    {
+        try
+        {
+            this.server.registerMBean(object, objectName);
+
+            this.registeredBeans.add(objectName);
+
+            this.logger.info(format("Registered MBean '%s' with server", 
objectName));
+        }
+        catch (final Exception e)
+        {
+            this.logger.error(format("Failed to register MBean '%s' with 
server", objectName), e);
+        }
+    }
+
+    public void unregister(final ObjectName objectName)
+    {
+        if (this.server.isRegistered(objectName))
+        {
+            try
+            {
+                this.server.unregisterMBean(objectName);
+
+                this.logger.info(format("Unegistered MBean '%s' from server", 
objectName));
+            }
+            catch (final Exception e)
+            {
+                this.logger.error(String.format("Failed to unregister MBean 
'%s' from server", objectName), e);
+            }
+        }
+    }
+
+    public void registryDidShutdown()
+    {
+        for (final ObjectName name : this.registeredBeans)
+        {
+            unregister(name);
+        }
+
+        this.registeredBeans.clear();
+
+    }
+}

Propchange: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MBeanSupportImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MBeanSupportImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePoolImpl.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePoolImpl.java?rev=948348&r1=948347&r2=948348&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePoolImpl.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePoolImpl.java
 Wed May 26 07:05:38 2010
@@ -14,6 +14,7 @@
 
 package org.apache.tapestry5.internal.services;
 
+import org.apache.tapestry5.SymbolConstants;
 import org.apache.tapestry5.internal.structure.Page;
 import org.apache.tapestry5.ioc.annotations.IntermediateType;
 import org.apache.tapestry5.ioc.annotations.Symbol;
@@ -47,7 +48,7 @@ import java.util.Map;
  *
  * @see org.apache.tapestry5.internal.services.PagePoolCache
  */
-public class PagePoolImpl implements PagePool, InvalidationListener, 
UpdateListener
+public class PagePoolImpl implements PagePool, InvalidationListener, 
UpdateListener, PagePoolImplMBean
 {
     private final Logger logger;
 
@@ -55,13 +56,13 @@ public class PagePoolImpl implements Pag
 
     private final ThreadLocale threadLocale;
 
-    private final int softLimit;
+    private int softLimit;
 
-    private final long softWait;
+    private long softWait;
 
-    private final int hardLimit;
+    private int hardLimit;
 
-    private final long activeWindow;
+    private long activeWindow;
 
     private final Map<PageLocator, PagePoolCache> pool = 
CollectionFactory.newMap();
 
@@ -71,16 +72,16 @@ public class PagePoolImpl implements Pag
 
                         ThreadLocale threadLocale,
 
-                        @Symbol("tapestry.page-pool.soft-limit")
+                        @Symbol(SymbolConstants.PAGE_POOL_SOFT_LIMIT)
                         int softLimit,
 
-                        @Symbol("tapestry.page-pool.soft-wait") 
@IntermediateType(TimeInterval.class)
+                        @Symbol(SymbolConstants.PAGE_POOL_SOFT_WAIT) 
@IntermediateType(TimeInterval.class)
                         long softWait,
 
-                        @Symbol("tapestry.page-pool.hard-limit")
+                        @Symbol(SymbolConstants.PAGE_POOL_HARD_LIMIT)
                         int hardLimit,
 
-                        @Symbol("tapestry.page-pool.active-window") 
@IntermediateType(TimeInterval.class)
+                        @Symbol(SymbolConstants.PAGE_POOL_ACTIVE_WINDOW) 
@IntermediateType(TimeInterval.class)
                         long activeWindow)
     {
         this.logger = logger;
@@ -165,4 +166,53 @@ public class PagePoolImpl implements Pag
             cache.cleanup();
         }
     }
+
+    public int getSoftLimit()
+    {
+        return softLimit;
+    }
+
+    public void setSoftLimit(int softLimit)
+    {
+        this.softLimit = softLimit;
+        
+        objectWasInvalidated();
+    }
+
+    public long getSoftWait()
+    {
+        return softWait;
+    }
+
+    public void setSoftWait(long softWait)
+    {
+        this.softWait = softWait;
+        
+        objectWasInvalidated();
+    }
+
+    public int getHardLimit()
+    {
+        return hardLimit;
+    }
+
+    public void setHardLimit(int hardLimit)
+    {
+        this.hardLimit = hardLimit;
+        
+        objectWasInvalidated();
+    }
+
+    public long getActiveWindow()
+    {
+        return activeWindow;
+    }
+
+    public void setActiveWindow(long activeWindow)
+    {
+        this.activeWindow = activeWindow;
+        
+        objectWasInvalidated();
+    }
+
 }

Added: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePoolImplMBean.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePoolImplMBean.java?rev=948348&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePoolImplMBean.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePoolImplMBean.java
 Wed May 26 07:05:38 2010
@@ -0,0 +1,78 @@
+// Copyright 2010 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package org.apache.tapestry5.internal.services;
+
+
+
+/**
+ * Exposes page pool settings as managed properties of a MBean.
+ * 
+ * @since 5.2.0
+ */
+public interface PagePoolImplMBean
+{
+    /**
+     * Returns the soft limit.
+     * 
+     * @see org.apache.tapestry5.SymbolConstants#PAGE_POOL_SOFT_LIMIT
+     */
+    int getSoftLimit();
+    
+    /**
+     * Sets the soft limit.
+     */
+    void setSoftLimit(int softLimit);
+    
+    /**
+     * Returns the soft wait.
+     * 
+     * @see org.apache.tapestry5.SymbolConstants#PAGE_POOL_SOFT_WAIT
+     */
+    long getSoftWait();
+    
+    /**
+     * Sets the soft wait.
+     */
+    void setSoftWait(long softWait);
+    
+    /**
+     * Returns the hard limit.
+     * 
+     * @see org.apache.tapestry5.SymbolConstants#PAGE_POOL_HARD_LIMIT
+     * 
+     * @deprecated The hard limit will be removed in a later release of 
Tapestry, as the maximum number of instance
+     *             is easily controlled by limiting the number of request 
handling threads in the servlet container.
+     */
+    int getHardLimit();
+    
+    /**
+     * Sets the hard limit.
+     * 
+     * @deprecated The hard limit will be removed in a later release of 
Tapestry, as the maximum number of instance
+     *             is easily controlled by limiting the number of request 
handling threads in the servlet container.
+     */
+    void setHardLimit(int hardLimit);
+    
+    /**
+     * Returns the active window.
+     * 
+     * @see org.apache.tapestry5.SymbolConstants#PAGE_POOL_ACTIVE_WINDOW
+     */
+    long getActiveWindow();
+    
+    /**
+     * Sets the active window.
+     */
+    void setActiveWindow(long activeWindow);
+}

Propchange: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePoolImplMBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePoolImplMBean.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/RemotePoolManagement.tml
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/RemotePoolManagement.tml?rev=948348&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/RemotePoolManagement.tml 
(added)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/RemotePoolManagement.tml 
Wed May 26 07:05:38 2010
@@ -0,0 +1,7 @@
+<html t:type="Border" 
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>
+
+  <h1>Remote Pool Management Demo</h1>
+  
+  <p>SoftWait: ${softWait}</p>
+
+</html>
\ No newline at end of file

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java?rev=948348&r1=948347&r2=948348&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java
 Wed May 26 07:05:38 2010
@@ -1488,4 +1488,13 @@ public class CoreBehaviorsTests extends 
         assertText("id=no-override", "[pre-app]");
         assertText("id=override", "[app]");
     }
+    
+    /** TAP5-978 */
+    @Test
+    public void remote_pool_management()
+    {
+        clickThru("Remote Pool Management");
+
+        assertTextPresent("SoftWait: 10");
+    }
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java?rev=948348&r1=948347&r2=948348&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
 Wed May 26 07:05:38 2010
@@ -435,7 +435,9 @@ public class Index
                     new Item("unavailablecomponentdemo", "Report Location of 
Unavailable Component",
                             "Report Location of Unavailable Component"),
 
-                    new Item("discardafterdemo", "@DiscardAfter Demo", "Demo 
using @DiscardAfter annotation")
+                    new Item("discardafterdemo", "@DiscardAfter Demo", "Demo 
using @DiscardAfter annotation"),
+                    
+                    new Item("remotepoolmanagement", "Remote Pool Management", 
"Proves that Page Pool MBean is registered")
 
             );
 

Added: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/RemotePoolManagement.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/RemotePoolManagement.java?rev=948348&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/RemotePoolManagement.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/RemotePoolManagement.java
 Wed May 26 07:05:38 2010
@@ -0,0 +1,31 @@
+// Copyright 2010 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package org.apache.tapestry5.integration.app1.pages;
+
+import java.lang.management.ManagementFactory;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+public class RemotePoolManagement
+{
+    
+    public Object getSoftWait() throws Exception
+    {
+        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+        
+        return server.getAttribute(new 
ObjectName("org.apache.tapestry5:type=PagePool"), "SoftWait");
+    }
+
+}

Propchange: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/RemotePoolManagement.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/RemotePoolManagement.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain


Reply via email to