You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sirona.apache.org by rm...@apache.org on 2013/11/21 14:46:28 UTC

svn commit: r1544178 - in /incubator/sirona/trunk: ./ server/plugins/ server/plugins/ehcache/ server/plugins/ehcache/agent/ server/plugins/ehcache/agent/src/ server/plugins/ehcache/agent/src/main/ server/plugins/ehcache/agent/src/main/java/ server/plug...

Author: rmannibucau
Date: Thu Nov 21 13:46:27 2013
New Revision: 1544178

URL: http://svn.apache.org/r1544178
Log:
SIRONA-6 basic EhCache integration

Added:
    incubator/sirona/trunk/server/plugins/ehcache/
    incubator/sirona/trunk/server/plugins/ehcache/agent/
    incubator/sirona/trunk/server/plugins/ehcache/agent/pom.xml
      - copied, changed from r1544045, incubator/sirona/trunk/server/plugins/hazelcast/agent/pom.xml
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheCacheGauge.java
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheCachesCountManagerGauge.java
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheGaugeFactory.java
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheManagerGaugeBase.java
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheTransactionCommittedCountManagerGauge.java
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheTransactionRollbackedCountManagerGauge.java
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/resources/
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/resources/META-INF/
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/resources/META-INF/services/
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/resources/META-INF/services/org.apache.sirona.gauges.GaugeFactory
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/test/
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/test/java/
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/test/java/org/
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/test/java/org/apache/
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/test/java/org/apache/sirona/
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/test/java/org/apache/sirona/agent/
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/test/java/org/apache/sirona/agent/ehcache/
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/test/java/org/apache/sirona/agent/ehcache/EhCacheGaugesTest.java
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/test/resources/
    incubator/sirona/trunk/server/plugins/ehcache/agent/src/test/resources/ehcache.xml
    incubator/sirona/trunk/server/plugins/ehcache/pom.xml
Modified:
    incubator/sirona/trunk/pom.xml
    incubator/sirona/trunk/server/plugins/pom.xml

Modified: incubator/sirona/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/pom.xml?rev=1544178&r1=1544177&r2=1544178&view=diff
==============================================================================
--- incubator/sirona/trunk/pom.xml (original)
+++ incubator/sirona/trunk/pom.xml Thu Nov 21 13:46:27 2013
@@ -54,6 +54,7 @@
     <tomcat.version>7.0.47</tomcat.version>
     <arquillian.version>1.0.3.Final</arquillian.version> <!-- for tomcat adapter -->
     <openejb.version>4.5.2</openejb.version>
+    <slf4j.version>1.7.5</slf4j.version>
   </properties>
 
   <modules>
@@ -299,12 +300,21 @@
 
   <dependencyManagement>
     <dependencies>
+      <!-- we rely on JUL but some dependencies can need slf4j, ex: EhCache -->
       <dependency>
-        <groupId>org.apache.commons</groupId>
-        <artifactId>commons-math3</artifactId>
-        <version>3.2</version>
+        <groupId>org.slf4j</groupId>
+        <artifactId>slf4j-api</artifactId>
+        <version>${slf4j.version}</version>
+        <scope>provided</scope>
       </dependency>
       <dependency>
+        <groupId>org.slf4j</groupId>
+        <artifactId>slf4j-jdk14</artifactId>
+        <version>${slf4j.version}</version>
+        <scope>provided</scope>
+      </dependency>
+
+      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>4.11</version>

Copied: incubator/sirona/trunk/server/plugins/ehcache/agent/pom.xml (from r1544045, incubator/sirona/trunk/server/plugins/hazelcast/agent/pom.xml)
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/plugins/ehcache/agent/pom.xml?p2=incubator/sirona/trunk/server/plugins/ehcache/agent/pom.xml&p1=incubator/sirona/trunk/server/plugins/hazelcast/agent/pom.xml&r1=1544045&r2=1544178&rev=1544178&view=diff
==============================================================================
--- incubator/sirona/trunk/server/plugins/hazelcast/agent/pom.xml (original)
+++ incubator/sirona/trunk/server/plugins/ehcache/agent/pom.xml Thu Nov 21 13:46:27 2013
@@ -19,15 +19,15 @@
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <parent>
-    <artifactId>sirona-hazelcast</artifactId>
+    <artifactId>sirona-ehcache</artifactId>
     <groupId>org.apache.sirona</groupId>
     <version>0.1-incubating-SNAPSHOT</version>
   </parent>
 
   <modelVersion>4.0.0</modelVersion>
 
