Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4FF3E17E43 for ; Wed, 14 Jan 2015 11:44:00 +0000 (UTC) Received: (qmail 69027 invoked by uid 500); 14 Jan 2015 11:44:02 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 68992 invoked by uid 500); 14 Jan 2015 11:44:02 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 68978 invoked by uid 99); 14 Jan 2015 11:44:02 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Jan 2015 11:44:02 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 14 Jan 2015 11:43:34 +0000 Received: (qmail 67558 invoked by uid 99); 14 Jan 2015 11:43:31 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Jan 2015 11:43:31 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 2FABAA4119E; Wed, 14 Jan 2015 11:43:31 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.incubator.apache.org Date: Wed, 14 Jan 2015 11:43:34 -0000 Message-Id: In-Reply-To: <08ad42d4cf96431ebec75b91bce93b2f@git.apache.org> References: <08ad42d4cf96431ebec75b91bce93b2f@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [04/12] incubator-ignite git commit: ignite-45: wip X-Virus-Checked: Checked by ClamAV on apache.org 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-53 Commit: 5800a75660a534711388367ef9046afb4603d041 Parents: 5190b12 Author: Yakov Zhdanov Authored: Mon Jan 12 09:35:30 2015 +0300 Committer: Yakov Zhdanov 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 igniteMap = new HashMap<>(); + private final Map> 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 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 IgniteCache findCache(String cacheName) { - Ignite ignite; + IgniteBiTuple 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 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 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 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[] 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 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 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 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"); + } + } +}