[jboss-svn-commits] JBoss Portal SVN: r5476 - in trunk: common/src/main/org/jboss/portal/common/util common/src/main/org/jboss/portal/test/common core/src/main/org/jboss/portal/core/aspects/controller core/src/main/org/jboss/portal/core/aspects/server core/src/main/org/jboss/portal/core/impl/model/instance core/src/main/org/jboss/portal/core/management core/src/main/org/jboss/portal/core/model/instance core/src/resources/portal-core-sar/META-INF core/src/resources/portal-core-war/WEB-INF/jsp/admin portlet/src/main/org/jboss/portal/portlet/aspects/portlet portlet/src/main/org/jboss/portal/portlet/management
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Oct 18 11:49:20 EDT 2006
Author: thomas.heute at jboss.com
Date: 2006-10-18 11:48:59 -0400 (Wed, 18 Oct 2006)
New Revision: 5476
Added:
trunk/core/src/main/org/jboss/portal/core/impl/model/instance/InstanceContainerListener.java
trunk/core/src/main/org/jboss/portal/core/management/InstanceContainerListenerImpl.java
trunk/core/src/main/org/jboss/portal/core/management/WSRPPortletConsumerManager.java
trunk/core/src/main/org/jboss/portal/core/management/WSRPPortletConsumerManagerMBean.java
trunk/portlet/src/main/org/jboss/portal/portlet/management/PortletContainerRegistry.java
trunk/portlet/src/main/org/jboss/portal/portlet/management/PortletContainerRegistryImpl.java
Modified:
trunk/common/src/main/org/jboss/portal/common/util/LoopCollection.java
trunk/common/src/main/org/jboss/portal/test/common/LoopCollectionTestCase.java
trunk/core/src/main/org/jboss/portal/core/aspects/controller/
trunk/core/src/main/org/jboss/portal/core/aspects/server/
trunk/core/src/main/org/jboss/portal/core/impl/model/instance/PersistentInstanceContainer.java
trunk/core/src/main/org/jboss/portal/core/model/instance/InstanceContainer.java
trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml
trunk/core/src/resources/portal-core-war/WEB-INF/jsp/admin/index.jsp
trunk/portlet/src/main/org/jboss/portal/portlet/aspects/portlet/
trunk/portlet/src/main/org/jboss/portal/portlet/management/PortletContainerManagementInterceptor.java
trunk/portlet/src/main/org/jboss/portal/portlet/management/PortletContainerManagementInterceptorImpl.java
trunk/portlet/src/main/org/jboss/portal/portlet/management/PortletContainerManager.java
Log:
WSRP metrics + refactoring
Modified: trunk/common/src/main/org/jboss/portal/common/util/LoopCollection.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/LoopCollection.java 2006-10-17 23:46:19 UTC (rev 5475)
+++ trunk/common/src/main/org/jboss/portal/common/util/LoopCollection.java 2006-10-18 15:48:59 UTC (rev 5476)
@@ -1,101 +1,89 @@
package org.jboss.portal.common.util;
+import java.util.ArrayList;
+import java.util.List;
+
public class LoopCollection
{
- private long[] array;
+ private List list;
+ private int size;
+
private int index;
public LoopCollection(int size)
{
- array = new long[size];
- emptyArray(array);
- index = 0;
+ this.list = new ArrayList(size);
+ this.size = size;
+ this.index = -1;
}
- public void put(long value)
+ public void put(Object value)
{
- array[index] = value;
index++;
- if (index == array.length)
+ if (index == size)
{
index = 0;
}
+ if (list.size() < size)
+ {
+ list.add(value);
+ }
+ else
+ {
+ list.set(index, value);
+ }
}
public void setSize(int newSize)
{
- long[] newArray = new long[newSize];
- emptyArray(newArray);
- for (int i = 0; i < Math.min(newArray.length, array.length); i++)
+
+
+ if (newSize <= size)
{
- int cursor = index - 1 - i;
- if (cursor < 0)
+ List newList = new ArrayList(newSize);
+ for (int i = 0; i < newSize; i++)
{
- cursor += array.length;
+ int cursor = index + 1 - newSize + i;
+ if (cursor < 0) cursor += size;
+ newList.add(list.get(cursor));
}
- int newCursor = newArray.length - 1 - i;
- if (newCursor < 0)
- {
- break;
- }
- if (array[cursor] != -1)
- {
- newArray[newCursor] = array[cursor];
- }
+ this.list = newList;
+ this.index = newSize - 1;
}
- array = newArray;
- index = 0;
+ this.size = newSize;
}
-
- public float getAverage()
+
+ public int getSize()
{
- float sum = 0;
- int nb = 0;
- for (int i = 0; i < array.length; i++)
- {
- if (array[i] != -1)
- {
- sum += array[i];
- nb++;
- }
- }
- // Division by 0
- return sum / nb;
+ return list.size();
}
-
- public long getMax()
+
+ /**
+ * Return elements from oldest to nexest
+ * @param i
+ * @return
+ */
+ public Object get(int i)
{
- long max = -1;
- for (int i = 0; i < array.length; i++)
+ if (i > list.size() || i < 0)
{
- if (array[i] > max)
- {
- max = array[i];
- }
+ throw new IndexOutOfBoundsException();
}
- return max;
- }
-
- public long getMin()
- {
- long min = Long.MAX_VALUE;
- for (int i = 0; i < array.length; i++)
+ else
{
- if ((array[i] != -1) && (array[i] < min))
+ if (list.size() < size)
{
- min = array[i];
+ return list.get(i);
}
+ else
+ {
+ int cursor = index + 1 - size + i;
+ if (cursor < 0) cursor += size;
+ return list.get(cursor);
+ }
+
}
- return min;
}
- private void emptyArray(long[] array)
- {
- for (int i = 0; i < array.length; i++)
- {
- array[i] = -1;
- }
- }
-
}
Modified: trunk/common/src/main/org/jboss/portal/test/common/LoopCollectionTestCase.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/LoopCollectionTestCase.java 2006-10-17 23:46:19 UTC (rev 5475)
+++ trunk/common/src/main/org/jboss/portal/test/common/LoopCollectionTestCase.java 2006-10-18 15:48:59 UTC (rev 5476)
@@ -11,33 +11,59 @@
LoopCollection loop = new LoopCollection(6);
- loop.put(1);
- loop.put(2);
- loop.put(3);
- assertTrue(loop.getAverage() == 2);
- loop.put(4);
- loop.put(5);
- assertTrue(loop.getAverage() == 3);
- loop.put(6);
- loop.put(7);
- loop.put(8);
- loop.put(0);
- assertTrue(loop.getAverage() == 5);
-
+ loop.put("a");
+ loop.put("b");
+ loop.put("c");
+ assertTrue(loop.get(0).equals("a"));
+ assertTrue(loop.get(1).equals("b"));
+ assertTrue(loop.get(2).equals("c"));
+ loop.put("d");
+ loop.put("e");
+ assertTrue(loop.get(0).equals("a"));
+ assertTrue(loop.get(1).equals("b"));
+ assertTrue(loop.get(2).equals("c"));
+ assertTrue(loop.get(3).equals("d"));
+ assertTrue(loop.get(4).equals("e"));
+ loop.put("f");
+ loop.put("g");
+ loop.put("h");
+ loop.put("i");
+ assertTrue(loop.get(0).equals("d"));
+ assertTrue(loop.get(1).equals("e"));
+ assertTrue(loop.get(2).equals("f"));
+ assertTrue(loop.get(3).equals("g"));
+ assertTrue(loop.get(4).equals("h"));
+ assertTrue(loop.get(5).equals("i"));
loop.setSize(4);
- assertTrue(loop.getAverage() == 5.25);
+ assertTrue(loop.get(0).equals("f"));
+ assertTrue(loop.get(1).equals("g"));
+ assertTrue(loop.get(2).equals("h"));
+ assertTrue(loop.get(3).equals("i"));
loop.setSize(2);
- assertTrue(loop.getAverage() == 4);
+ assertTrue(loop.get(0).equals("h"));
+ assertTrue(loop.get(1).equals("i"));
loop.setSize(5);
- loop.put(2);
- loop.put(7);
- loop.put(3);
- assertTrue(loop.getAverage() == 4);
+ loop.put("k");
+ loop.put("l");
+ loop.put("m");
+ assertTrue(loop.get(0).equals("h"));
+ assertTrue(loop.get(1).equals("i"));
+ assertTrue(loop.get(2).equals("k"));
+ assertTrue(loop.get(3).equals("l"));
+ assertTrue(loop.get(4).equals("m"));
loop.setSize(10);
- loop.put(4);
- assertTrue(loop.getAverage() == 4);
+ loop.put("n");
+ assertTrue(loop.get(0).equals("h"));
+ assertTrue(loop.get(1).equals("i"));
+ assertTrue(loop.get(2).equals("k"));
+ assertTrue(loop.get(3).equals("l"));
+ assertTrue(loop.get(4).equals("m"));
+ assertTrue(loop.get(5).equals("n"));
loop.setSize(4);
- assertTrue(loop.getAverage() == 4);
+ assertTrue(loop.get(0).equals("k"));
+ assertTrue(loop.get(1).equals("l"));
+ assertTrue(loop.get(2).equals("m"));
+ assertTrue(loop.get(3).equals("n"));
Property changes on: trunk/core/src/main/org/jboss/portal/core/aspects/controller
___________________________________________________________________
Name: svn:ignore
+ CommandLogInterceptor.java
Property changes on: trunk/core/src/main/org/jboss/portal/core/aspects/server
___________________________________________________________________
Name: svn:ignore
+ ServerLogInterceptor.java
Added: trunk/core/src/main/org/jboss/portal/core/impl/model/instance/InstanceContainerListener.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/model/instance/InstanceContainerListener.java 2006-10-17 23:46:19 UTC (rev 5475)
+++ trunk/core/src/main/org/jboss/portal/core/impl/model/instance/InstanceContainerListener.java 2006-10-18 15:48:59 UTC (rev 5476)
@@ -0,0 +1,10 @@
+package org.jboss.portal.core.impl.model.instance;
+
+public interface InstanceContainerListener
+{
+
+ void portletInstanceCreated(InstanceDefinitionImpl instance);
+
+ void portletInstanceDestroyed(InstanceDefinitionImpl instance);
+
+}
Modified: trunk/core/src/main/org/jboss/portal/core/impl/model/instance/PersistentInstanceContainer.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/model/instance/PersistentInstanceContainer.java 2006-10-17 23:46:19 UTC (rev 5475)
+++ trunk/core/src/main/org/jboss/portal/core/impl/model/instance/PersistentInstanceContainer.java 2006-10-18 15:48:59 UTC (rev 5476)
@@ -77,6 +77,8 @@
PermissionRepository, PermissionFactory
{
+ private List listeners = new ArrayList();
+
/** . */
protected InterceptorStackFactory stackFactory;
@@ -278,6 +280,8 @@
session.update(instance);
}
+ raiseCreatedPortletInstanceEvent(instance);
+
//
return instance;
}
@@ -370,11 +374,35 @@
// Delete instance
removeBindings(session, instance);
session.delete(instance);
-
+
//
session.flush();
+
+ raiseDestroyedPortletInstanceEvent(instance);
}
+ private void raiseCreatedPortletInstanceEvent(InstanceDefinitionImpl instance)
+ {
+ Iterator it = listeners.iterator();
+ while (it.hasNext())
+ {
+ InstanceContainerListener listener = (InstanceContainerListener)it.next();
+ listener.portletInstanceCreated(instance);
+ }
+ }
+
+ private void raiseDestroyedPortletInstanceEvent(InstanceDefinitionImpl instance)
+ {
+ Iterator it = listeners.iterator();
+ while (it.hasNext())
+ {
+ InstanceContainerListener listener = (InstanceContainerListener)it.next();
+ listener.portletInstanceDestroyed(instance);
+ }
+ }
+
+
+
public Collection getInstances()
{
Session session = ctx.getCurrentSession();
@@ -567,7 +595,17 @@
{
return this;
}
+
+ public void addListener(InstanceContainerListener listener)
+ {
+ listeners.add(listener);
+ }
+ public void removeListener(InstanceContainerListener listener)
+ {
+ listeners.remove(listener);
+ }
+
private void removeBindings(Session session, InstanceDefinitionImpl instance)
{
if (instance.getSecurityBindings() != null)
Added: trunk/core/src/main/org/jboss/portal/core/management/InstanceContainerListenerImpl.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/management/InstanceContainerListenerImpl.java 2006-10-17 23:46:19 UTC (rev 5475)
+++ trunk/core/src/main/org/jboss/portal/core/management/InstanceContainerListenerImpl.java 2006-10-18 15:48:59 UTC (rev 5476)
@@ -0,0 +1,178 @@
+/******************************************************************************
+ * 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.management;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.management.ObjectName;
+
+import org.jboss.portal.core.impl.model.instance.InstanceContainerListener;
+import org.jboss.portal.core.impl.model.instance.InstanceDefinitionImpl;
+import org.jboss.portal.core.model.instance.InstanceContainer;
+import org.jboss.portal.portlet.management.PortletContainerManagementInterceptor;
+import org.jboss.system.ServiceMBeanSupport;
+
+/**
+ * Used for WSRP portlets
+ *
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class InstanceContainerListenerImpl extends ServiceMBeanSupport implements InstanceContainerListener
+{
+ public static final String JMX_PREFIX = "portal:service=Management,type=WSRPPorletConsumer,name=";
+
+ private InstanceContainer instanceContainer;
+
+ private PortletContainerManagementInterceptor interceptor;
+
+ private List portlets = new ArrayList();
+
+ public void create()
+ {
+ instanceContainer.addListener(this);
+ }
+
+ public void destroy()
+ {
+ instanceContainer.removeListener(this);
+ }
+
+ public void start()
+ {
+ Collection startedPortletInstances = instanceContainer.getInstances();
+ Iterator it = startedPortletInstances.iterator();
+ while (it.hasNext())
+ {
+ InstanceDefinitionImpl portlet = (InstanceDefinitionImpl)it.next();
+ String portletRef = portlet.getPortletRef();
+ registerWSRPPortlet(portletRef, portlet);
+ }
+ }
+
+
+
+ public void stop()
+ {
+ /*
+ Iterator it = portletContainers.iterator();
+ while (it.hasNext())
+ {
+ Instance portlet = (Instance)it.next();
+ unregisterPortlet(portlet.getPortlet());
+ }
+ if (portletContainers.size() != 0)
+ {
+ log.error("Unable to remove all the PortletContainer manager MBeans");
+ }
+ */
+ }
+
+ public void portletInstanceCreated(InstanceDefinitionImpl portlet)
+ {
+ /*
+ log.debug("Registering Management MBean: " + portlet.getId());
+ try
+ {
+ createPortletContainerManagemenentMBean(portlet);
+ portletContainers.add(portlet);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ */
+ }
+
+ private void registerWSRPPortlet(String portletRef, InstanceDefinitionImpl portlet)
+ {
+ String prefix = portletRef.substring(0, portletRef.indexOf("."));
+ if (!prefix.equals("local") && !portlets.contains(portletRef))
+ {
+ try
+ {
+ createWSRPPortletConsumerManagemenentMBean(portletRef);
+ portlets.add(portletRef);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+/*
+ private void unregisterPortletContainer(Portlet portlet)
+ {
+
+ }
+*/
+ public void portletInstanceDestroyed(InstanceDefinitionImpl portlet)
+ {
+ /*
+ log.debug("Unregistering Management MBean: " + portlet.getId());
+ try
+ {
+ destroyPortletContainerManagemenentMBean(portlet);
+ portletContainers.remove(portlet);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ */
+ }
+
+ public void setInstanceContainer(InstanceContainer instanceContainer)
+ {
+ this.instanceContainer = instanceContainer;
+ }
+
+ public void setInterceptor(PortletContainerManagementInterceptor interceptor)
+ {
+ this.interceptor = interceptor;
+ }
+
+ private void createWSRPPortletConsumerManagemenentMBean(String portletRef) throws Exception
+ {
+ WSRPPortletConsumerManager manager = new WSRPPortletConsumerManager(portletRef, interceptor);
+ ObjectName objectName = new ObjectName(getMBeanName(portletRef));
+ getServer().registerMBean(manager, objectName);
+ }
+
+ /*
+ private void destroyPortletContainerManagemenentMBean(PortletContainer portlet) throws Exception
+ {
+ ObjectName objectName = new ObjectName(getMBeanName(portlet));
+ getServer().unregisterMBean(objectName);
+ }
+ */
+
+ private String getMBeanName(String portletRef)
+ {
+ return JMX_PREFIX + portletRef;
+ }
+
+}
Added: trunk/core/src/main/org/jboss/portal/core/management/WSRPPortletConsumerManager.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/management/WSRPPortletConsumerManager.java 2006-10-17 23:46:19 UTC (rev 5475)
+++ trunk/core/src/main/org/jboss/portal/core/management/WSRPPortletConsumerManager.java 2006-10-18 15:48:59 UTC (rev 5476)
@@ -0,0 +1,94 @@
+/******************************************************************************
+ * 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.management;
+
+import org.jboss.portal.portlet.management.PortletContainerManagementInterceptor;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class WSRPPortletConsumerManager implements WSRPPortletConsumerManagerMBean
+{
+ private String portletRef;
+
+ private PortletContainerManagementInterceptor interceptor;
+
+ public WSRPPortletConsumerManager(String portletRef, PortletContainerManagementInterceptor interceptor)
+ {
+ this.portletRef = portletRef;
+ this.interceptor = interceptor;
+ }
+
+ public String getId()
+ {
+ return portletRef;
+ }
+
+ public float getAverageRenderTime()
+ {
+ Float time = interceptor.getAverageRenderTime(getId());
+ return time.floatValue();
+ }
+
+ public float getAverageActionTime()
+ {
+ Float time = interceptor.getAverageActionTime(getId());
+ return time.floatValue();
+ }
+
+ public long getMaxRenderTime()
+ {
+ Long time = interceptor.getMaxRenderTime(getId());
+ return time.longValue();
+ }
+
+ public long getMaxActionTime()
+ {
+ Long time = interceptor.getMaxActionTime(getId());
+ return time.longValue();
+ }
+
+ public long getMinRenderTime()
+ {
+ Long time = interceptor.getMinRenderTime(getId());
+ return time.longValue();
+ }
+
+ public long getMinActionTime()
+ {
+ Long time = interceptor.getMinActionTime(getId());
+ return time.longValue();
+ }
+
+ public long getNbRenderCalls()
+ {
+ return interceptor.getNbRenderCalls(getId());
+ }
+
+ public long getNbActionCalls()
+ {
+ return interceptor.getNbActionCalls(getId());
+ }
+
+}
Added: trunk/core/src/main/org/jboss/portal/core/management/WSRPPortletConsumerManagerMBean.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/management/WSRPPortletConsumerManagerMBean.java 2006-10-17 23:46:19 UTC (rev 5475)
+++ trunk/core/src/main/org/jboss/portal/core/management/WSRPPortletConsumerManagerMBean.java 2006-10-18 15:48:59 UTC (rev 5476)
@@ -0,0 +1,48 @@
+/******************************************************************************
+ * 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.management;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public interface WSRPPortletConsumerManagerMBean
+{
+ // public String getName();
+
+ public float getAverageRenderTime();
+
+ public float getAverageActionTime();
+
+ public long getMaxRenderTime();
+
+ public long getMaxActionTime();
+
+ public long getMinRenderTime();
+
+ public long getMinActionTime();
+
+ public long getNbRenderCalls();
+
+ public long getNbActionCalls();
+}
Modified: trunk/core/src/main/org/jboss/portal/core/model/instance/InstanceContainer.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/model/instance/InstanceContainer.java 2006-10-17 23:46:19 UTC (rev 5475)
+++ trunk/core/src/main/org/jboss/portal/core/model/instance/InstanceContainer.java 2006-10-18 15:48:59 UTC (rev 5476)
@@ -22,6 +22,7 @@
******************************************************************************/
package org.jboss.portal.core.model.instance;
+import org.jboss.portal.core.impl.model.instance.InstanceContainerListener;
import org.jboss.portal.portlet.PortletInvoker;
import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.security.spi.provider.AuthorizationDomain;
@@ -96,4 +97,8 @@
* @return the authorization domain
*/
AuthorizationDomain getAuthorizationDomain();
+
+ void addListener(InstanceContainerListener listener);
+
+ void removeListener(InstanceContainerListener listener);
}
Modified: trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml
===================================================================
--- trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml 2006-10-17 23:46:19 UTC (rev 5475)
+++ trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml 2006-10-18 15:48:59 UTC (rev 5476)
@@ -23,7 +23,47 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
<server>
-
+ <!-- Management MBean -->
+ <mbean
+ code="org.jboss.portal.core.management.PortalImpl"
+ name="portal:service=Management,type=Portal,name=Default"
+ xmbean-dd=""
+ xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
+ <depends
+ optional-attribute-name="InstanceContainer"
+ proxy-type="attribute">portal:container=Instance</depends>
+ <xmbean/>
+ </mbean>
+
+ <mbean
+ code="org.jboss.portal.management.PortletContainerRegistryImpl"
+ name="portal:service=Management,type=PortletContainerRegistry,name=Default"
+ xmbean-dd=""
+ xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
+ <depends
+ optional-attribute-name="Registry"
+ proxy-type="attribute">portal:service=WebAppRegistry</depends>
+ <xmbean/>
+ <depends
+ optional-attribute-name="Interceptor"
+ proxy-type="attribute">portal:service=ManagementInterceptor,type=Portlet,name=PortletContainer</depends>
+ <xmbean/>
+ </mbean>
+
+ <mbean
+ code="org.jboss.portal.core.management.InstanceContainerListenerImpl"
+ name="portal:service=Management,type=InstanceContainer,name=Default"
+ xmbean-dd=""
+ xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
+ <depends
+ optional-attribute-name="InstanceContainer"
+ proxy-type="attribute">portal:container=Instance</depends>
+ <xmbean/>
+ <depends
+ optional-attribute-name="Interceptor"
+ proxy-type="attribute">portal:service=ManagementInterceptor,type=Portlet,name=PortletContainer</depends>
+ <xmbean/>
+ </mbean>
<!-- Server configuration service -->
<mbean
code="org.jboss.portal.server.config.ServerConfigService"
Modified: trunk/core/src/resources/portal-core-war/WEB-INF/jsp/admin/index.jsp
===================================================================
--- trunk/core/src/resources/portal-core-war/WEB-INF/jsp/admin/index.jsp 2006-10-17 23:46:19 UTC (rev 5475)
+++ trunk/core/src/resources/portal-core-war/WEB-INF/jsp/admin/index.jsp 2006-10-18 15:48:59 UTC (rev 5476)
@@ -25,7 +25,8 @@
<form method="post" action="<portlet:renderURL/>"/>
<select name="application" class="inputbox" size="1">
<option value=""></option>
-<% for (Iterator i = container.getApplications().iterator();i.hasNext();)
+<%
+ for (Iterator i = container.getApplications().iterator();i.hasNext();)
{
Application app = (Application)i.next();
String appName = app.getName();
@@ -35,9 +36,9 @@
targetApp = app;
}
%>
- <option value="<%= appName %>" <%= selected ? " selected=\"selected\"" : "" %>><%= appName %></option>
+ <option value="<%= appName %>" <%= selected ? " selected=\"selected\"" : "" %>><%=appName%></option>
<%
- }
+}
%>
</select>
<input type="submit" value="infos"/>
@@ -71,18 +72,18 @@
<a href="<portlet:renderURL>
<portlet:param name="application" value="<%= targetApp.getName() %>"/>
<portlet:param name="component" value="<%= comp.getName() %>"/>
- </portlet:renderURL>"><%= comp.getName() %>
+ </portlet:renderURL>"><%=comp.getName()%>
</a>
</td>
<td>
- <%= expirationCache != null ? expirationCache.toString() : "-" %>
+ <%=expirationCache != null ? expirationCache.toString() : "-"%>
</td>
<td>
<input type="submit" name="<%= comp.getName() %>" value="create"/>
</td>
</tr>
<%
- }
+}
%>
<tr>
<td colspan="3">
@@ -99,9 +100,9 @@
{
Portal portal = (Portal)j.next();
%>
- <option name="<%= portal.getName() %>"><%= portal.getName() %></option>
+ <option name="<%= portal.getName() %>"><%=portal.getName()%></option>
<%
- }
+}
%>
</select>
</td>
@@ -109,7 +110,7 @@
</table>
</form>
<%
- }
+}
%>
<hr height="1"/>
@@ -122,7 +123,8 @@
<th>portal</th>
<th>action</th>
</tr>
-<% for (Iterator i = container.getPortals().iterator();i.hasNext();)
+<%
+ for (Iterator i = container.getPortals().iterator();i.hasNext();)
{
Portal portal = (Portal)i.next();
String portalName = portal.getName();
Property changes on: trunk/portlet/src/main/org/jboss/portal/portlet/aspects/portlet
___________________________________________________________________
Name: svn:ignore
+ InstanceLogInterceptor.java
PortletLogInterceptor.java
Modified: trunk/portlet/src/main/org/jboss/portal/portlet/management/PortletContainerManagementInterceptor.java
===================================================================
--- trunk/portlet/src/main/org/jboss/portal/portlet/management/PortletContainerManagementInterceptor.java 2006-10-17 23:46:19 UTC (rev 5475)
+++ trunk/portlet/src/main/org/jboss/portal/portlet/management/PortletContainerManagementInterceptor.java 2006-10-18 15:48:59 UTC (rev 5476)
@@ -28,17 +28,17 @@
*/
public interface PortletContainerManagementInterceptor
{
- public float getLocalAverageRenderTime(String portletId);
+ public Float getAverageRenderTime(String portletId);
- public float getLocalAverageActionTime(String portletId);
+ public Float getAverageActionTime(String portletId);
- public long getLocalMaxRenderTime(String portletId);
+ public Long getMaxRenderTime(String portletId);
- public long getLocalMaxActionTime(String portletId);
+ public Long getMaxActionTime(String portletId);
- public long getLocalMinRenderTime(String portletId);
+ public Long getMinRenderTime(String portletId);
- public long getLocalMinActionTime(String portletId);
+ public Long getMinActionTime(String portletId);
public long getNbRenderCalls(String portletId);
Modified: trunk/portlet/src/main/org/jboss/portal/portlet/management/PortletContainerManagementInterceptorImpl.java
===================================================================
--- trunk/portlet/src/main/org/jboss/portal/portlet/management/PortletContainerManagementInterceptorImpl.java 2006-10-17 23:46:19 UTC (rev 5475)
+++ trunk/portlet/src/main/org/jboss/portal/portlet/management/PortletContainerManagementInterceptorImpl.java 2006-10-18 15:48:59 UTC (rev 5476)
@@ -48,8 +48,6 @@
private int sampleSize = 10;
private Map map = new HashMap();
-// private Map localRenderMap = new HashMap();
-// private Map localActionMap = new HashMap();
protected Object invoke(PortletInvocation invocation) throws Exception, InvocationException
{
@@ -61,24 +59,15 @@
System.out.println(invocation);
if (invocation instanceof RenderInvocation)
{
- if (portletName.startsWith("local."))
- {
- String key = portletName.substring("local.".length());
- Value value = getValue(key);
- value.renderTimes.put(done.getTime() - start.getTime());
- value.nbRenderCalls++;
- }
- // TODO: Add WSRP
+ Value value = getValue(portletName);
+ value.renderTimes.put(new Long(done.getTime() - start.getTime()));
+ value.nbRenderCalls++;
}
else if (invocation instanceof ActionInvocation)
{
- if (portletName.startsWith("local."))
- {
- String key = portletName.substring("local.".length());
- Value value = getValue(key);
- value.actionTimes.put(done.getTime() - start.getTime());
- value.nbActionCalls++;
- }
+ Value value = getValue(portletName);
+ value.actionTimes.put(new Long(done.getTime() - start.getTime()));
+ value.nbActionCalls++;
}
return object;
}
@@ -94,40 +83,40 @@
return value;
}
- public float getLocalAverageRenderTime(String portletId)
+ public Float getAverageRenderTime(String portletId)
{
Value value = (Value)map.get(portletId);
- return value.renderTimes.getAverage();
+ return getAverage(value.renderTimes);
}
- public float getLocalAverageActionTime(String portletId)
+ public Float getAverageActionTime(String portletId)
{
Value value = (Value)map.get(portletId);
- return value.actionTimes.getAverage();
+ return getAverage(value.actionTimes);
}
- public long getLocalMaxRenderTime(String portletId)
+ public Long getMaxRenderTime(String portletId)
{
Value value = (Value)map.get(portletId);
- return value.renderTimes.getMax();
+ return getMax(value.renderTimes);
}
- public long getLocalMaxActionTime(String portletId)
+ public Long getMaxActionTime(String portletId)
{
Value value = (Value)map.get(portletId);
- return value.actionTimes.getMax();
+ return getMax(value.actionTimes);
}
- public long getLocalMinRenderTime(String portletId)
+ public Long getMinRenderTime(String portletId)
{
Value value = (Value)map.get(portletId);
- return value.renderTimes.getMin();
+ return getMin(value.renderTimes);
}
- public long getLocalMinActionTime(String portletId)
+ public Long getMinActionTime(String portletId)
{
Value value = (Value)map.get(portletId);
- return value.actionTimes.getMin();
+ return getMin(value.actionTimes);
}
public long getNbRenderCalls(String portletId)
@@ -178,4 +167,47 @@
}
+ private Float getAverage(LoopCollection loop)
+ {
+ if (loop.getSize() == 0)
+ {
+ return null;
+ }
+
+ float sum = 0;
+ for (int i = 0; i < loop.getSize(); i++)
+ {
+ sum += ((Long)loop.get(i)).longValue();
+ }
+ return new Float(sum / loop.getSize());
+ }
+
+ public Long getMax(LoopCollection loop)
+ {
+ long max = -1;
+ for (int i = 0; i < loop.getSize(); i++)
+ {
+ if (((Long)loop.get(i)).longValue() > max)
+ {
+ max = ((Long)loop.get(i)).longValue();
+ }
+ }
+ if (max == -1) return null;
+ return new Long(max);
+ }
+
+ public Long getMin(LoopCollection loop)
+ {
+ long min = Long.MAX_VALUE;
+ for (int i = 0; i < loop.getSize(); i++)
+ {
+ if (((Long)loop.get(i)).longValue() < min)
+ {
+ min = ((Long)loop.get(i)).longValue();
+ }
+ }
+ if (min == Long.MAX_VALUE) return null;
+ return new Long(min);
+ }
+
}
Modified: trunk/portlet/src/main/org/jboss/portal/portlet/management/PortletContainerManager.java
===================================================================
--- trunk/portlet/src/main/org/jboss/portal/portlet/management/PortletContainerManager.java 2006-10-17 23:46:19 UTC (rev 5475)
+++ trunk/portlet/src/main/org/jboss/portal/portlet/management/PortletContainerManager.java 2006-10-18 15:48:59 UTC (rev 5476)
@@ -47,37 +47,43 @@
public String getId()
{
- return portlet.getContext().getId();
+ return "local." + portlet.getContext().getId();
}
public float getAverageRenderTime()
{
- return interceptor.getLocalAverageRenderTime(getId());
+ Float time = interceptor.getAverageRenderTime(getId());
+ return time.floatValue();
}
public float getAverageActionTime()
{
- return interceptor.getLocalAverageActionTime(getId());
+ Float time = interceptor.getAverageActionTime(getId());
+ return time.floatValue();
}
public long getMaxRenderTime()
{
- return interceptor.getLocalMaxRenderTime(getId());
+ Long time = interceptor.getMaxRenderTime(getId());
+ return time.longValue();
}
public long getMaxActionTime()
{
- return interceptor.getLocalMaxActionTime(getId());
+ Long time = interceptor.getMaxActionTime(getId());
+ return time.longValue();
}
public long getMinRenderTime()
{
- return interceptor.getLocalMinRenderTime(getId());
+ Long time = interceptor.getMinRenderTime(getId());
+ return time.longValue();
}
public long getMinActionTime()
{
- return interceptor.getLocalMinActionTime(getId());
+ Long time = interceptor.getMinActionTime(getId());
+ return time.longValue();
}
public long getNbRenderCalls()
Added: trunk/portlet/src/main/org/jboss/portal/portlet/management/PortletContainerRegistry.java
===================================================================
--- trunk/portlet/src/main/org/jboss/portal/portlet/management/PortletContainerRegistry.java 2006-10-17 23:46:19 UTC (rev 5475)
+++ trunk/portlet/src/main/org/jboss/portal/portlet/management/PortletContainerRegistry.java 2006-10-18 15:48:59 UTC (rev 5476)
@@ -0,0 +1,32 @@
+/******************************************************************************
+ * 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.management;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public interface PortletContainerRegistry
+{
+
+}
Added: trunk/portlet/src/main/org/jboss/portal/portlet/management/PortletContainerRegistryImpl.java
===================================================================
--- trunk/portlet/src/main/org/jboss/portal/portlet/management/PortletContainerRegistryImpl.java 2006-10-17 23:46:19 UTC (rev 5475)
+++ trunk/portlet/src/main/org/jboss/portal/portlet/management/PortletContainerRegistryImpl.java 2006-10-18 15:48:59 UTC (rev 5476)
@@ -0,0 +1,146 @@
+/******************************************************************************
+ * 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.management;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.management.ObjectName;
+
+import org.jboss.logging.Logger;
+import org.jboss.portal.portlet.container.PortletApplicationRegistry;
+import org.jboss.portal.portlet.container.PortletContainer;
+import org.jboss.portal.portlet.management.PortletContainerManagementInterceptor;
+import org.jboss.portal.portlet.management.PortletContainerManager;
+import org.jboss.system.ServiceMBeanSupport;
+
+/**
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class PortletContainerRegistryImpl extends ServiceMBeanSupport implements PortletContainerRegistry, org.jboss.portal.portlet.container.PortletContainerRegistryListener
+{
+ private final static Logger log = Logger.getLogger(PortletContainerRegistryImpl.class);
+
+ public static final String JMX_PREFIX = "portal:service=Management,type=PortletContainer,name=";
+
+ private PortletApplicationRegistry registry;
+
+ private PortletContainerManagementInterceptor interceptor;
+
+ private List portletContainers = new ArrayList();
+
+ public void create()
+ {
+ registry.addListener(this);
+ }
+
+ public void destroy()
+ {
+ registry.removeListener(this);
+ }
+
+ public void start()
+ {
+ Collection startedPortletContainers = registry.getPortletContainers();
+ Iterator it = startedPortletContainers.iterator();
+ while (it.hasNext())
+ {
+ PortletContainer portlet = (PortletContainer)it.next();
+ registerPortletContainer(portlet);
+ }
+ }
+
+ public void stop()
+ {
+ Iterator it = portletContainers.iterator();
+ while (it.hasNext())
+ {
+ PortletContainer portlet = (PortletContainer)it.next();
+ unregisterPortletContainer(portlet);
+ }
+ if (portletContainers.size() != 0)
+ {
+ log.error("Unable to remove all the PortletContainer manager MBeans");
+ }
+ }
+
+ public void registerPortletContainer(PortletContainer portlet)
+ {
+ log.debug("Registering Management MBean: " + portlet.getContext().getId());
+ try
+ {
+ createPortletContainerManagemenentMBean(portlet);
+ portletContainers.add(portlet);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void unregisterPortletContainer(PortletContainer portlet)
+ {
+ log.debug("Unregistering Management MBean: " + portlet.getContext().getId());
+ try
+ {
+ destroyPortletContainerManagemenentMBean(portlet);
+ portletContainers.remove(portlet);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void setRegistry(PortletApplicationRegistry registry)
+ {
+ this.registry = registry;
+ }
+
+ public void setInterceptor(PortletContainerManagementInterceptor interceptor)
+ {
+ this.interceptor = interceptor;
+ }
+
+ private void createPortletContainerManagemenentMBean(PortletContainer portlet) throws Exception
+ {
+ PortletContainerManager manager = new PortletContainerManager(portlet, interceptor);
+ ObjectName objectName = new ObjectName(getMBeanName(portlet));
+ getServer().registerMBean(manager, objectName);
+ }
+
+ private void destroyPortletContainerManagemenentMBean(PortletContainer portlet) throws Exception
+ {
+ ObjectName objectName = new ObjectName(getMBeanName(portlet));
+ getServer().unregisterMBean(objectName);
+ }
+
+ private String getMBeanName(PortletContainer portlet)
+ {
+ return JMX_PREFIX + "local." + portlet.getContext().getId();
+ }
+
+}
More information about the jboss-svn-commits
mailing list