-  <artifactId>sirona-hazelcast-agent</artifactId>
-  <name>Apache Sirona Incubator :: Server :: Plugins :: Hazelcast :: Agent</name>
+  <artifactId>sirona-ehcache-agent</artifactId>
+  <name>Apache Sirona Incubator :: Server :: Plugins :: EhCache :: Agent</name>
 
   <dependencies>
     <dependency>
@@ -35,12 +35,16 @@
       <artifactId>sirona-core</artifactId>
     </dependency>
     <dependency>
-      <groupId>com.hazelcast</groupId>
-      <artifactId>hazelcast</artifactId>
+      <groupId>net.sf.ehcache</groupId>
+      <artifactId>ehcache</artifactId>
     </dependency>
     <dependency>
-      <groupId>com.hazelcast</groupId>
-      <artifactId>hazelcast-client</artifactId>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-jdk14</artifactId>
     </dependency>
 
     <dependency>

Added: incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheCacheGauge.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheCacheGauge.java?rev=1544178&view=auto
==============================================================================
--- incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheCacheGauge.java (added)
+++ incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheCacheGauge.java Thu Nov 21 13:46:27 2013
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sirona.agent.ehcache;
+
+import net.sf.ehcache.CacheManager;
+import org.apache.sirona.SironaException;
+
+import java.lang.reflect.Method;
+
+public class EhCacheCacheGauge extends EhCacheManagerGaugeBase {
+    private final String cache;
+    private final Method method;
+
+    public EhCacheCacheGauge(final Method method, final CacheManager cacheManager, final String cache) {
+        super(method.getName(), cacheManager);
+        this.cache = cache;
+        this.method = method;
+    }
+
+    @Override
+    public double value() {
+        try {
+            return Number.class.cast(method.invoke(manager.getCache(cache).getStatistics())).doubleValue();
+        } catch (final Exception e) {
+            throw new SironaException(e);
+        }
+    }
+
+    @Override
+    public String toString() {
+        return "EhCacheCacheGauge{" +
+            "cache='" + cache + '\'' +
+            ", method=" + method.getName() +
+            '}';
+    }
+}

Added: incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheCachesCountManagerGauge.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheCachesCountManagerGauge.java?rev=1544178&view=auto
==============================================================================
--- incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheCachesCountManagerGauge.java (added)
+++ incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheCachesCountManagerGauge.java Thu Nov 21 13:46:27 2013
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sirona.agent.ehcache;
+
+import net.sf.ehcache.CacheException;
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Status;
+import net.sf.ehcache.event.CacheManagerEventListener;
+import net.sf.ehcache.statistics.FlatStatistics;
+import org.apache.sirona.gauges.Gauge;
+import org.apache.sirona.repositories.Repository;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class EhCacheCachesCountManagerGauge extends EhCacheManagerGaugeBase {
+    public EhCacheCachesCountManagerGauge(final CacheManager cacheManager) {
+        super("caches-count", cacheManager);
+        cacheManager.getCacheManagerEventListenerRegistry().registerListener(new DynamicCacheGauges(cacheManager));
+    }
+
+    @Override
+    public double value() {
+        return manager.getCacheNames().length;
+    }
+
+    private static class DynamicCacheGauges implements CacheManagerEventListener {
+        private final CacheManager manager;
+        private final Map<String, Collection<Gauge>> children = new ConcurrentHashMap<String, Collection<Gauge>>();
+
+        public DynamicCacheGauges(final CacheManager cacheManager) {
+            this.manager = cacheManager;
+        }
+
+        @Override
+        public void init() throws CacheException {
+            // no-op
+        }
+
+        @Override
+        public Status getStatus() {
+            return manager.getStatus();
+        }
+
+        @Override
+        public void dispose() throws CacheException {
+            for (final String gauge : children.keySet()) {
+                notifyCacheRemoved(gauge);
+            }
+        }
+
+        @Override
+        public void notifyCacheAdded(final String cacheName) {
+            final Collection<Gauge> gauges = new ArrayList<Gauge>();
+            for (final Method m : FlatStatistics.class.getMethods()) {
+                final Class<?> returnType = m.getReturnType();
+                final String name = m.getName();
+                if (m.getParameterTypes().length == 0 &&
+                    (returnType.equals(Long.TYPE) || returnType.equals(Double.TYPE))
+                    && !name.startsWith("get") && !name.startsWith("local") && !name.startsWith("xa")) {
+                    gauges.add(new EhCacheCacheGauge(m, manager, cacheName));
+                }
+            }
+            children.put(cacheName, gauges);
+        }
+
+        @Override
+        public void notifyCacheRemoved(final String cacheName) {
+            final Collection<Gauge> gauges = children.remove(cacheName);
+            if (gauges != null) {
+                for (final Gauge gauge : gauges) {
+                    Repository.INSTANCE.stopGauge(gauge);
+                }
+            }
+        }
+    }
+}

