Author: julien_viet
Date: 2010-02-10 14:40:15 -0500 (Wed, 10 Feb 2010)
New Revision: 1620
Modified:
portal/trunk/component/common/pom.xml
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinService.java
portal/trunk/component/scripting/src/main/java/org/exoplatform/groovyscript/text/TemplateService.java
portal/trunk/component/scripting/src/main/java/org/exoplatform/groovyscript/text/TemplateStatisticService.java
portal/trunk/component/web/src/main/java/org/exoplatform/web/login/PortalLoginController.java
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/Token.java
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/AbstractTokenService.java
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/CookieTokenService.java
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/TransientTokenService.java
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetToken.java
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetTokenContainer.java
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetTokenEntry.java
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetTokenInfoService.java
portal/trunk/pom.xml
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/ApplicationStatisticService.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStatisticService.java
Log:
- make a bit the token service to be more type safe
- use the @Impact annotations on the various managed operations
Modified: portal/trunk/component/common/pom.xml
===================================================================
--- portal/trunk/component/common/pom.xml 2010-02-10 17:34:37 UTC (rev 1619)
+++ portal/trunk/component/common/pom.xml 2010-02-10 19:40:15 UTC (rev 1620)
@@ -63,6 +63,10 @@
<groupId>org.chromattic</groupId>
<artifactId>chromattic.spi</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.exoplatform.ws</groupId>
+ <artifactId>exo.ws.rest.core</artifactId>
+ </dependency>
<dependency>
<groupId>org.exoplatform.portal</groupId>
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinService.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinService.java 2010-02-10
17:34:37 UTC (rev 1619)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinService.java 2010-02-10
19:40:15 UTC (rev 1620)
@@ -22,6 +22,8 @@
import org.exoplatform.commons.utils.PropertyManager;
import org.exoplatform.commons.utils.Safe;
import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.management.annotations.Impact;
+import org.exoplatform.management.annotations.ImpactType;
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.annotations.ManagedDescription;
import org.exoplatform.management.annotations.ManagedName;
@@ -56,6 +58,7 @@
@NameTemplate({@Property(key = "view", value = "portal"),
@Property(key = "service", value = "management"),
@Property(key = "type", value = "skin")})
@ManagedDescription("Skin service")
+// @Rest("skinservice")
public class SkinService implements Startable
{
@@ -563,6 +566,7 @@
@Managed
@ManagedDescription("Reload all skins")
+ @Impact(ImpactType.WRITE)
public void reloadSkins()
{
// remove all ltCache, rtCache
Modified:
portal/trunk/component/scripting/src/main/java/org/exoplatform/groovyscript/text/TemplateService.java
===================================================================
---
portal/trunk/component/scripting/src/main/java/org/exoplatform/groovyscript/text/TemplateService.java 2010-02-10
17:34:37 UTC (rev 1619)
+++
portal/trunk/component/scripting/src/main/java/org/exoplatform/groovyscript/text/TemplateService.java 2010-02-10
19:40:15 UTC (rev 1620)
@@ -26,6 +26,8 @@
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.groovyscript.GroovyTemplate;
import org.exoplatform.groovyscript.GroovyTemplateEngine;
+import org.exoplatform.management.annotations.Impact;
+import org.exoplatform.management.annotations.ImpactType;
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.annotations.ManagedDescription;
import org.exoplatform.management.annotations.ManagedName;
@@ -36,6 +38,7 @@
import org.exoplatform.services.cache.ExoCache;
import java.io.InputStream;
+import java.util.ArrayList;
/**
* Created by The eXo Platform SAS Dec 26, 2005
@@ -44,6 +47,7 @@
@NameTemplate({@Property(key = "view", value = "portal"),
@Property(key = "service", value = "management"),
@Property(key = "type", value = "template")})
@ManagedDescription("Template management service")
+// @Rest("templateservice")
public class TemplateService
{
@@ -172,6 +176,7 @@
*/
@Managed
@ManagedDescription("Clear the template cache for a specified template
identifier")
+ @Impact(ImpactType.IDEMPOTENT_WRITE)
public void reloadTemplate(@ManagedDescription("The template id")
@ManagedName("templateId") String name)
{
try
@@ -185,4 +190,25 @@
e.printStackTrace();
}
}
+
+ @Managed
+ @ManagedDescription("List the identifiers of the cached templates")
+ @Impact(ImpactType.READ)
+ public String[] listCachedTemplates()
+ {
+ try
+ {
+ ArrayList<String> list = new ArrayList<String>();
+ for (GroovyTemplate template : templatesCache_.getCachedObjects())
+ {
+ list.add(template.getId());
+ }
+ return list.toArray(new String[list.size()]);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ return null;
+ }
+ }
}
Modified:
portal/trunk/component/scripting/src/main/java/org/exoplatform/groovyscript/text/TemplateStatisticService.java
===================================================================
---
portal/trunk/component/scripting/src/main/java/org/exoplatform/groovyscript/text/TemplateStatisticService.java 2010-02-10
17:34:37 UTC (rev 1619)
+++
portal/trunk/component/scripting/src/main/java/org/exoplatform/groovyscript/text/TemplateStatisticService.java 2010-02-10
19:40:15 UTC (rev 1620)
@@ -19,12 +19,15 @@
package org.exoplatform.groovyscript.text;
+import org.exoplatform.management.annotations.Impact;
+import org.exoplatform.management.annotations.ImpactType;
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.annotations.ManagedDescription;
import org.exoplatform.management.annotations.ManagedName;
import org.exoplatform.management.jmx.annotations.NameTemplate;
import org.exoplatform.management.jmx.annotations.Property;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
@@ -40,9 +43,12 @@
*/
@Managed
-@NameTemplate({@Property(key = "view", value = "portal"),
@Property(key = "service", value = "statistic"),
- @Property(key = "type", value = "template")})
@ManagedDescription("Template statistic service")
+@NameTemplate({
+ @Property(key = "view", value = "portal"),
+ @Property(key = "service", value = "statistic"),
+ @Property(key = "type", value = "template")})
+// @Rest("templatestatistics")
public class TemplateStatisticService
{
@@ -95,6 +101,7 @@
*/
@Managed
@ManagedDescription("The maximum rendering time of a specified template in
seconds")
+ @Impact(ImpactType.READ)
public double getMaxTime(@ManagedDescription("The template id")
@ManagedName("templateId") String name)
{
TemplateStatistic app = apps.get(name);
@@ -106,6 +113,7 @@
*/
@Managed
@ManagedDescription("The minimum rendering time of a specified template in
seconds")
+ @Impact(ImpactType.READ)
public double getMinTime(@ManagedDescription("The template id")
@ManagedName("templateId") String name)
{
TemplateStatistic app = apps.get(name);
@@ -117,6 +125,7 @@
*/
@Managed
@ManagedDescription("The rendering count of a specified template")
+ @Impact(ImpactType.READ)
public long getExecutionCount(@ManagedDescription("The template id")
@ManagedName("templateId") String name)
{
TemplateStatistic app = apps.get(name);
@@ -128,6 +137,7 @@
*/
@Managed
@ManagedDescription("The average rendering time of a specified template in
seconds")
+ @Impact(ImpactType.READ)
public double getAverageTime(@ManagedDescription("The template id")
@ManagedName("templateId") String name)
{
TemplateStatistic app = apps.get(name);
@@ -142,12 +152,10 @@
public String[] getSlowestTemplates()
{
- Map application = new HashMap();
- List<Object> list = new LinkedList<Object>(apps.entrySet());
- for (Iterator it = list.iterator(); it.hasNext();)
+ Map<String, Double> application = new HashMap<String, Double>();
+ for (Map.Entry<String, TemplateStatistic> entry : apps.entrySet())
{
- Map.Entry entry = (Map.Entry)it.next();
- String url = (String)entry.getKey();
+ String url = entry.getKey();
application.put(url, getAverageTime(url));
}
@@ -162,12 +170,10 @@
public String[] getMostExecutedTemplates()
{
- Map application = new HashMap();
- List<Object> list = new LinkedList<Object>(apps.entrySet());
- for (Iterator it = list.iterator(); it.hasNext();)
+ Map<String, Long> application = new HashMap<String, Long>();
+ for (Map.Entry<String, TemplateStatistic> entry : apps.entrySet())
{
- Map.Entry entry = (Map.Entry)it.next();
- String url = (String)entry.getKey();
+ String url = entry.getKey();
application.put(url, getExecutionCount(url));
}
@@ -182,74 +188,39 @@
public String[] getFastestTemplates()
{
- Map application = new HashMap();
- List<Object> list = new LinkedList<Object>(apps.entrySet());
- for (Iterator it = list.iterator(); it.hasNext();)
+ Map<String, Double> application = new HashMap<String, Double>();
+ for (Map.Entry<String, TemplateStatistic> entry : apps.entrySet())
{
- Map.Entry entry = (Map.Entry)it.next();
- String url = (String)entry.getKey();
+ String url = entry.getKey();
application.put(url, getAverageTime(url));
}
return sort(application, ASC);
}
- private String[] sort(Map source, String order)
+ private <T extends Comparable<T>> String[] sort(Map<String, T>
source, final String order)
{
String[] app = new String[10];
- List<Object> list = new LinkedList<Object>(source.entrySet());
- if (order.equals(ASC))
+ List<Map.Entry<String, T>> list = new ArrayList<Map.Entry<String,
T>>(source.entrySet());
+ Collections.sort(list, new Comparator<Map.Entry<String, T>>()
{
- Collections.sort(list, new Comparator<Object>()
+ public int compare(Map.Entry<String, T> o1, Map.Entry<String, T>
o2)
{
- public int compare(Object o1, Object o2)
+ T value1 = o1.getValue();
+ T value2 = o2.getValue();
+ if (DESC.equals(order))
{
- 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;
- }
+ T tmp = value1;
+ value1 = value2;
+ value2 = tmp;
}
- });
- }
- 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;
- }
- }
- });
- }
-
+ return value1.compareTo(value2);
+ }
+ });
int index = 0;
- for (Iterator it = list.iterator(); it.hasNext();)
+ for (Map.Entry<String, T> entry : list)
{
- Map.Entry entry = (Map.Entry)it.next();
- app[index] = (String)entry.getKey();
+ app[index] = entry.getKey();
index++;
if (index >= app.length)
{
@@ -257,7 +228,6 @@
}
}
return app;
-
}
private double toSeconds(double value)
Modified:
portal/trunk/component/web/src/main/java/org/exoplatform/web/login/PortalLoginController.java
===================================================================
---
portal/trunk/component/web/src/main/java/org/exoplatform/web/login/PortalLoginController.java 2010-02-10
17:34:37 UTC (rev 1619)
+++
portal/trunk/component/web/src/main/java/org/exoplatform/web/login/PortalLoginController.java 2010-02-10
19:40:15 UTC (rev 1620)
@@ -69,7 +69,7 @@
String cookieToken = tokenService.createToken(credentials);
Cookie cookie = new Cookie(InitiateLoginServlet.COOKIE_NAME, cookieToken);
cookie.setPath(req.getContextPath());
- cookie.setMaxAge((int)tokenService.getExpiredPeriodTime() / 1000);
+ cookie.setMaxAge((int)tokenService.getValidityTime() / 1000);
resp.addCookie(cookie);
}
}
Modified:
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/Token.java
===================================================================
---
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/Token.java 2010-02-10
17:34:37 UTC (rev 1619)
+++
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/Token.java 2010-02-10
19:40:15 UTC (rev 1620)
@@ -1,6 +1,32 @@
+/**
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.web.security;
+/**
+ * A token.
+ */
public interface Token
{
- public boolean isExpired();
+ boolean isExpired();
+
+ long getExpirationTimeMillis();
+
+ Credentials getPayload();
+
}
Modified:
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/AbstractTokenService.java
===================================================================
---
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/AbstractTokenService.java 2010-02-10
17:34:37 UTC (rev 1619)
+++
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/AbstractTokenService.java 2010-02-10
19:40:15 UTC (rev 1620)
@@ -21,14 +21,11 @@
import org.exoplatform.container.PortalContainer;
import org.exoplatform.container.xml.InitParams;
-import org.exoplatform.management.annotations.Managed;
-import org.exoplatform.management.annotations.ManagedDescription;
-import org.exoplatform.management.annotations.ManagedName;
+import org.exoplatform.management.annotations.*;
import org.exoplatform.management.jmx.annotations.NameTemplate;
import org.exoplatform.management.jmx.annotations.Property;
import org.exoplatform.web.login.InitiateLoginServlet;
import org.exoplatform.web.security.Credentials;
-import org.exoplatform.web.security.GateInToken;
import org.exoplatform.web.security.Token;
import org.exoplatform.web.security.TokenStore;
import org.picocontainer.Startable;
@@ -42,11 +39,21 @@
/**
* Created by The eXo Platform SAS Author : liem.nguyen ncliam(a)gmail.com Jun 5,
* 2009
+ *
+ * todo julien :
+ * - make delay configuration from init param and @Managed setter
+ * - start/stop expiration daemon
+ * - manually invoke the daemon via @Managed
+ *
+ * @param <T> the token type
+ * @param <K> the token key type
*/
@Managed
-@NameTemplate({@Property(key = "service", value = "TokenStore"),
@Property(key = "name", value = "{Name}")})
@ManagedDescription("Token Store Service")
-public abstract class AbstractTokenService implements Startable, TokenStore
+@NameTemplate({
+ @Property(key = "service", value = "TokenStore"),
+ @Property(key = "name", value = "{Name}")})
+public abstract class AbstractTokenService<T extends Token, K> implements
Startable, TokenStore
{
protected static final String SERVICE_CONFIG = "service.configuration";
@@ -94,14 +101,17 @@
return classType.cast(container.getComponentInstanceOfType(classType));
}
- public Credentials validateToken(String tokenKey, boolean remove)
+ public Credentials validateToken(String stringKey, boolean remove)
{
- if (tokenKey == null)
+ if (stringKey == null)
{
throw new NullPointerException();
}
- GateInToken token;
+ //
+ K tokenKey = decodeKey(stringKey);
+
+ T token;
try
{
if (remove)
@@ -135,49 +145,60 @@
@Managed
@ManagedDescription("Clean all tokens are expired")
+ @Impact(ImpactType.IDEMPOTENT_WRITE)
public void cleanExpiredTokens()
{
- String[] ids = getAllTokens();
- for (String s : ids)
+ K[] ids = getAllTokens();
+ for (K id : ids)
{
- GateInToken token = getToken(s);
+ T token = getToken(id);
if (token.isExpired())
{
- deleteToken(s);
+ deleteToken(id);
}
}
}
@Managed
- @ManagedDescription("Get period time of expired token")
- public long getExpiredPeriodTime()
+ @ManagedDescription("Get time for token expiration in seconds")
+ public long getValidityTime()
{
- return validityMillis;
+ return validityMillis / 1000;
}
@Managed
- @ManagedName("Name")
+ @ManagedDescription("The expiration daemon period time in seconds")
+ public long getPeriodTime()
+ {
+ return DELAY_TIME;
+ }
+
+ @Managed
@ManagedDescription("The token service name")
public String getName()
{
return name;
}
- @Managed
- @ManagedDescription("get a token by id")
- public abstract <T extends Token> T getToken(Object id);
+ public abstract T getToken(K id);
- @Managed
- @ManagedDescription("Delete a token by id")
- public abstract <T extends Token> T deleteToken(Object id);
+ public abstract T deleteToken(K id);
- @Managed
- @ManagedDescription("The list of all tokens")
- public abstract <T extends Object> T[] getAllTokens();
+ public abstract K[] getAllTokens();
+ /**
+ * Decode a key from its string representation.
+ *
+ * @param stringKey the key a s a string
+ * @return the typed key
+ */
+ protected abstract K decodeKey(String stringKey);
+
+ // We don't make it a property as retrieving the value can be an expensive
operation
@Managed
@ManagedDescription("The number of tokens")
- public abstract long getNumberTokens() throws Exception;
+ @Impact(ImpactType.READ)
+ public abstract long size() throws Exception;
private enum TimeoutEnum {
SECOND(1000), MINUTE(1000 * 60), HOUR(1000 * 60 * 60), DAY(1000 * 60 * 60 * 24);
Modified:
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/CookieTokenService.java
===================================================================
---
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/CookieTokenService.java 2010-02-10
17:34:37 UTC (rev 1619)
+++
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/CookieTokenService.java 2010-02-10
19:40:15 UTC (rev 1620)
@@ -35,7 +35,7 @@
* Created by The eXo Platform SAS Author : liem.nguyen ncliam(a)gmail.com Jun 5,
* 2009
*/
-public class CookieTokenService extends AbstractTokenService
+public class CookieTokenService extends AbstractTokenService<GateInToken, String>
{
/** . */
@@ -78,7 +78,7 @@
}
@Override
- public GateInToken getToken(final Object id)
+ public GateInToken getToken(final String id)
{
return new TokenTask<GateInToken>() {
@Override
@@ -90,7 +90,7 @@
}
@Override
- public GateInToken deleteToken(final Object id)
+ public GateInToken deleteToken(final String id)
{
return new TokenTask<GateInToken>() {
@Override
@@ -122,7 +122,7 @@
}
@Override
- public long getNumberTokens() throws Exception
+ public long size() throws Exception
{
return new TokenTask<Long>() {
@Override
@@ -135,6 +135,12 @@
}.executeWith(chromatticLifeCycle);
}
+ @Override
+ protected String decodeKey(String stringKey)
+ {
+ return stringKey;
+ }
+
/**
* Wraps token store logic conveniently.
*
Modified:
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/TransientTokenService.java
===================================================================
---
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/TransientTokenService.java 2010-02-10
17:34:37 UTC (rev 1619)
+++
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/TransientTokenService.java 2010-02-10
19:40:15 UTC (rev 1620)
@@ -29,7 +29,7 @@
* Created by The eXo Platform SAS Author : liem.nguyen ncliam(a)gmail.com Jun 5,
* 2009
*/
-public class TransientTokenService extends AbstractTokenService
+public class TransientTokenService extends AbstractTokenService<GateInToken,
String>
{
protected final ConcurrentHashMap<String, GateInToken> tokens = new
ConcurrentHashMap<String, GateInToken>();
@@ -56,14 +56,20 @@
}
@Override
- public GateInToken getToken(Object id)
+ public GateInToken getToken(String id)
{
return tokens.get(id);
}
@Override
- public GateInToken deleteToken(Object id)
+ protected String decodeKey(String stringKey)
{
+ return stringKey;
+ }
+
+ @Override
+ public GateInToken deleteToken(String id)
+ {
GateInToken token = tokens.get(id);
tokens.remove(id);
return token;
@@ -76,7 +82,7 @@
}
@Override
- public long getNumberTokens() throws Exception
+ public long size() throws Exception
{
return tokens.size();
}
Modified:
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetToken.java
===================================================================
---
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetToken.java 2010-02-10
17:34:37 UTC (rev 1619)
+++
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetToken.java 2010-02-10
19:40:15 UTC (rev 1620)
@@ -1,6 +1,7 @@
package org.exoplatform.portal.gadget.core;
import org.apache.shindig.gadgets.oauth.OAuthStore.TokenInfo;
+import org.exoplatform.web.security.Credentials;
import org.exoplatform.web.security.Token;
@@ -16,4 +17,15 @@
{
return false;
}
+
+ public long getExpirationTimeMillis()
+ {
+ return getTokenExpireMillis();
+ }
+
+ public Credentials getPayload()
+ {
+ // Should we return something ?
+ return null;
+ }
}
Modified:
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetTokenContainer.java
===================================================================
---
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetTokenContainer.java 2010-02-10
17:34:37 UTC (rev 1619)
+++
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetTokenContainer.java 2010-02-10
19:40:15 UTC (rev 1620)
@@ -20,18 +20,10 @@
public GadgetToken getToken(BasicOAuthStoreTokenIndex tokenKey)
{
Map<String, GadgetTokenEntry> tokens = getGadgetTokens();
-
for (GadgetTokenEntry tokenEntry : tokens.values())
{
- {
- BasicOAuthStoreTokenIndex key = new BasicOAuthStoreTokenIndex();
- key.setGadgetUri(tokenEntry.getGadgetUri());
- key.setModuleId(tokenEntry.getModuleId());
- key.setServiceName(tokenEntry.getServiceName());
- key.setTokenName(tokenEntry.getTokenName());
- key.setUserId(tokenEntry.getUserId());
- if (tokenKey.equals(key)) return tokenEntry.getToken();
- }
+ BasicOAuthStoreTokenIndex key = tokenEntry.getKey();
+ if (tokenKey.equals(key)) return tokenEntry.getToken();
}
return null;
}
@@ -42,14 +34,10 @@
for (GadgetTokenEntry tokenEntry : tokens.values())
{
+ BasicOAuthStoreTokenIndex key = tokenEntry.getKey();
+ if (tokenKey.equals(key))
{
- BasicOAuthStoreTokenIndex key = new BasicOAuthStoreTokenIndex();
- key.setGadgetUri(tokenEntry.getGadgetUri());
- key.setModuleId(tokenEntry.getModuleId());
- key.setServiceName(tokenEntry.getServiceName());
- key.setTokenName(tokenEntry.getTokenName());
- key.setUserId(tokenEntry.getUserId());
- if (tokenKey.equals(key)) tokenEntry.remove();
+ tokenEntry.remove();
return tokenEntry.getToken();
}
}
@@ -62,17 +50,11 @@
GadgetTokenEntry entry = null;
for (GadgetTokenEntry item : tokens.values())
{
+ BasicOAuthStoreTokenIndex key = item.getKey();
+ if (tokenKey.equals(key))
{
- BasicOAuthStoreTokenIndex key = new BasicOAuthStoreTokenIndex();
- key.setGadgetUri(item.getGadgetUri());
- key.setModuleId(item.getModuleId());
- key.setServiceName(item.getServiceName());
- key.setTokenName(item.getTokenName());
- key.setUserId(item.getUserId());
- if (tokenKey.equals(key))
- entry = item;
+ entry = item;
}
-
}
if (entry == null)
{
Modified:
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetTokenEntry.java
===================================================================
---
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetTokenEntry.java 2010-02-10
17:34:37 UTC (rev 1619)
+++
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetTokenEntry.java 2010-02-10
19:40:15 UTC (rev 1620)
@@ -1,5 +1,6 @@
package org.exoplatform.portal.gadget.core;
+import org.apache.shindig.gadgets.oauth.BasicOAuthStoreTokenIndex;
import org.chromattic.api.annotations.Destroy;
import org.chromattic.api.annotations.PrimaryType;
import org.chromattic.api.annotations.Property;
@@ -7,7 +8,18 @@
@PrimaryType(name = "lgn:gadgettoken")
public abstract class GadgetTokenEntry
{
-
+
+ public BasicOAuthStoreTokenIndex getKey()
+ {
+ BasicOAuthStoreTokenIndex key = new BasicOAuthStoreTokenIndex();
+ key.setGadgetUri(getGadgetUri());
+ key.setModuleId(getModuleId());
+ key.setServiceName(getServiceName());
+ key.setTokenName(getTokenName());
+ key.setUserId(getUserId());
+ return key;
+ }
+
@Property(name = "userId")
public abstract String getUserId();
Modified:
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetTokenInfoService.java
===================================================================
---
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetTokenInfoService.java 2010-02-10
17:34:37 UTC (rev 1619)
+++
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetTokenInfoService.java 2010-02-10
19:40:15 UTC (rev 1620)
@@ -32,7 +32,7 @@
import java.util.Collection;
-public class GadgetTokenInfoService extends AbstractTokenService
+public class GadgetTokenInfoService extends AbstractTokenService<GadgetToken,
BasicOAuthStoreTokenIndex>
{
private ChromatticLifeCycle chromatticLifeCycle;
@@ -57,45 +57,45 @@
}
@Override
- public GadgetToken getToken(final Object key)
+ public GadgetToken getToken(final BasicOAuthStoreTokenIndex key)
{
return new TokenTask<GadgetToken>()
{
@Override
protected GadgetToken execute()
{
- return getGadgetTokenContainer().getToken((BasicOAuthStoreTokenIndex)key);
+ return getGadgetTokenContainer().getToken(key);
}
}.executeWith(chromatticLifeCycle);
}
@Override
- public GadgetToken deleteToken(final Object key)
+ public GadgetToken deleteToken(final BasicOAuthStoreTokenIndex key)
{
return new TokenTask<GadgetToken>()
{
@Override
protected GadgetToken execute()
{
- return
getGadgetTokenContainer().removeToken((BasicOAuthStoreTokenIndex)key);
+ return getGadgetTokenContainer().removeToken(key);
}
}.executeWith(chromatticLifeCycle);
}
@Override
- public GadgetToken[] getAllTokens()
+ public BasicOAuthStoreTokenIndex[] getAllTokens()
{
- return new TokenTask<GadgetToken[]>()
+ return new TokenTask<BasicOAuthStoreTokenIndex[]>()
{
@Override
- protected GadgetToken[] execute()
+ protected BasicOAuthStoreTokenIndex[] execute()
{
GadgetTokenContainer container = getGadgetTokenContainer();
Collection<GadgetTokenEntry> tokens =
container.getGadgetTokens().values();
- GadgetToken[] gadgetTokens = new GadgetToken[9];
+ BasicOAuthStoreTokenIndex[] gadgetTokens = new BasicOAuthStoreTokenIndex[9];
int count = 0;
for(GadgetTokenEntry tokenEntry : tokens) {
- gadgetTokens[count++] = tokenEntry.getToken();
+ gadgetTokens[count++] = tokenEntry.getKey();
}
return gadgetTokens;
}
@@ -103,7 +103,7 @@
}
@Override
- public long getNumberTokens() throws Exception
+ public long size() throws Exception
{
return new TokenTask<Long>()
{
@@ -123,6 +123,11 @@
return null;
}
+ @Override
+ protected BasicOAuthStoreTokenIndex decodeKey(String stringKey)
+ {
+ throw new UnsupportedOperationException();
+ }
/**
* Wraps token store logic conveniently.
Modified: portal/trunk/pom.xml
===================================================================
--- portal/trunk/pom.xml 2010-02-10 17:34:37 UTC (rev 1619)
+++ portal/trunk/pom.xml 2010-02-10 19:40:15 UTC (rev 1620)
@@ -176,6 +176,11 @@
<artifactId>exo.ws.frameworks.servlet</artifactId>
<version>${org.exoplatform.ws.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.exoplatform.ws</groupId>
+ <artifactId>exo.ws.rest.core</artifactId>
+ <version>${org.exoplatform.ws.version}</version>
+ </dependency>
<!-- GateIn components -->
<dependency>
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 2010-02-10
17:34:37 UTC (rev 1619)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/ApplicationStatisticService.java 2010-02-10
19:40:15 UTC (rev 1620)
@@ -19,6 +19,8 @@
package org.exoplatform.portal.application;
+import org.exoplatform.management.annotations.Impact;
+import org.exoplatform.management.annotations.ImpactType;
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.annotations.ManagedDescription;
import org.exoplatform.management.annotations.ManagedName;
@@ -38,9 +40,12 @@
* @version $Revision$
*/
@Managed
-@NameTemplate({@Property(key = "view", value = "portal"),
@Property(key = "service", value = "statistic"),
+@ManagedDescription("Application statistic service")
+@NameTemplate({
+ @Property(key = "view", value = "portal"),
+ @Property(key = "service", value = "statistic"),
@Property(key = "type", value = "application")})
-@ManagedDescription("Application statistic service")
+// @Rest("applicationstatistic")
public class ApplicationStatisticService implements Startable
{
@@ -66,8 +71,7 @@
/*
* get ApplicationStatistic by application id, if it isn't exits, create a new
one
*/
- public ApplicationStatistic getApplicationStatistic(
- @ManagedDescription("The application id")
@ManagedName("applicationId") String appId)
+ public ApplicationStatistic getApplicationStatistic(String appId)
{
ApplicationStatistic app = apps.get(appId);
if (app == null)
@@ -87,6 +91,7 @@
*/
@Managed
@ManagedDescription("The maximum execution time of a specified application in
seconds")
+ @Impact(ImpactType.READ)
public double getMaxTime(@ManagedDescription("The application id")
@ManagedName("applicationId") String appId)
{
ApplicationStatistic app = getApplicationStatistic(appId);
@@ -98,6 +103,7 @@
*/
@Managed
@ManagedDescription("The minimum execution time of a specified application in
seconds")
+ @Impact(ImpactType.READ)
public double getMinTime(@ManagedDescription("The application id")
@ManagedName("applicationId") String appId)
{
ApplicationStatistic app = getApplicationStatistic(appId);
@@ -109,6 +115,7 @@
*/
@Managed
@ManagedDescription("Return the average execution time of a specified application
in seconds")
+ @Impact(ImpactType.READ)
public double getAverageTime(@ManagedDescription("The application id")
@ManagedName("applicationId") String appId)
{
ApplicationStatistic app = getApplicationStatistic(appId);
@@ -120,6 +127,7 @@
*/
@Managed
@ManagedDescription("The execution count of a specified application")
+ @Impact(ImpactType.READ)
public long getExecutionCount(@ManagedDescription("The application id")
@ManagedName("applicationId") String appId)
{
ApplicationStatistic app = getApplicationStatistic(appId);
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStatisticService.java
===================================================================
---
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStatisticService.java 2010-02-10
17:34:37 UTC (rev 1619)
+++
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStatisticService.java 2010-02-10
19:40:15 UTC (rev 1620)
@@ -19,6 +19,8 @@
package org.exoplatform.portal.application;
+import org.exoplatform.management.annotations.Impact;
+import org.exoplatform.management.annotations.ImpactType;
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.annotations.ManagedDescription;
import org.exoplatform.management.annotations.ManagedName;
@@ -36,9 +38,12 @@
* @version $Revision$
*/
@Managed
-@NameTemplate({@Property(key = "view", value = "portal"),
@Property(key = "service", value = "statistic"),
+@ManagedDescription("The portal statistic service")
+@NameTemplate({
+ @Property(key = "view", value = "portal"),
+ @Property(key = "service", value = "statistic"),
@Property(key = "type", value = "portal")})
-@ManagedDescription("The portal statistic service")
+// @Rest("portalstatistic")
public class PortalStatisticService implements Startable
{
@@ -94,6 +99,7 @@
*/
@Managed
@ManagedDescription("The maximum execution time of a specified portal in
seconds")
+ @Impact(ImpactType.READ)
public double getMaxTime(@ManagedDescription("The portal id")
@ManagedName("portalId") String id)
{
return toSeconds(getPortalStatistic(id).getMaxTime());
@@ -104,6 +110,7 @@
*/
@Managed
@ManagedDescription("The mininum execution time of a specified portal in
seconds")
+ @Impact(ImpactType.READ)
public double getMinTime(@ManagedDescription("The portal id")
@ManagedName("portalId") String id)
{
return toSeconds(getPortalStatistic(id).getMinTime());
@@ -114,6 +121,7 @@
*/
@Managed
@ManagedDescription("The average execution time of a specified portal in
seconds")
+ @Impact(ImpactType.READ)
public double getAverageTime(@ManagedDescription("The portal id")
@ManagedName("portalId") String id)
{
return toSeconds(getPortalStatistic(id).getAverageTime());
@@ -124,6 +132,7 @@
*/
@Managed
@ManagedDescription("The number of request per second of a specified
portal")
+ @Impact(ImpactType.READ)
public double getThroughput(@ManagedDescription("The portal id")
@ManagedName("portalId") String id)
{
return getPortalStatistic(id).getThroughput();
@@ -134,6 +143,7 @@
*/
@Managed
@ManagedDescription("The execution count of a specified portal")
+ @Impact(ImpactType.READ)
public long getExecutionCount(@ManagedDescription("The portal id")
@ManagedName("portalId") String id)
{
return getPortalStatistic(id).viewCount();