Author: julien_viet
Date: 2009-11-18 18:39:15 -0500 (Wed, 18 Nov 2009)
New Revision: 655
Modified:
portal/trunk/component/application-registry/src/main/java/org/exoplatform/application/registry/mop/MOPApplicationRegistryService.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/ApplicationStatistic.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/ApplicationStatisticService.java
Log:
improve the application statistic service making it not rely on the application registry
Modified:
portal/trunk/component/application-registry/src/main/java/org/exoplatform/application/registry/mop/MOPApplicationRegistryService.java
===================================================================
---
portal/trunk/component/application-registry/src/main/java/org/exoplatform/application/registry/mop/MOPApplicationRegistryService.java 2009-11-18
23:03:17 UTC (rev 654)
+++
portal/trunk/component/application-registry/src/main/java/org/exoplatform/application/registry/mop/MOPApplicationRegistryService.java 2009-11-18
23:39:15 UTC (rev 655)
@@ -29,6 +29,7 @@
import org.exoplatform.portal.config.model.ApplicationType;
import org.exoplatform.portal.pom.config.POMSession;
import org.exoplatform.portal.pom.config.POMSessionManager;
+import org.exoplatform.portal.pom.config.POMTask;
import org.exoplatform.portal.pom.registry.CategoryDefinition;
import org.exoplatform.portal.pom.registry.ContentDefinition;
import org.exoplatform.portal.pom.registry.ContentRegistry;
@@ -48,8 +49,13 @@
import java.util.Comparator;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
/**
+ * The fundamental reason that motives to use tasks is because of the JMX access that
does not
+ * setup a context and therefore the task either reuse the existing context setup by the
portal
+ * or create a temporary context when accessed by JMX.
+ *
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
* @version $Revision$
*/
@@ -83,27 +89,34 @@
}
public List<ApplicationCategory> getApplicationCategories(
- Comparator<ApplicationCategory> sortComparator,
+ final Comparator<ApplicationCategory> sortComparator,
String accessUser,
- ApplicationType<?>... appTypes) throws Exception
+ final ApplicationType<?>... appTypes) throws Exception
{
- POMSession session = POMSessionManager.getSession();
- ContentRegistry registry = session.getContentRegistry();
+ final List<ApplicationCategory> categories = new
ArrayList<ApplicationCategory>();
//
- List<ApplicationCategory> categories = new
ArrayList<ApplicationCategory>();
- for (CategoryDefinition categoryDef : registry.getCategoryList())
+ pomMGr.execute(new POMTask()
{
- ApplicationCategory category = load(categoryDef, appTypes);
- categories.add(category);
- }
+ public void run(POMSession session) throws Exception
+ {
+ ContentRegistry registry = session.getContentRegistry();
- //
- if (sortComparator != null)
- {
- Collections.sort(categories, sortComparator);
- }
+ //
+ for (CategoryDefinition categoryDef : registry.getCategoryList())
+ {
+ ApplicationCategory category = load(categoryDef, appTypes);
+ categories.add(category);
+ }
+ //
+ if (sortComparator != null)
+ {
+ Collections.sort(categories, sortComparator);
+ }
+ }
+ });
+
//
return categories;
}
@@ -123,53 +136,69 @@
return getApplicationCategories(sortComparator, null);
}
- public ApplicationCategory getApplicationCategory(String name) throws Exception
+ public ApplicationCategory getApplicationCategory(final String name) throws Exception
{
- POMSession session = POMSessionManager.getSession();
- ContentRegistry registry = session.getContentRegistry();
+ final AtomicReference<ApplicationCategory> a = new
AtomicReference<ApplicationCategory>();
//
- CategoryDefinition categoryDef = registry.getCategory(name);
- if (categoryDef != null)
+ pomMGr.execute(new POMTask()
{
- return load(categoryDef);
- }
- else
- {
- return null;
- }
- }
+ public void run(POMSession session) throws Exception
+ {
+ ContentRegistry registry = session.getContentRegistry();
- public void save(ApplicationCategory category) throws Exception
- {
- POMSession session = POMSessionManager.getSession();
- ContentRegistry registry = session.getContentRegistry();
+ //
+ CategoryDefinition categoryDef = registry.getCategory(name);
+ if (categoryDef != null)
+ {
+ ApplicationCategory applicationCategory = load(categoryDef);
+ a.set(applicationCategory);
+ }
+ }
+ });
//
- String categoryName = category.getName();
+ return a.get();
+ }
- //
- CategoryDefinition categoryDef = registry.getCategory(categoryName);
- if (categoryDef == null)
+ public void save(final ApplicationCategory category) throws Exception
+ {
+ pomMGr.execute(new POMTask()
{
- categoryDef = registry.createCategory(categoryName);
- }
+ public void run(POMSession session) throws Exception
+ {
+ ContentRegistry registry = session.getContentRegistry();
- //
- categoryDef.setDisplayName(category.getDisplayName());
- categoryDef.setCreationDate(category.getCreatedDate());
- categoryDef.setLastModificationDate(category.getModifiedDate());
- categoryDef.setDescription(category.getDescription());
- categoryDef.setAccessPermissions(category.getAccessPermissions());
+ //
+ String categoryName = category.getName();
+
+ //
+ CategoryDefinition categoryDef = registry.getCategory(categoryName);
+ if (categoryDef == null)
+ {
+ categoryDef = registry.createCategory(categoryName);
+ }
+
+ //
+ categoryDef.setDisplayName(category.getDisplayName());
+ categoryDef.setCreationDate(category.getCreatedDate());
+ categoryDef.setLastModificationDate(category.getModifiedDate());
+ categoryDef.setDescription(category.getDescription());
+ categoryDef.setAccessPermissions(category.getAccessPermissions());
+ }
+ });
}
- public void remove(ApplicationCategory category) throws Exception
+ public void remove(final ApplicationCategory category) throws Exception
{
- POMSession session = POMSessionManager.getSession();
- ContentRegistry registry = session.getContentRegistry();
-
- //
- registry.getCategoryMap().remove(category.getName());
+ pomMGr.execute(new POMTask()
+ {
+ public void run(POMSession session) throws Exception
+ {
+ ContentRegistry registry = session.getContentRegistry();
+ registry.getCategoryMap().remove(category.getName());
+ }
+ });
}
public List<Application> getApplications(ApplicationCategory category,
ApplicationType<?>... appTypes) throws Exception
@@ -178,25 +207,36 @@
}
public List<Application> getApplications(
- ApplicationCategory category,
- Comparator<Application> sortComparator,
- ApplicationType<?>... appTypes) throws Exception
+ final ApplicationCategory category,
+ final Comparator<Application> sortComparator,
+ final ApplicationType<?>... appTypes) throws Exception
{
- POMSession session = POMSessionManager.getSession();
- ContentRegistry registry = session.getContentRegistry();
+ final AtomicReference<List<Application>> ref = new
AtomicReference<List<Application>>();
//
- CategoryDefinition categoryDef = registry.getCategory(category.getName());
- List<Application> applications = load(categoryDef,
appTypes).getApplications();
-
- //
- if (sortComparator != null)
+ pomMGr.execute(new POMTask()
{
- Collections.sort(applications, sortComparator);
- }
+ public void run(POMSession session) throws Exception
+ {
+ ContentRegistry registry = session.getContentRegistry();
+ //
+ CategoryDefinition categoryDef = registry.getCategory(category.getName());
+ List<Application> applications = load(categoryDef,
appTypes).getApplications();
+
+ //
+ if (sortComparator != null)
+ {
+ Collections.sort(applications, sortComparator);
+ }
+
+ //
+ ref.set(applications);
+ }
+ });
+
//
- return applications;
+ return ref.get();
}
public List<Application> getAllApplications() throws Exception
@@ -220,90 +260,108 @@
return getApplication(fragments[0], fragments[1]);
}
- public Application getApplication(String category, String name) throws Exception
+ public Application getApplication(final String category, final String name) throws
Exception
{
- POMSession session = POMSessionManager.getSession();
- ContentRegistry registry = session.getContentRegistry();
+ final AtomicReference<Application> ref = new
AtomicReference<Application>();
//
- CategoryDefinition categoryDef = registry.getCategory(category);
- if (categoryDef != null)
+ pomMGr.execute(new POMTask()
{
- ContentDefinition contentDef = categoryDef.getContentMap().get(name);
- if (contentDef != null)
+ public void run(POMSession session) throws Exception
{
- return load(contentDef);
+ ContentRegistry registry = session.getContentRegistry();
+
+ //
+ CategoryDefinition categoryDef = registry.getCategory(category);
+ if (categoryDef != null)
+ {
+ ContentDefinition contentDef = categoryDef.getContentMap().get(name);
+ if (contentDef != null)
+ {
+ ref.set(load(contentDef));
+ }
+ }
}
- }
+ });
//
- return null;
+ return ref.get();
}
- public void save(ApplicationCategory category, Application application) throws
Exception
+ public void save(final ApplicationCategory category, final Application application)
throws Exception
{
- POMSession session = POMSessionManager.getSession();
- ContentRegistry registry = session.getContentRegistry();
-
- //
- String categoryName = category.getName();
- CategoryDefinition categoryDef = registry.getCategory(categoryName);
- if (categoryDef == null)
+ pomMGr.execute(new POMTask()
{
- categoryDef = registry.createCategory(categoryName);
- save(category, categoryDef);
- }
+ public void run(POMSession session) throws Exception
+ {
+ ContentRegistry registry = session.getContentRegistry();
- //
- ContentDefinition contentDef = null;
- CategoryDefinition applicationCategoryDef =
registry.getCategory(application.getCategoryName());
- String applicationName = application.getApplicationName();
- if (applicationCategoryDef != null)
- {
- contentDef = applicationCategoryDef.getContentMap().get(applicationName);
- }
- if (contentDef == null)
- {
- String contentId = application.getContentId();
- ContentType<?> contentType = application.getType().getContentType();
- String definitionName = application.getDisplayName().replace(' ',
'_');
- contentDef = categoryDef.createContent(definitionName, contentType, contentId);
- }
- else
- {
- // A JCR move actually
- categoryDef.getContentList().add(contentDef);
- }
+ //
+ String categoryName = category.getName();
+ CategoryDefinition categoryDef = registry.getCategory(categoryName);
+ if (categoryDef == null)
+ {
+ categoryDef = registry.createCategory(categoryName);
+ save(category, categoryDef);
+ }
- // Update state
- save(application, contentDef);
+ //
+ ContentDefinition contentDef = null;
+ CategoryDefinition applicationCategoryDef =
registry.getCategory(application.getCategoryName());
+ String applicationName = application.getApplicationName();
+ if (applicationCategoryDef != null)
+ {
+ contentDef = applicationCategoryDef.getContentMap().get(applicationName);
+ }
+ if (contentDef == null)
+ {
+ String contentId = application.getContentId();
+ ContentType<?> contentType =
application.getType().getContentType();
+ String definitionName = application.getDisplayName().replace(' ',
'_');
+ contentDef = categoryDef.createContent(definitionName, contentType,
contentId);
+ }
+ else
+ {
+ // A JCR move actually
+ categoryDef.getContentList().add(contentDef);
+ }
+
+ // Update state
+ save(application, contentDef);
+ }
+ });
}
- public void update(Application application) throws Exception
+ public void update(final Application application) throws Exception
{
- POMSession session = POMSessionManager.getSession();
- ContentRegistry registry = session.getContentRegistry();
-
- //
- String categoryName = application.getCategoryName();
- CategoryDefinition categoryDef = registry.getCategory(categoryName);
- if (categoryDef == null)
+ pomMGr.execute(new POMTask()
{
- throw new IllegalStateException();
- }
+ public void run(POMSession session) throws Exception
+ {
+ ContentRegistry registry = session.getContentRegistry();
- //
- ContentDefinition contentDef =
categoryDef.getContentMap().get(application.getApplicationName());
- if (contentDef == null)
- {
- throw new IllegalStateException();
- }
+ //
+ String categoryName = application.getCategoryName();
+ CategoryDefinition categoryDef = registry.getCategory(categoryName);
+ if (categoryDef == null)
+ {
+ throw new IllegalStateException();
+ }
- // Update state
- save(application, contentDef);
+ //
+ ContentDefinition contentDef =
categoryDef.getContentMap().get(application.getApplicationName());
+ if (contentDef == null)
+ {
+ throw new IllegalStateException();
+ }
+
+ // Update state
+ save(application, contentDef);
+ }
+ });
}
- public void remove(Application app) throws Exception
+ public void remove(final Application app) throws Exception
{
if (app == null)
{
@@ -311,154 +369,169 @@
}
//
- POMSession session = POMSessionManager.getSession();
- ContentRegistry registry = session.getContentRegistry();
+ pomMGr.execute(new POMTask()
+ {
+ public void run(POMSession session) throws Exception
+ {
+ ContentRegistry registry = session.getContentRegistry();
- //
- String categoryName = app.getCategoryName();
- CategoryDefinition categoryDef = registry.getCategory(categoryName);
+ //
+ String categoryName = app.getCategoryName();
+ CategoryDefinition categoryDef = registry.getCategory(categoryName);
- //
- if (categoryDef != null)
- {
+ //
+ if (categoryDef != null)
+ {
- String contentName = app.getApplicationName();
- categoryDef.getContentMap().remove(contentName);
- }
+ String contentName = app.getApplicationName();
+ categoryDef.getContentMap().remove(contentName);
+ }
+ }
+ });
}
public void importExoGadgets() throws Exception
{
- POMSession session = POMSessionManager.getSession();
- ContentRegistry registry = session.getContentRegistry();
+ pomMGr.execute(new POMTask()
+ {
+ public void run(POMSession session) throws Exception
+ {
+ ContentRegistry registry = session.getContentRegistry();
- //
- ExoContainer container = ExoContainerContext.getCurrentContainer();
- GadgetRegistryService gadgetService =
(GadgetRegistryService)container.getComponentInstanceOfType(GadgetRegistryService.class);
- List<Gadget> eXoGadgets = gadgetService.getAllGadgets();
+ //
+ ExoContainer container = ExoContainerContext.getCurrentContainer();
+ GadgetRegistryService gadgetService =
(GadgetRegistryService)container.getComponentInstanceOfType(GadgetRegistryService.class);
+ List<Gadget> eXoGadgets = gadgetService.getAllGadgets();
- //
- if (eXoGadgets != null)
- {
- ArrayList<String> permissions = new ArrayList<String>();
- permissions.add(UserACL.EVERYONE);
- String categoryName = "Gadgets";
+ //
+ if (eXoGadgets != null)
+ {
+ ArrayList<String> permissions = new ArrayList<String>();
+ permissions.add(UserACL.EVERYONE);
+ String categoryName = "Gadgets";
- //
- CategoryDefinition category = registry.getCategory(categoryName);
- if (category == null)
- {
- category = registry.createCategory(categoryName);
- category.setDisplayName(categoryName);
- category.setDescription(categoryName);
- category.setAccessPermissions(permissions);
- }
+ //
+ CategoryDefinition category = registry.getCategory(categoryName);
+ if (category == null)
+ {
+ category = registry.createCategory(categoryName);
+ category.setDisplayName(categoryName);
+ category.setDescription(categoryName);
+ category.setAccessPermissions(permissions);
+ }
- //
- for (Gadget ele : eXoGadgets)
- {
- ContentDefinition app = category.getContentMap().get(ele.getName());
- if (app == null)
- {
- app = category.createContent(ele.getName(),
org.exoplatform.portal.pom.spi.gadget.Gadget.CONTENT_TYPE, ele.getName());
- app.setDisplayName(ele.getTitle());
- app.setDescription(ele.getDescription());
- app.setAccessPermissions(permissions);
+ //
+ for (Gadget ele : eXoGadgets)
+ {
+ ContentDefinition app = category.getContentMap().get(ele.getName());
+ if (app == null)
+ {
+ app = category.createContent(ele.getName(),
org.exoplatform.portal.pom.spi.gadget.Gadget.CONTENT_TYPE, ele.getName());
+ app.setDisplayName(ele.getTitle());
+ app.setDescription(ele.getDescription());
+ app.setAccessPermissions(permissions);
+ }
+ }
}
}
- }
+ });
}
public void importAllPortlets() throws Exception
{
- POMSession session = POMSessionManager.getSession();
- ContentRegistry registry = session.getContentRegistry();
-
- //
- ExoContainer manager = ExoContainerContext.getCurrentContainer();
- PortletInvoker portletInvoker =
(PortletInvoker)manager.getComponentInstance(PortletInvoker.class);
- Set<org.gatein.pc.api.Portlet> portlets = portletInvoker.getPortlets();
-
- //
- for (org.gatein.pc.api.Portlet portlet : portlets)
+ pomMGr.execute(new POMTask()
{
- PortletInfo info = portlet.getInfo();
- String portletApplicationName = info.getApplicationName();
- String portletName = info.getName();
-
- // Need to sanitize portlet and application names in case they contain
characters that would
- // cause an improper Application name
- portletApplicationName = portletApplicationName.replace('/',
'_');
- portletName = portletName.replace('/', '_');
-
- LocalizedString keywordsLS = info.getMeta().getMetaValue(MetaInfo.KEYWORDS);
-
- String[] categoryNames = null;
- if (keywordsLS != null)
+ public void run(POMSession session) throws Exception
{
- String keywords = keywordsLS.getDefaultString();
- if (keywords != null && keywords.length() != 0)
- {
- categoryNames = keywords.split(",");
- }
- }
+ ContentRegistry registry = session.getContentRegistry();
- if (categoryNames == null || categoryNames.length == 0)
- {
- categoryNames = new String[]{portletApplicationName};
- }
-
- if (portlet.isRemote())
- {
- categoryNames = Tools.appendTo(categoryNames, REMOTE_CATEGORY_NAME);
- }
-
- //
- for (String categoryName : categoryNames)
- {
- categoryName = categoryName.trim();
-
//
- CategoryDefinition category = registry.getCategory(categoryName);
+ ExoContainer manager = ExoContainerContext.getCurrentContainer();
+ PortletInvoker portletInvoker =
(PortletInvoker)manager.getComponentInstance(PortletInvoker.class);
+ Set<org.gatein.pc.api.Portlet> portlets =
portletInvoker.getPortlets();
//
- if (category == null)
+ for (org.gatein.pc.api.Portlet portlet : portlets)
{
- category = registry.createCategory(categoryName);
- category.setDisplayName(categoryName);
- }
+ PortletInfo info = portlet.getInfo();
+ String portletApplicationName = info.getApplicationName();
+ String portletName = info.getName();
- //
- ContentDefinition app = category.getContentMap().get(portletName);
- if (app == null)
- {
- LocalizedString descriptionLS =
portlet.getInfo().getMeta().getMetaValue(MetaInfo.DESCRIPTION);
- LocalizedString displayNameLS =
portlet.getInfo().getMeta().getMetaValue(MetaInfo.DISPLAY_NAME);
+ // Need to sanitize portlet and application names in case they contain
characters that would
+ // cause an improper Application name
+ portletApplicationName = portletApplicationName.replace('/',
'_');
+ portletName = portletName.replace('/', '_');
- // julien: ????
- // getLocalizedStringValue(descriptionLS, portletName);
+ LocalizedString keywordsLS =
info.getMeta().getMetaValue(MetaInfo.KEYWORDS);
- ContentType<?> contentType;
- String contentId;
- if (portlet.isRemote())
+ String[] categoryNames = null;
+ if (keywordsLS != null)
{
- contentType = WSRP.CONTENT_TYPE;
- contentId = portlet.getContext().getId();
+ String keywords = keywordsLS.getDefaultString();
+ if (keywords != null && keywords.length() != 0)
+ {
+ categoryNames = keywords.split(",");
+ }
}
- else
+
+ if (categoryNames == null || categoryNames.length == 0)
{
- contentType = Portlet.CONTENT_TYPE;
- contentId = info.getApplicationName() + "/" +
info.getName();
+ categoryNames = new String[]{portletApplicationName};
}
+ if (portlet.isRemote())
+ {
+ categoryNames = Tools.appendTo(categoryNames, REMOTE_CATEGORY_NAME);
+ }
//
- app = category.createContent(portletName, contentType, contentId);
- app.setDisplayName(getLocalizedStringValue(displayNameLS, portletName));
- app.setDescription(getLocalizedStringValue(descriptionLS, portletName));
+ for (String categoryName : categoryNames)
+ {
+ categoryName = categoryName.trim();
+
+ //
+ CategoryDefinition category = registry.getCategory(categoryName);
+
+ //
+ if (category == null)
+ {
+ category = registry.createCategory(categoryName);
+ category.setDisplayName(categoryName);
+ }
+
+ //
+ ContentDefinition app = category.getContentMap().get(portletName);
+ if (app == null)
+ {
+ LocalizedString descriptionLS =
portlet.getInfo().getMeta().getMetaValue(MetaInfo.DESCRIPTION);
+ LocalizedString displayNameLS =
portlet.getInfo().getMeta().getMetaValue(MetaInfo.DISPLAY_NAME);
+
+ // julien: ????
+ // getLocalizedStringValue(descriptionLS, portletName);
+
+ ContentType<?> contentType;
+ String contentId;
+ if (portlet.isRemote())
+ {
+ contentType = WSRP.CONTENT_TYPE;
+ contentId = portlet.getContext().getId();
+ }
+ else
+ {
+ contentType = Portlet.CONTENT_TYPE;
+ contentId = info.getApplicationName() + "/" +
info.getName();
+ }
+
+
+ //
+ app = category.createContent(portletName, contentType, contentId);
+ app.setDisplayName(getLocalizedStringValue(displayNameLS,
portletName));
+ app.setDescription(getLocalizedStringValue(descriptionLS,
portletName));
+ }
+ }
}
}
- }
+ });
}
private boolean isApplicationType(Application app, ApplicationType<?>...
appTypes)
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/ApplicationStatistic.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/ApplicationStatistic.java 2009-11-18
23:03:17 UTC (rev 654)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/ApplicationStatistic.java 2009-11-18
23:39:15 UTC (rev 655)
@@ -51,6 +51,11 @@
this.appId = appId;
}
+ public String getAppId()
+ {
+ return appId;
+ }
+
/**
* Log the time.
*
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/ApplicationStatisticService.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/ApplicationStatisticService.java 2009-11-18
23:03:17 UTC (rev 654)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/ApplicationStatisticService.java 2009-11-18
23:39:15 UTC (rev 655)
@@ -20,7 +20,6 @@
package org.exoplatform.portal.application;
import org.exoplatform.application.registry.Application;
-import org.exoplatform.application.registry.ApplicationRegistryService;
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.annotations.ManagedDescription;
import org.exoplatform.management.annotations.ManagedName;
@@ -36,6 +35,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -50,17 +50,11 @@
public class ApplicationStatisticService implements Startable
{
- private ApplicationRegistryService appRegistryService;
+ /** . */
+ private final ConcurrentMap<String, ApplicationStatistic> apps = new
ConcurrentHashMap<String, ApplicationStatistic>();
- private ConcurrentMap<String, ApplicationStatistic> apps = new
ConcurrentHashMap<String, ApplicationStatistic>();
-
- private final String ASC = "ASC";
-
- private final String DESC = "DESC";
-
- public ApplicationStatisticService(ApplicationRegistryService appRegistryService)
+ public ApplicationStatisticService()
{
- this.appRegistryService = appRegistryService;
}
/*
@@ -70,22 +64,9 @@
@ManagedDescription("The list of application identifiers sorted
alphabetically")
public String[] getApplicationList()
{
- List<Application> list = null;
- try
- {
- list = appRegistryService.getAllApplications();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- List<String> appIds = new ArrayList<String>();
- for (Application app : list)
- {
- appIds.add(app.getId());
- }
- Collections.sort(appIds);
- return appIds.toArray(new String[appIds.size()]);
+ List<String> list = new ArrayList<String>(apps.keySet());
+ Collections.sort(list);
+ return list.toArray(new String[list.size()]);
}
/*
@@ -158,28 +139,7 @@
@ManagedDescription("The list of the 10 slowest applications")
public String[] getSlowestApplications()
{
- List<Application> list = null;
- Map application = new HashMap();
- try
- {
- list = appRegistryService.getAllApplications();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
-
- for (Application app : list)
- {
- ApplicationStatistic appSta = getApplicationStatistic(app.getId());
- // remove application haven't loaded
- if (appSta.getAverageTime() != 0)
- {
- application.put(app.getId(), appSta.getAverageTime());
- }
- }
-
- return sort(application, DESC);
+ return getApplicationsSortedByAverageTime(true);
}
/*
@@ -189,28 +149,26 @@
@ManagedDescription("The list of the 10 fastest applications")
public String[] getFastestApplications()
{
- List<Application> list = null;
- Map application = new HashMap();
- try
- {
- list = appRegistryService.getAllApplications();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
+ return getApplicationsSortedByAverageTime(false);
+ }
- for (Application app : list)
+ private String[] getApplicationsSortedByAverageTime(boolean desc)
+ {
+ TreeMap<Double, String> map = new TreeMap<Double, String>();
+ for (ApplicationStatistic app : apps.values())
{
- ApplicationStatistic appSta = getApplicationStatistic(app.getId());
- // remove application haven't loaded
- if (appSta.getAverageTime() != 0)
+ if (app.getAverageTime() > 0)
{
- application.put(app.getId(), appSta.getAverageTime());
+ map.put(app.getAverageTime(), app.getAppId());
}
}
-
- return sort(application, ASC);
+ List<String> list = new ArrayList<String>(map.values());
+ if (desc)
+ {
+ Collections.reverse(list);
+ }
+ List<String> sub = list.subList(0, Math.min(map.size(), 10));
+ return sub.toArray(new String[sub.size()]);
}
/*
@@ -220,99 +178,20 @@
@ManagedDescription("The list of the 10 most executed applications")
public String[] getMostExecutedApplications()
{
- List<Application> list = null;
- Map application = new HashMap();
- try
+ TreeMap<Long, String> map = new TreeMap<Long, String>();
+ for (ApplicationStatistic app : apps.values())
{
- list = appRegistryService.getAllApplications();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
-
- for (Application app : list)
- {
- ApplicationStatistic appSta = getApplicationStatistic(app.getId());
- // remove application haven't loaded
- if (appSta.executionCount() != 0)
+ if (app.executionCount() > 0)
{
- application.put(app.getId(), appSta.executionCount());
+ map.put(app.executionCount(), app.getAppId());
}
}
-
- return sort(application, DESC);
+ List<String> list = new ArrayList<String>(map.values());
+ Collections.reverse(list);
+ List<String> sub = list.subList(0, Math.min(map.size(), 10));
+ return sub.toArray(new String[sub.size()]);
}
- /*
- * sort map by value asc or desc
- */
- private String[] sort(Map source, String order)
- {
- String[] app = new String[10];
- List<Object> list = new LinkedList<Object>(source.entrySet());
- if (order.equals(ASC))
- {
- Collections.sort(list, new Comparator<Object>()
- {
- public int compare(Object o1, Object o2)
- {
- double value1 =
Double.parseDouble(((Map.Entry)(o1)).getValue().toString());
- double value2 =
Double.parseDouble(((Map.Entry)(o2)).getValue().toString());
- if (value1 > value2)
- {
- return 1;
- }
- else if (value1 < value2)
- {
- return -1;
- }
- else
- {
- return 0;
- }
- }
- });
- }
- else if (order.equals(DESC))
- {
- Collections.sort(list, new Comparator<Object>()
- {
- public int compare(Object o1, Object o2)
- {
- double value1 =
Double.parseDouble(((Map.Entry)(o1)).getValue().toString());
- double value2 =
Double.parseDouble(((Map.Entry)(o2)).getValue().toString());
- if (value2 > value1)
- {
- return 1;
- }
- else if (value2 < value1)
- {
- return -1;
- }
- else
- {
- return 0;
- }
- }
- });
- }
-
- int index = 0;
- for (Iterator it = list.iterator(); it.hasNext();)
- {
- Map.Entry entry = (Map.Entry)it.next();
- app[index] = (String)entry.getKey();
- index++;
- if (index >= app.length)
- {
- break;
- }
- }
- return app;
-
- }
-
private double toSeconds(double value)
{
return value == -1 ? -1 : value / 1000D;