Added: incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheGaugeFactory.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheGaugeFactory.java?rev=1544178&view=auto
==============================================================================
--- incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheGaugeFactory.java (added)
+++ incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheGaugeFactory.java Thu Nov 21 13:46:27 2013
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sirona.agent.ehcache;
+
+import net.sf.ehcache.CacheManager;
+import org.apache.sirona.configuration.Configuration;
+import org.apache.sirona.gauges.Gauge;
+import org.apache.sirona.gauges.GaugeFactory;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+public class EhCacheGaugeFactory implements GaugeFactory {
+    @Override
+    public Gauge[] gauges() {
+        if (!Configuration.is(Configuration.CONFIG_PROPERTY_PREFIX + "ehcache.activated", true)) {
+            return null;
+        }
+
+        try {
+            final Field list = CacheManager.class.getDeclaredField("ALL_CACHE_MANAGERS");
+            list.setAccessible(true);
+            final List<CacheManager> managers = List.class.cast(list.get(null));
+
+            final Collection<Gauge> gauges = new ArrayList<Gauge>(managers.size() * 3);
+            for (final CacheManager manager : managers) {
+                gauges.addAll(register(manager));
+            }
+            return gauges.toArray(new Gauge[gauges.size()]);
+        } catch (final Exception e) {
+            return null;
+        }
+    }
+
+    // utility method user can reuse for custom managers
+    public static Collection<Gauge> register(final CacheManager manager) {
+        return Arrays.<Gauge>asList(
+            new EhCacheCachesCountManagerGauge(manager),
+            new EhCacheTransactionCommittedCountManagerGauge(manager),
+            new EhCacheTransactionRollbackedCountManagerGauge(manager)
+        );
+    }
+}

Added: incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheManagerGaugeBase.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheManagerGaugeBase.java?rev=1544178&view=auto
==============================================================================
--- incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheManagerGaugeBase.java (added)
+++ incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheManagerGaugeBase.java Thu Nov 21 13:46:27 2013
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sirona.agent.ehcache;
+
+import net.sf.ehcache.CacheManager;
+import org.apache.sirona.Role;
+import org.apache.sirona.counters.Unit;
+import org.apache.sirona.gauges.Gauge;
+
+public abstract class EhCacheManagerGaugeBase implements Gauge {
+    private final Role role;
+    protected final CacheManager manager;
+
+    public EhCacheManagerGaugeBase(final String gauge, final CacheManager cacheManager) {
+        this.role = new Role("ehcache-" + cacheManager.getName() + "-" + gauge, Unit.UNARY);
+        this.manager = cacheManager;
+    }
+
+    @Override
+    public Role role() {
+        return role;
+    }
+}

Added: incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheTransactionCommittedCountManagerGauge.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheTransactionCommittedCountManagerGauge.java?rev=1544178&view=auto
==============================================================================
--- incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheTransactionCommittedCountManagerGauge.java (added)
+++ incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheTransactionCommittedCountManagerGauge.java Thu Nov 21 13:46:27 2013
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sirona.agent.ehcache;
+
+import net.sf.ehcache.CacheManager;
+
+public class EhCacheTransactionCommittedCountManagerGauge extends EhCacheManagerGaugeBase {
+    public EhCacheTransactionCommittedCountManagerGauge(final CacheManager cacheManager) {
+        super("transaction-committed", cacheManager);
+    }
+
+    @Override
+    public double value() {
+        return manager.getTransactionController().getTransactionCommittedCount();
+    }
+}

