camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bvah...@apache.org
Subject git commit: CAMEL-7370: Properly close the underlying physical connection to MongoDB while shutting down
Date Wed, 16 Apr 2014 06:57:30 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.12.x 204e321f1 -> 49061150b


CAMEL-7370: Properly close the underlying physical connection to MongoDB while shutting down


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/49061150
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/49061150
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/49061150

Branch: refs/heads/camel-2.12.x
Commit: 49061150b5289a394b78f4fc1848edf368f9461f
Parents: 204e321
Author: Babak Vahdat <bvahdat@apache.org>
Authored: Wed Apr 16 08:56:03 2014 +0200
Committer: Babak Vahdat <bvahdat@apache.org>
Committed: Wed Apr 16 08:57:22 2014 +0200

----------------------------------------------------------------------
 .../component/mongodb/MongoDbComponent.java     | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/49061150/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbComponent.java
b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbComponent.java
index d923a46..3718aba 100644
--- a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbComponent.java
+++ b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbComponent.java
@@ -27,6 +27,9 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.impl.DefaultComponent;
 import org.apache.camel.util.CamelContextHelper;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 /**
  * Represents the component that manages {@link MongoDbEndpoint}.
  */
@@ -35,12 +38,16 @@ public class MongoDbComponent extends DefaultComponent {
     public static final Set<MongoDbOperation> WRITE_OPERATIONS = 
             new HashSet<MongoDbOperation>(Arrays.asList(MongoDbOperation.insert, MongoDbOperation.save,

                     MongoDbOperation.update, MongoDbOperation.remove));
+    private static final Logger LOG = LoggerFactory.getLogger(MongoDbComponent.class);
+    private Mongo db;
 
     /**
      * Should access a singleton of type Mongo
      */
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object>
parameters) throws Exception {
-        Mongo db = CamelContextHelper.mandatoryLookup(getCamelContext(), remaining, Mongo.class);
+        if (db == null) {
+            db = CamelContextHelper.mandatoryLookup(getCamelContext(), remaining, Mongo.class);
+        }
 
         Endpoint endpoint = new MongoDbEndpoint(uri, this);
         parameters.put("mongoConnection", db);
@@ -49,6 +56,17 @@ public class MongoDbComponent extends DefaultComponent {
         return endpoint;
     }
 
+    @Override
+    protected void doShutdown() throws Exception {
+        if (db != null) {
+            // properly close the underlying physical connection to MongoDB
+            LOG.debug("closing the connection {} on {}", db, this);
+            db.close();
+        }
+
+        super.doShutdown();
+    }
+
     public static CamelMongoDbException wrapInCamelMongoDbException(Throwable t) {
         if (t instanceof CamelMongoDbException) {
             return (CamelMongoDbException) t;


Mime
View raw message