ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [24/50] [abbrv] incubator-ignite git commit: ignite-45: wip
Date Mon, 19 Jan 2015 14:21:01 GMT
ignite-45: wip


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/5800a756
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/5800a756
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/5800a756

Branch: refs/heads/ignite-54
Commit: 5800a75660a534711388367ef9046afb4603d041
Parents: 5190b12
Author: Yakov Zhdanov <yzhdanov@gridgain.com>
Authored: Mon Jan 12 09:35:30 2015 +0300
Committer: Yakov Zhdanov <yzhdanov@gridgain.com>
Committed: Mon Jan 12 09:35:30 2015 +0300

----------------------------------------------------------------------
 .../org/apache/ignite/IgniteCacheManager.java   | 107 +++++++++++++---
 .../processors/cache/IgniteCacheProxy.java      |   9 +-
 .../ignite/tck/TCKMBeanServerBuilder.java       | 124 +++++++++++++++++++
 3 files changed, 217 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5800a756/modules/core/src/main/java/org/apache/ignite/IgniteCacheManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteCacheManager.java b/modules/core/src/main/java/org/apache/ignite/IgniteCacheManager.java
index 2f0073f..376c982 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteCacheManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteCacheManager.java
@@ -10,11 +10,14 @@
 package org.apache.ignite;
 
 import org.apache.ignite.configuration.*;
+import org.apache.ignite.lang.*;
 import org.gridgain.grid.cache.*;
+import org.gridgain.grid.util.typedef.*;
 
 import javax.cache.*;
 import javax.cache.configuration.*;
 import javax.cache.spi.*;
+import javax.management.*;
 import java.net.*;
 import java.util.*;
 import java.util.concurrent.atomic.*;