Added: incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheTransactionRollbackedCountManagerGauge.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheTransactionRollbackedCountManagerGauge.java?rev=1544178&view=auto
==============================================================================
--- incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheTransactionRollbackedCountManagerGauge.java (added)
+++ incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/java/org/apache/sirona/agent/ehcache/EhCacheTransactionRollbackedCountManagerGauge.java Thu Nov 21 13:46:27 2013
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sirona.agent.ehcache;
+
+import net.sf.ehcache.CacheManager;
+
+public class EhCacheTransactionRollbackedCountManagerGauge extends EhCacheManagerGaugeBase {
+    public EhCacheTransactionRollbackedCountManagerGauge(final CacheManager cacheManager) {
+        super("transaction-rollbacked", cacheManager);
+    }
+
+    @Override
+    public double value() {
+        return manager.getTransactionController().getTransactionRolledBackCount();
+    }
+}

Added: incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/resources/META-INF/services/org.apache.sirona.gauges.GaugeFactory
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/resources/META-INF/services/org.apache.sirona.gauges.GaugeFactory?rev=1544178&view=auto
==============================================================================
--- incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/resources/META-INF/services/org.apache.sirona.gauges.GaugeFactory (added)
+++ incubator/sirona/trunk/server/plugins/ehcache/agent/src/main/resources/META-INF/services/org.apache.sirona.gauges.GaugeFactory Thu Nov 21 13:46:27 2013
@@ -0,0 +1 @@
+org.apache.sirona.agent.ehcache.EhCacheGaugeFactory

Added: incubator/sirona/trunk/server/plugins/ehcache/agent/src/test/java/org/apache/sirona/agent/ehcache/EhCacheGaugesTest.java
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/plugins/ehcache/agent/src/test/java/org/apache/sirona/agent/ehcache/EhCacheGaugesTest.java?rev=1544178&view=auto
==============================================================================
--- incubator/sirona/trunk/server/plugins/ehcache/agent/src/test/java/org/apache/sirona/agent/ehcache/EhCacheGaugesTest.java (added)
+++ incubator/sirona/trunk/server/plugins/ehcache/agent/src/test/java/org/apache/sirona/agent/ehcache/EhCacheGaugesTest.java Thu Nov 21 13:46:27 2013
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sirona.agent.ehcache;
+
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Element;
+import net.sf.ehcache.config.Configuration;
+import org.apache.sirona.gauges.Gauge;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.lang.reflect.Field;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class EhCacheGaugesTest {
+    private CacheManager mgr;
+
+    @Before
+    public void createManager() {
+        mgr = new CacheManager();
+    }
+
+    @After
+    public void shutdownManager() {
+        mgr.shutdown();
+    }
+
+    @Test
+    public void register() {
+        assertEquals(3, EhCacheGaugeFactory.register(mgr).size());
+    }
+
+    @Test
+    public void factory() {
+        assertEquals(3, new EhCacheGaugeFactory().gauges().length);
+        new CacheManager(new Configuration().name("other"));
+        assertEquals(6, new EhCacheGaugeFactory().gauges().length);
+    }
+
+    @Test
+    public void ehCacheCachesCountManagerGauge() {
+        final Gauge gauge = new EhCacheCachesCountManagerGauge(mgr);
+        assertEquals(0., gauge.value(), 0.);
+        mgr.addCacheIfAbsent("cache1");
+        assertEquals(1., gauge.value(), 0.);
+        mgr.addCacheIfAbsent("cache2");
+        assertEquals(2., gauge.value(), 0.);
+        mgr.removeCache("cache1");
+        assertEquals(1., gauge.value(), 0.);
+    }
+
+    @Test
+    public void cacheGauges() throws Exception {
+        new EhCacheCachesCountManagerGauge(mgr);
+
+        final Set<?> registeredListeners = mgr.getCacheManagerEventListenerRegistry().getRegisteredListeners();
+        assertEquals(1, registeredListeners.size());
+        final Object listener = registeredListeners.iterator().next();
+        final Map<String, Collection<Gauge>> gauges = getField(listener, "children");
+        assertTrue(gauges.isEmpty());
+
+        mgr.addCache("cache1");
+        assertEquals(1, gauges.size());
+        for (final Gauge g : gauges.values().iterator().next()) {
+            if (g.role().getName().equals("ehcache-__DEFAULT__-cacheHitCount")) {
+                assertEquals(0., g.value(), 0.);
+                mgr.getCache("cache1").put(new Element("k", "v", 0));
+                mgr.getCache("cache1").get("k");
+                mgr.getCache("cache1").get("k");
+                assertEquals(2., g.value(), 0.);
+                return;
+            }
+        }
+        fail("gauge not found");
+    }
+
+    @Test
+    public void cacheGaugesUnregister() throws Exception {
+        new EhCacheCachesCountManagerGauge(mgr);
+
+        final Map<String, Collection<Gauge>> gauges = getField(mgr.getCacheManagerEventListenerRegistry().getRegisteredListeners().iterator().next(), "children");
+
+        mgr.addCache("cache1");
+        assertEquals(1, gauges.size());
+        mgr.removeCache("cache1");
+        assertEquals(0, gauges.size());
+    }
+
+    @Test
+    public void ehCacheTransactionCommittedCountManagerGauge() {
+        final Gauge gauge = new EhCacheTransactionCommittedCountManagerGauge(mgr);
+        assertEquals(0., gauge.value(), 0.);
+        mgr.getTransactionController().begin();
+        mgr.getTransactionController().commit();
+        assertEquals(1., gauge.value(), 0.);
+    }
+
+    @Test
+    public void ehCacheTransactionRollbackedCountManagerGauge() {
+        final Gauge gauge = new EhCacheTransactionRollbackedCountManagerGauge(mgr);
+        assertEquals(0., gauge.value(), 0.);
+        mgr.getTransactionController().begin();
+        mgr.getTransactionController().rollback();
+        assertEquals(1., gauge.value(), 0.);
+    }
+
+    private static Map<String, Collection<Gauge>> getField(final Object listener, final String children) throws Exception {
+        final Field field = listener.getClass().getDeclaredField(children);
+        field.setAccessible(true);
+        return (Map<String, Collection<Gauge>>) field.get(listener);
+    }
+}

