You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2013/07/16 16:22:22 UTC
svn commit: r1503730 - in
/cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache:
EHCacheIdentityCache.java MemoryIdentityCache.java
MemoryIdentityCacheStatistics.java
Author: dkulp
Date: Tue Jul 16 14:22:22 2013
New Revision: 1503730
URL: http://svn.apache.org/r1503730
Log:
Merged revisions 1503717 via git cherry-pick from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1503717 | dkulp | 2013-07-16 09:49:18 -0400 (Tue, 16 Jul 2013) | 2 lines
Use CXF annotations and such for the management
........
Modified:
cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/EHCacheIdentityCache.java
cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/MemoryIdentityCache.java
cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/MemoryIdentityCacheStatistics.java
Modified: cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/EHCacheIdentityCache.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/EHCacheIdentityCache.java?rev=1503730&r1=1503729&r2=1503730&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/EHCacheIdentityCache.java (original)
+++ cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/EHCacheIdentityCache.java Tue Jul 16 14:22:22 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.cache.EHCacheManagerHolder;
import org.apache.cxf.ws.security.tokenstore.TokenStoreFactory;
import org.apache.ws.security.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) {
@@ -94,7 +108,7 @@ public class EHCacheIdentityCache
public MemoryIdentityCacheStatistics getStatistics() {
if (statistics == null) {
- this.statistics = new MemoryIdentityCacheStatistics();
+ this.statistics = new MemoryIdentityCacheStatistics(bus, this);
}
return statistics;
}
@@ -254,5 +268,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/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/MemoryIdentityCache.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/MemoryIdentityCache.java?rev=1503730&r1=1503729&r2=1503730&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/MemoryIdentityCache.java (original)
+++ cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/MemoryIdentityCache.java Tue Jul 16 14:22:22 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.ws.security.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/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/MemoryIdentityCacheStatistics.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/MemoryIdentityCacheStatistics.java?rev=1503730&r1=1503729&r2=1503730&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/MemoryIdentityCacheStatistics.java (original)
+++ cxf/branches/2.7.x-fixes/services/sts/sts-core/src/main/java/org/apache/cxf/sts/cache/MemoryIdentityCacheStatistics.java Tue Jul 16 14:22:22 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;
+ }
}