brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [2/6] git commit: Adds JmxHelper.terminate()
Date Tue, 05 Aug 2014 20:43:52 GMT
Adds JmxHelper.terminate()

- important for entity stop(), if a connect attempt is taking a very
  long time to timeout and there are other jobs backing up.


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/683bbbde
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/683bbbde
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/683bbbde

Branch: refs/heads/master
Commit: 683bbbde979d7dd2e523aebd675f6bb49fee5828
Parents: 46bf6ff
Author: Aled Sage <aled.sage@gmail.com>
Authored: Fri Jul 18 14:46:11 2014 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Tue Aug 5 16:08:18 2014 +0100

----------------------------------------------------------------------
 .../entity/database/derby/DerbyDatabase.java    |  2 +-
 .../java/brooklyn/event/feed/jmx/JmxFeed.java   |  2 +-
 .../java/brooklyn/event/feed/jmx/JmxHelper.java | 49 +++++++++++++++++---
 .../entity/messaging/kafka/KafkaBrokerImpl.java |  2 +-
 .../entity/messaging/qpid/QpidBrokerImpl.java   |  2 +-
 .../entity/messaging/storm/StormImpl.java       |  2 +-
 .../entity/zookeeper/AbstractZooKeeperImpl.java |  2 +-
 .../nosql/cassandra/CassandraNodeImpl.java      |  2 +-
 .../entity/osgi/karaf/KarafContainerImpl.java   |  2 +-
 9 files changed, 51 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/683bbbde/sandbox/database/src/main/java/brooklyn/entity/database/derby/DerbyDatabase.java
----------------------------------------------------------------------
diff --git a/sandbox/database/src/main/java/brooklyn/entity/database/derby/DerbyDatabase.java
b/sandbox/database/src/main/java/brooklyn/entity/database/derby/DerbyDatabase.java
index ec492bd..5143e36 100644
--- a/sandbox/database/src/main/java/brooklyn/entity/database/derby/DerbyDatabase.java
+++ b/sandbox/database/src/main/java/brooklyn/entity/database/derby/DerbyDatabase.java
@@ -127,7 +127,7 @@ public class DerbyDatabase extends SoftwareProcessImpl implements Database,
Uses
         for (DerbySchema schema : schemas.values()) {
             schema.destroy();
         }
-        if (jmxHelper != null) jmxHelper.disconnect();
+        if (jmxHelper != null) jmxHelper.terminate();
     }
 
     public void createSchema(String name) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/683bbbde/software/base/src/main/java/brooklyn/event/feed/jmx/JmxFeed.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/event/feed/jmx/JmxFeed.java b/software/base/src/main/java/brooklyn/event/feed/jmx/JmxFeed.java
