cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
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 GMT
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;
+    }
     
 }



Mime
View raw message