@@ -24,7 +27,7 @@ import java.util.concurrent.atomic.*;
  */
 public class IgniteCacheManager implements CacheManager {
     /** */
-    private final Map<String, Ignite> igniteMap = new HashMap<>();
+    private final Map<String, IgniteBiTuple<Ignite, IgniteCacheMXBean>> igniteMap
= new HashMap<>();
 
     /** */
     private final URI uri;
@@ -45,7 +48,7 @@ public class IgniteCacheManager implements CacheManager {
      * @param uri Uri.
      * @param cachingProvider Caching provider.
      * @param clsLdr Class loader.
-     * @param props
+     * @param props Properties.
      */
     public IgniteCacheManager(URI uri, CachingProvider cachingProvider, ClassLoader clsLdr,
Properties props) {
         this.uri = uri;
@@ -102,12 +105,14 @@ public class IgniteCacheManager implements CacheManager {
             }
         }
 
-        Ignite ignite;
+        IgniteCache<K, V> res;
 
         synchronized (igniteMap) {
             if (igniteMap.containsKey(cacheName))
                 throw new CacheException("Cache already exists [cacheName=" + cacheName +
", manager=" + uri + ']');
 
+            Ignite ignite;
+
             if (uri.equals(cachingProvider.getDefaultURI())) {
                 IgniteConfiguration cfg = new IgniteConfiguration();
                 cfg.setGridName("grid-for-" + cacheName);
@@ -126,26 +131,31 @@ public class IgniteCacheManager implements CacheManager {
             else
                 throw new UnsupportedOperationException();
 
-            igniteMap.put(cacheName, ignite);
+            res = ignite.jcache(cacheName);
+
+            igniteMap.put(cacheName, new T2<>(ignite, new IgniteCacheMXBean(res)));
         }
 
-        return ignite.jcache(cacheName);
+        if (((CompleteConfiguration)cacheCfg).isManagementEnabled())
+            enableManagement(cacheName, true);
+
+        return res;
     }
 
     /**
      * @param cacheName Cache name.
      */
     private <K, V> IgniteCache<K, V> findCache(String cacheName) {
-        Ignite ignite;
+        IgniteBiTuple<Ignite, IgniteCacheMXBean> tuple;
 
         synchronized (igniteMap) {
-            ignite = igniteMap.get(cacheName);
+            tuple = igniteMap.get(cacheName);
         }
 
-        if (ignite == null)
+        if (tuple == null)
             return null;
 
-        return ignite.jcache(cacheName);
+        return tuple.get1().jcache(cacheName);
     }
 
     /** {@inheritDoc} */
@@ -202,8 +212,13 @@ public class IgniteCacheManager implements CacheManager {
      */
     public boolean isManagedIgnite(Ignite ignite) {
         synchronized (igniteMap) {
-            return igniteMap.values().contains(ignite);
+            for (IgniteBiTuple<Ignite, IgniteCacheMXBean> tuple : igniteMap.values())
{
+                if (ignite.equals(tuple.get1()))
+                    return true;
+            }
         }
+
+        return false;
     }
 
     /** {@inheritDoc} */
@@ -213,19 +228,48 @@ public class IgniteCacheManager implements CacheManager {
         if (cacheName == null)
             throw new NullPointerException();
 
-        Ignite ignite;
+        IgniteBiTuple<Ignite, IgniteCacheMXBean> tuple;
 
         synchronized (igniteMap) {
-            ignite = igniteMap.remove(cacheName);
+            tuple = igniteMap.remove(cacheName);
         }
 
-        if (ignite != null) {
+        if (tuple != null) {
             try {
-                ignite.close();
+                tuple.get1().close();
             }
             catch (Exception ignored) {
 
             }
+
+            ObjectName objName = getObjectName(cacheName);
+
+            MBeanServer mBeanSrv = tuple.get1().configuration().getMBeanServer();
+
+            for (ObjectName n : mBeanSrv.queryNames(objName, null)) {
+                try {
+                    mBeanSrv.unregisterMBean(n);
+                }
+                catch (Exception ignored) {
+
+                }
+            }
+        }
+    }
+
+    /**
+     * @param cacheName Cache name.
+     */
+    private ObjectName getObjectName(String cacheName) {
+        String mBeanName = "javax.cache:type=CacheConfiguration,CacheManager="
+            + uri.toString().replaceAll(",|:|=|\n", ".")
+            + ",Cache=" + cacheName.replaceAll(",|:|=|\n", ".");
+
+        try {
+            return new ObjectName(mBeanName);
+        }
+        catch (MalformedObjectNameException e) {
+            throw new CacheException("Failed to create MBean name: " + mBeanName, e);
         }
     }
 
@@ -236,7 +280,32 @@ public class IgniteCacheManager implements CacheManager {
         if (cacheName == null)
             throw new NullPointerException();
 
-        throw new UnsupportedOperationException();
+        IgniteBiTuple<Ignite, IgniteCacheMXBean> tuple;
+
+        synchronized (igniteMap) {
+            tuple = igniteMap.get(cacheName);
+        }
+
+        ObjectName objName = getObjectName(cacheName);
+        MBeanServer mBeanSrv = tuple.get1().configuration().getMBeanServer();
+
+        try {
+            if (enabled) {
+                if(mBeanSrv.queryNames(objName, null).isEmpty())
+                    mBeanSrv.registerMBean(tuple.get2(), objName);
+            }
+            else {
+                for (ObjectName n : mBeanSrv.queryNames(objName, null))
+                    mBeanSrv.unregisterMBean(n);
+
+            }
+        }
+        catch (InstanceAlreadyExistsException | InstanceNotFoundException ignored) {
+
+        }
+        catch (MBeanRegistrationException | NotCompliantMBeanException e) {
+            throw new CacheException(e);
+        }
     }
 
     /** {@inheritDoc} */
@@ -260,15 +329,15 @@ public class IgniteCacheManager implements CacheManager {
     /** {@inheritDoc} */
     @Override public void close() {
         if (closed.compareAndSet(false, true)) {
-            Ignite[] ignites;
+            IgniteBiTuple<Ignite, IgniteCacheMXBean>[] ignites;
 
             synchronized (igniteMap) {
-                ignites = igniteMap.values().toArray(new Ignite[igniteMap.values().size()]);
+                ignites = igniteMap.values().toArray(new IgniteBiTuple[igniteMap.values().size()]);
             }
 
-            for (Ignite ignite : ignites) {
+            for (IgniteBiTuple<Ignite, IgniteCacheMXBean> tuple : ignites) {
                 try {
-                    ignite.close();
+                    tuple.get1().close();
                 }
                 catch (Exception ignored) {
                     // Ignore any exceptions according to javadoc of javax.cache.CacheManager#close()

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5800a756/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
index 7d0bf2d..2f47697 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
@@ -747,6 +747,7 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter
implements
 
     /** {@inheritDoc} */
     @Override public CacheManager getCacheManager() {
+        // TODO IGNITE-45 (Support start/close/destroy cache correctly)
         IgniteCachingProvider provider = (IgniteCachingProvider)Caching.getCachingProvider(
             IgniteCachingProvider.class.getName(),
             IgniteCachingProvider.class.getClassLoader());
@@ -759,14 +760,14 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter
implements
 
     /** {@inheritDoc} */
     @Override public void close() {
-        // TODO IGNITE-1.
-        throw new UnsupportedOperationException();
+        // TODO IGNITE-45 (Support start/close/destroy cache correctly)
+        getCacheManager().destroyCache(getName());
     }
 
     /** {@inheritDoc} */
     @Override public boolean isClosed() {
-        // TODO IGNITE-1.
-        throw new UnsupportedOperationException();
+        // TODO IGNITE-45 (Support start/close/destroy cache correctly)
+        return getCacheManager() == null;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5800a756/modules/core/src/main/java/org/apache/ignite/tck/TCKMBeanServerBuilder.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/tck/TCKMBeanServerBuilder.java b/modules/core/src/main/java/org/apache/ignite/tck/TCKMBeanServerBuilder.java
new file mode 100644
index 0000000..8123504
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/tck/TCKMBeanServerBuilder.java
@@ -0,0 +1,124 @@
+/* @java.file.header */
+
+/*  _________        _____ __________________        _____
+ *  __  ____/___________(_)______  /__  ____/______ ____(_)_______
+ *  _  / __  __  ___/__  / _  __  / _  / __  _  __ `/__  / __  __ \
+ *  / /_/ /  _  /    _  /  / /_/ /  / /_/ /  / /_/ / _  /  _  / / /
+ *  \____/   /_/     /_/   \_,__/   \____/   \__,_/  /_/   /_/ /_/
+ */
+
+package org.apache.ignite.tck;
+
+import com.sun.jmx.mbeanserver.*;
+
+import javax.management.*;
+
+/**
+ *
+ */
+public class TCKMBeanServerBuilder extends MBeanServerBuilder {
+    /** {@inheritDoc} */
+    @Override public MBeanServer newMBeanServer(String dfltDomain, MBeanServer outer, MBeanServerDelegate
delegate) {
+        MBeanServerDelegate decoratingDelegate = new ServerDelegate(delegate);
+        return JmxMBeanServer.newMBeanServer(dfltDomain, outer,
+            decoratingDelegate, false);
+    }
+
+    /**
+     *
+     */
+    private static class ServerDelegate extends MBeanServerDelegate {
+        /** */
+        private final MBeanServerDelegate delegate;
+
+        /**
+         * Constructor
+         *
+         * @param delegate the provided delegate
+         */
+        ServerDelegate(MBeanServerDelegate delegate) {
+            this.delegate = delegate;
+        }
+
+        /** {@inheritDoc} */
+        @Override public String getSpecificationName() {
+            return delegate.getSpecificationName();
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public String getSpecificationVersion() {
+            return delegate.getSpecificationVersion();
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public String getSpecificationVendor() {
+            return delegate.getSpecificationVendor();
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public String getImplementationName() {
+            return delegate.getImplementationName();
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public String getImplementationVersion() {
+            return delegate.getImplementationVersion();
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public String getImplementationVendor() {
+            return delegate.getImplementationVendor();
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public MBeanNotificationInfo[] getNotificationInfo() {
+            return delegate.getNotificationInfo();
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public synchronized void addNotificationListener(NotificationListener listener,
+                                                         NotificationFilter filter,
+                                                         Object handback) throws
+            IllegalArgumentException {
+            delegate.addNotificationListener(listener, filter, handback);
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public synchronized void removeNotificationListener(NotificationListener
+                                                                listener,
+                                                            NotificationFilter
+                                                                filter,
+                                                            Object handback) throws
+            ListenerNotFoundException {
+            delegate.removeNotificationListener(listener, filter, handback);
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public synchronized void removeNotificationListener(NotificationListener
+                                                                listener) throws
+            ListenerNotFoundException {
+            delegate.removeNotificationListener(listener);
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public void sendNotification(Notification notification) {
+            delegate.sendNotification(notification);
+        }
+
+        /** {@inheritDoc} */
+        @Override
+        public synchronized String getMBeanServerId() {
+            return System.getProperty("org.jsr107.tck.management.agentId");
+        }
+    }
+}


Mime
View raw message