index a57d441..026f000 100644
--- a/software/base/src/main/java/brooklyn/event/feed/jmx/JmxFeed.java
+++ b/software/base/src/main/java/brooklyn/event/feed/jmx/JmxFeed.java
@@ -265,7 +265,7 @@ public class JmxFeed extends AbstractFeed {
     @Override
     protected void postStop() {
         super.postStop();
-        if (helper != null && ownHelper) helper.disconnect();
+        if (helper != null && ownHelper) helper.terminate();
     }
     
     /**

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/683bbbde/software/base/src/main/java/brooklyn/event/feed/jmx/JmxHelper.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/event/feed/jmx/JmxHelper.java b/software/base/src/main/java/brooklyn/event/feed/jmx/JmxHelper.java
index 80e5065..b9353c3 100644
--- a/software/base/src/main/java/brooklyn/event/feed/jmx/JmxHelper.java
+++ b/software/base/src/main/java/brooklyn/event/feed/jmx/JmxHelper.java
@@ -34,6 +34,7 @@ import java.util.Set;
 import java.util.WeakHashMap;
 import java.util.concurrent.Callable;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
 
 import javax.management.AttributeNotFoundException;
@@ -158,7 +159,8 @@ public class JmxHelper {
     private boolean failedReconnecting;
     private long failedReconnectingTime;
     private int minTimeBetweenReconnectAttempts = 1000;
-
+    private final AtomicBoolean terminated = new AtomicBoolean();
+    
     // Tracks the MBeans we have failed to find for this JmsHelper's connection URL (so can
log just once for each)
     private final Set<ObjectName> notFoundMBeans;
 
@@ -263,6 +265,7 @@ public class JmxHelper {
     /** attempts to connect immediately */
     @SuppressWarnings({ "rawtypes", "unchecked" })
     public synchronized void connect() throws IOException {
+        if (terminated.get()) throw new IllegalStateException("JMX Helper "+this+" already
terminated");
         if (connection != null) return;
 
         triedConnecting = true;
@@ -282,8 +285,20 @@ public class JmxHelper {
             } else {
                 throw npe;
             }
+        } catch (IOException e) {
+            Exceptions.propagateIfFatal(e);
+            if (terminated.get()) {
+                throw new IllegalStateException("JMX Helper "+this+" already terminated",
e);
+            } else {
+                throw e;
+            }
         }
         connection = connector.getMBeanServerConnection();
+        
+        if (terminated.get()) {
+            disconnectNow();
+            throw new IllegalStateException("JMX Helper "+this+" already terminated");
+        }
     }
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
@@ -353,11 +368,12 @@ public class JmxHelper {
                 connect();
                 return true;
             } catch (Exception e) {
-                if (shouldRetryOn(e)) {
+                Exceptions.propagateIfFatal(e);
+                if (!terminated.get() && shouldRetryOn(e)) {
                     if (LOG.isDebugEnabled()) LOG.debug("Attempt {} failed connecting to
{} ({})", new Object[] {attempt + 1, url, e.getMessage()});
                     lastError = e;
                 } else {
-                    throw Throwables.propagate(e);
+                    throw Exceptions.propagate(e);
                 }
             }
             attempt++;
@@ -380,18 +396,39 @@ public class JmxHelper {
         if (e instanceof ListenerNotFoundException) return false;
         if (e instanceof MalformedObjectNameException) return false;
         if (e instanceof NotCompliantMBeanException) return false;
+        if (e instanceof InterruptedException) return false;
+        if (e instanceof RuntimeInterruptedException) return false;
 
         return true;
     }
 
     /**
-     * Disconnects. Method doesn't throw an exception.
-     *
-     * Can safely be called if already disconnected.
+     * A thread-safe version of {@link #disconnectNow()}.
      *
      * This method is threadsafe.
      */
     public synchronized void disconnect() {
+        disconnectNow();
+    }
+    
+    /**
+     * Disconnects, preventing subsequent connections to be made. Method doesn't throw an
exception.
+     *
+     * Can safely be called if already disconnected.
+     *
+     * This method is not threadsafe, but will thus not block if 
+     * another thread is taking a long time for connections to timeout.
+     * 
+     * Any concurrent requests will likely get an IOException - see
+     * {@linkplain http://docs.oracle.com/javase/7/docs/api/javax/management/remote/JMXConnector.html#close()}.
+     * 
+     */
+    public void terminate() {
+        terminated.set(true);
+        disconnectNow();
+    }
+    
+    protected void disconnectNow() {
         triedConnecting = false;
         if (connector != null) {
             if (LOG.isDebugEnabled()) LOG.debug("Disconnecting from JMX URL {}", url);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/683bbbde/software/messaging/src/main/java/brooklyn/entity/messaging/kafka/KafkaBrokerImpl.java
----------------------------------------------------------------------
diff --git a/software/messaging/src/main/java/brooklyn/entity/messaging/kafka/KafkaBrokerImpl.java
b/software/messaging/src/main/java/brooklyn/entity/messaging/kafka/KafkaBrokerImpl.java
index 4ecfac3..b10e279 100644
--- a/software/messaging/src/main/java/brooklyn/entity/messaging/kafka/KafkaBrokerImpl.java
+++ b/software/messaging/src/main/java/brooklyn/entity/messaging/kafka/KafkaBrokerImpl.java
@@ -90,7 +90,7 @@ public class KafkaBrokerImpl extends SoftwareProcessImpl implements MessageBroke
             try {
                 helper.assertMBeanExistsEventually(SOCKET_SERVER_STATS_MBEAN, units.toMillis(duration));
             } finally {
-                helper.disconnect();
+                helper.terminate();
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/683bbbde/software/messaging/src/main/java/brooklyn/entity/messaging/qpid/QpidBrokerImpl.java
----------------------------------------------------------------------
diff --git a/software/messaging/src/main/java/brooklyn/entity/messaging/qpid/QpidBrokerImpl.java
b/software/messaging/src/main/java/brooklyn/entity/messaging/qpid/QpidBrokerImpl.java
index 6de5993..9ccbec1 100644
--- a/software/messaging/src/main/java/brooklyn/entity/messaging/qpid/QpidBrokerImpl.java
+++ b/software/messaging/src/main/java/brooklyn/entity/messaging/qpid/QpidBrokerImpl.java
@@ -85,7 +85,7 @@ public class QpidBrokerImpl extends JMSBrokerImpl<QpidQueue, QpidTopic>
implemen
         } catch (IOException e) {
             throw Exceptions.propagate(e);
         } finally {
-            if (helper != null) helper.disconnect();
+            if (helper != null) helper.terminate();
         }
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/683bbbde/software/messaging/src/main/java/brooklyn/entity/messaging/storm/StormImpl.java
----------------------------------------------------------------------
diff --git a/software/messaging/src/main/java/brooklyn/entity/messaging/storm/StormImpl.java
b/software/messaging/src/main/java/brooklyn/entity/messaging/storm/StormImpl.java
index abd9c71..57c09e6 100644
--- a/software/messaging/src/main/java/brooklyn/entity/messaging/storm/StormImpl.java
+++ b/software/messaging/src/main/java/brooklyn/entity/messaging/storm/StormImpl.java
@@ -112,7 +112,7 @@ public class StormImpl extends SoftwareProcessImpl implements Storm {
         super.disconnectSensors();
         disconnectServiceUpIsRunning();
         if (jmxFeed != null) jmxFeed.stop();
-        if (jmxHelper !=null && jmxHelper.isConnected()) jmxHelper.disconnect();
+        if (jmxHelper !=null) jmxHelper.terminate();
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/683bbbde/software/messaging/src/main/java/brooklyn/entity/zookeeper/AbstractZooKeeperImpl.java
----------------------------------------------------------------------
diff --git a/software/messaging/src/main/java/brooklyn/entity/zookeeper/AbstractZooKeeperImpl.java
b/software/messaging/src/main/java/brooklyn/entity/zookeeper/AbstractZooKeeperImpl.java
index d8a936c..ab77a10 100644
--- a/software/messaging/src/main/java/brooklyn/entity/zookeeper/AbstractZooKeeperImpl.java
+++ b/software/messaging/src/main/java/brooklyn/entity/zookeeper/AbstractZooKeeperImpl.java
@@ -64,7 +64,7 @@ public abstract class AbstractZooKeeperImpl extends SoftwareProcessImpl
implemen
             try {
                 helper.assertMBeanExistsEventually(ZOOKEEPER_MBEAN, units.toMillis(duration));
             } finally {
-                helper.disconnect();
+                helper.terminate();
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/683bbbde/software/nosql/src/main/java/brooklyn/entity/nosql/cassandra/CassandraNodeImpl.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/main/java/brooklyn/entity/nosql/cassandra/CassandraNodeImpl.java
b/software/nosql/src/main/java/brooklyn/entity/nosql/cassandra/CassandraNodeImpl.java
index ba3be07..e8ff089 100644
--- a/software/nosql/src/main/java/brooklyn/entity/nosql/cassandra/CassandraNodeImpl.java
+++ b/software/nosql/src/main/java/brooklyn/entity/nosql/cassandra/CassandraNodeImpl.java
@@ -565,7 +565,7 @@ public class CassandraNodeImpl extends SoftwareProcessImpl implements
CassandraN
 
         if (jmxFeed != null) jmxFeed.stop();
         if (jmxMxBeanFeed != null) jmxMxBeanFeed.stop();
-        if (jmxHelper != null && jmxHelper.isConnected()) jmxHelper.disconnect();
+        if (jmxHelper != null) jmxHelper.terminate();
         if (functionFeed != null) functionFeed.stop();
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/683bbbde/software/osgi/src/main/java/brooklyn/entity/osgi/karaf/KarafContainerImpl.java
----------------------------------------------------------------------
diff --git a/software/osgi/src/main/java/brooklyn/entity/osgi/karaf/KarafContainerImpl.java
b/software/osgi/src/main/java/brooklyn/entity/osgi/karaf/KarafContainerImpl.java
index f9f8d0f..4d48abb 100644
--- a/software/osgi/src/main/java/brooklyn/entity/osgi/karaf/KarafContainerImpl.java
+++ b/software/osgi/src/main/java/brooklyn/entity/osgi/karaf/KarafContainerImpl.java
@@ -169,7 +169,7 @@ public class KarafContainerImpl extends SoftwareProcessImpl implements
KarafCont
     protected void preStop() {
         super.preStop();
         
-        if (jmxHelper != null) jmxHelper.disconnect();
+        if (jmxHelper != null) jmxHelper.terminate();
     }
 
     @Effector(description="Updates the OSGi Service's properties, adding (and overriding)
the given key-value pairs")


Mime
View raw message