Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DD632C19A for ; Tue, 16 Jul 2013 13:49:41 +0000 (UTC) Received: (qmail 50006 invoked by uid 500); 16 Jul 2013 13:49:41 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 49949 invoked by uid 500); 16 Jul 2013 13:49:41 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 49942 invoked by uid 99); 16 Jul 2013 13:49:41 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Jul 2013 13:49:41 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Jul 2013 13:49:39 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id DE60623889DA; Tue, 16 Jul 2013 13:49:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1503717 - in /cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache: EHCacheIdentityCache.java MemoryIdentityCache.java MemoryIdentityCacheStatistics.java Date: Tue, 16 Jul 2013 13:49:18 -0000 To: commits@cxf.apache.org From: dkulp@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130716134918.DE60623889DA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dkulp Date: Tue Jul 16 13:49:18 2013 New Revision: 1503717 URL: http://svn.apache.org/r1503717 Log: Use CXF annotations and such for the management Modified: cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/EHCacheIdentityCache.java cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/MemoryIdentityCache.java cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/MemoryIdentityCacheStatistics.java Modified: cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/EHCacheIdentityCache.java URL: http://svn.apache.org/viewvc/cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/EHCacheIdentityCache.java?rev=1503717&r1=1503716&r2=1503717&view=diff ============================================================================== --- cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/EHCacheIdentityCache.java (original) +++ cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/EHCacheIdentityCache.java Tue Jul 16 13:49:18 2013 @@ -28,6 +28,9 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; +import javax.management.JMException; +import javax.management.ObjectName; + import net.sf.ehcache.Cache; import net.sf.ehcache.CacheManager; import net.sf.ehcache.Ehcache; @@ -39,13 +42,16 @@ import org.apache.cxf.buslifecycle.BusLi import org.apache.cxf.buslifecycle.BusLifeCycleManager; import org.apache.cxf.common.classloader.ClassLoaderUtils; import org.apache.cxf.common.logging.LogUtils; +import org.apache.cxf.management.InstrumentationManager; +import org.apache.cxf.management.ManagedComponent; +import org.apache.cxf.management.ManagementConstants; +import org.apache.cxf.management.annotation.ManagedOperation; +import org.apache.cxf.management.annotation.ManagedResource; import org.apache.cxf.resource.ResourceManager; import org.apache.cxf.sts.IdentityMapper; import org.apache.cxf.ws.security.tokenstore.TokenStoreFactory; import org.apache.wss4j.common.cache.EHCacheManagerHolder; import org.apache.wss4j.common.principal.CustomTokenPrincipal; -import org.springframework.jmx.export.annotation.ManagedOperation; -import org.springframework.jmx.export.annotation.ManagedResource; /** * A EH-Cache based cache to cache identities in different realms where @@ -53,7 +59,7 @@ import org.springframework.jmx.export.an */ @ManagedResource() public class EHCacheIdentityCache - implements IdentityCache, IdentityMapper, Closeable, BusLifeCycleListener { + implements IdentityCache, IdentityMapper, Closeable, BusLifeCycleListener, ManagedComponent { private static final Logger LOG = LogUtils.getL7dLogger(EHCacheIdentityCache.class); @@ -78,6 +84,14 @@ public class EHCacheIdentityCache bus = b; if (bus != null) { b.getExtension(BusLifeCycleManager.class).registerLifeCycleListener(this); + InstrumentationManager im = b.getExtension(InstrumentationManager.class); + if (im != null) { + try { + im.register(this); + } catch (JMException e) { + LOG.log(Level.WARNING, "Registering EHCacheIdentityCache failed.", e); + } + } } if (configFileURL != null) { @@ -93,7 +107,7 @@ public class EHCacheIdentityCache public MemoryIdentityCacheStatistics getStatistics() { if (statistics == null) { - this.statistics = new MemoryIdentityCacheStatistics(); + this.statistics = new MemoryIdentityCacheStatistics(bus, this); } return statistics; } @@ -253,5 +267,15 @@ public class EHCacheIdentityCache } return null; } + + public ObjectName getObjectName() throws JMException { + StringBuilder buffer = new StringBuilder(); + buffer.append(ManagementConstants.DEFAULT_DOMAIN_NAME).append(':'); + buffer.append(ManagementConstants.BUS_ID_PROP).append('=').append(bus.getId()).append(','); + buffer.append(ManagementConstants.TYPE_PROP).append('=').append("EHCacheIdentityCache").append(','); + buffer.append(ManagementConstants.NAME_PROP).append('=') + .append("EHCacheIdentityCache-" + System.identityHashCode(this)); + return new ObjectName(buffer.toString()); + } } Modified: cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/MemoryIdentityCache.java URL: http://svn.apache.org/viewvc/cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/MemoryIdentityCache.java?rev=1503717&r1=1503716&r2=1503717&view=diff ============================================================================== --- cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/MemoryIdentityCache.java (original) +++ cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/MemoryIdentityCache.java Tue Jul 16 13:49:18 2013 @@ -26,18 +26,25 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; +import javax.management.JMException; +import javax.management.ObjectName; + +import org.apache.cxf.Bus; import org.apache.cxf.common.logging.LogUtils; +import org.apache.cxf.management.InstrumentationManager; +import org.apache.cxf.management.ManagedComponent; +import org.apache.cxf.management.ManagementConstants; +import org.apache.cxf.management.annotation.ManagedOperation; +import org.apache.cxf.management.annotation.ManagedResource; import org.apache.cxf.sts.IdentityMapper; import org.apache.wss4j.common.principal.CustomTokenPrincipal; -import org.springframework.jmx.export.annotation.ManagedOperation; -import org.springframework.jmx.export.annotation.ManagedResource; /** * A simple in-memory HashMap based cache to cache identities in different realms where * the relationship is of type FederateIdentity. */ @ManagedResource() -public class MemoryIdentityCache implements IdentityCache, IdentityMapper { +public class MemoryIdentityCache implements IdentityCache, IdentityMapper, ManagedComponent { private static final Logger LOG = LogUtils.getL7dLogger(MemoryIdentityCache.class); @@ -47,21 +54,37 @@ public class MemoryIdentityCache impleme private long maxCacheItems = 10000L; private IdentityMapper identityMapper; + private final Bus bus; private MemoryIdentityCacheStatistics statistics; protected MemoryIdentityCache() { - + this.bus = null; } public MemoryIdentityCache(IdentityMapper identityMapper) { this.identityMapper = identityMapper; + this.bus = null; + } + public MemoryIdentityCache(Bus bus, IdentityMapper identityMapper) { + this.identityMapper = identityMapper; + this.bus = bus; + if (bus != null) { + InstrumentationManager im = bus.getExtension(InstrumentationManager.class); + if (im != null) { + try { + im.register(this); + } catch (JMException e) { + LOG.log(Level.WARNING, "Registering MemoryIdentityCache failed.", e); + } + } + } } public MemoryIdentityCacheStatistics getStatistics() { if (statistics == null) { - this.statistics = new MemoryIdentityCacheStatistics(); + this.statistics = new MemoryIdentityCacheStatistics(bus, this); } return statistics; } @@ -187,5 +210,15 @@ public class MemoryIdentityCache impleme from.put(key, to.get(key)); } } + + public ObjectName getObjectName() throws JMException { + StringBuilder buffer = new StringBuilder(); + buffer.append(ManagementConstants.DEFAULT_DOMAIN_NAME).append(':'); + buffer.append(ManagementConstants.BUS_ID_PROP).append('=').append(bus.getId()).append(','); + buffer.append(ManagementConstants.TYPE_PROP).append('=').append("MemoryIdentityCache").append(','); + buffer.append(ManagementConstants.NAME_PROP).append('=') + .append("MemoryIdentityCache-" + System.identityHashCode(this)); + return new ObjectName(buffer.toString()); + } } Modified: cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/MemoryIdentityCacheStatistics.java URL: http://svn.apache.org/viewvc/cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/MemoryIdentityCacheStatistics.java?rev=1503717&r1=1503716&r2=1503717&view=diff ============================================================================== --- cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/MemoryIdentityCacheStatistics.java (original) +++ cxf/trunk/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/MemoryIdentityCacheStatistics.java Tue Jul 16 13:49:18 2013 @@ -18,15 +18,57 @@ */ package org.apache.cxf.sts.cache; -import org.springframework.jmx.export.annotation.ManagedAttribute; -import org.springframework.jmx.export.annotation.ManagedResource; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.management.JMException; +import javax.management.ObjectName; + +import org.apache.cxf.Bus; +import org.apache.cxf.common.logging.LogUtils; +import org.apache.cxf.management.InstrumentationManager; +import org.apache.cxf.management.ManagedComponent; +import org.apache.cxf.management.ManagementConstants; +import org.apache.cxf.management.annotation.ManagedAttribute; +import org.apache.cxf.management.annotation.ManagedResource; @ManagedResource() -public class MemoryIdentityCacheStatistics { +public class MemoryIdentityCacheStatistics implements ManagedComponent { + private static final Logger LOG = LogUtils.getL7dLogger(MemoryIdentityCacheStatistics.class); private long cacheMiss; private long cacheHit; + private ObjectName objectName; + public MemoryIdentityCacheStatistics() { + } + + public MemoryIdentityCacheStatistics(Bus bus, ManagedComponent parent) { + if (bus != null) { + InstrumentationManager im = bus.getExtension(InstrumentationManager.class); + if (im != null) { + try { + StringBuilder buffer = new StringBuilder(); + ObjectName pname = parent.getObjectName(); + String pn = pname.getKeyProperty(ManagementConstants.NAME_PROP); + String pt = pname.getKeyProperty(ManagementConstants.TYPE_PROP); + buffer.append(ManagementConstants.DEFAULT_DOMAIN_NAME).append(':') + .append(ManagementConstants.BUS_ID_PROP).append('=').append(bus.getId()).append(',') + .append(pt).append('=').append(pn).append(',') + .append(ManagementConstants.TYPE_PROP).append('=') + .append("MemoryIdentityCacheStatistics").append(',') + .append(ManagementConstants.NAME_PROP).append('=') + .append("MemoryIdentityCacheStatistics-" + System.identityHashCode(this)); + objectName = new ObjectName(buffer.toString()); + + im.register(this); + } catch (JMException e) { + LOG.log(Level.WARNING, "Registering MemoryIdentityCacheStatistics failed.", e); + } + } + } + } + @ManagedAttribute() public synchronized long getCacheMiss() { return cacheMiss; @@ -44,5 +86,9 @@ public class MemoryIdentityCacheStatisti protected synchronized void increaseCacheMiss() { cacheMiss++; } + + public ObjectName getObjectName() throws JMException { + return objectName; + } }