Added: incubator/sirona/trunk/server/plugins/ehcache/agent/src/test/resources/ehcache.xml
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/plugins/ehcache/agent/src/test/resources/ehcache.xml?rev=1544178&view=auto
==============================================================================
--- incubator/sirona/trunk/server/plugins/ehcache/agent/src/test/resources/ehcache.xml (added)
+++ incubator/sirona/trunk/server/plugins/ehcache/agent/src/test/resources/ehcache.xml Thu Nov 21 13:46:27 2013
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:noNamespaceSchemaLocation="../config/ehcache.xsd">
+  <diskStore path="java.io.tmpdir"/>
+
+  <defaultCache
+    maxElementsInMemory="10000"
+    eternal="false"
+    timeToIdleSeconds="120"
+    timeToLiveSeconds="120"
+    maxElementsOnDisk="10000000"
+    diskExpiryThreadIntervalSeconds="120"
+    memoryStoreEvictionPolicy="LRU">
+    <persistence strategy="localTempSwap"/>
+  </defaultCache>
+</ehcache>

Added: incubator/sirona/trunk/server/plugins/ehcache/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/plugins/ehcache/pom.xml?rev=1544178&view=auto
==============================================================================
--- incubator/sirona/trunk/server/plugins/ehcache/pom.xml (added)
+++ incubator/sirona/trunk/server/plugins/ehcache/pom.xml Thu Nov 21 13:46:27 2013
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <parent>
+    <artifactId>sirona-plugins</artifactId>
+    <groupId>org.apache.sirona</groupId>
+    <version>0.1-incubating-SNAPSHOT</version>
+  </parent>
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>sirona-ehcache</artifactId>
+  <name>Apache Sirona Incubator :: Server :: Plugins :: EhCache</name>
+  <packaging>pom</packaging>
+
+  <modules>
+    <module>agent</module>
+  </modules>
+
+  <dependencyManagement>
+    <dependencies>
+      <dependency>
+        <groupId>net.sf.ehcache</groupId>
+        <artifactId>ehcache</artifactId>
+        <version>${ehcache.version}</version>
+        <scope>provided</scope>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
+
+  <properties>
+    <ehcache.version>2.7.4</ehcache.version>
+  </properties>
+</project>

Modified: incubator/sirona/trunk/server/plugins/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sirona/trunk/server/plugins/pom.xml?rev=1544178&r1=1544177&r2=1544178&view=diff
==============================================================================
--- incubator/sirona/trunk/server/plugins/pom.xml (original)
+++ incubator/sirona/trunk/server/plugins/pom.xml Thu Nov 21 13:46:27 2013
@@ -34,5 +34,6 @@
     <module>tomee</module>
     <module>api</module>
     <module>hazelcast</module>
+    <module>ehcache</module>
   </modules>
 </project>