camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject camel git commit: CAMEL-10635 - camel-mongodb-gridfs - The component should not store state
Date Fri, 23 Dec 2016 07:59:12 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.18.x a22853952 -> aa43bca20


CAMEL-10635 - camel-mongodb-gridfs - The component should not store state


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

Branch: refs/heads/camel-2.18.x
Commit: aa43bca204ea7321d3f5558c33b43a0b37951a30
Parents: a228539
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Fri Dec 23 08:54:54 2016 +0100
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Fri Dec 23 08:57:46 2016 +0100

----------------------------------------------------------------------
 .../camel/component/gridfs/GridFsComponent.java  | 19 -------------------
 .../camel/component/gridfs/GridFsEndpoint.java   | 15 ++++++++++++++-
 2 files changed, 14 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/aa43bca2/components/camel-mongodb-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-mongodb-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsComponent.java
b/components/camel-mongodb-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsComponent.java
index 62701a0..5b91313 100644
--- a/components/camel-mongodb-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsComponent.java
+++ b/components/camel-mongodb-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsComponent.java
@@ -18,35 +18,20 @@ package org.apache.camel.component.gridfs;
 
 import java.util.Map;
 
-import com.mongodb.Mongo;
 import org.apache.camel.Endpoint;
 import org.apache.camel.impl.UriEndpointComponent;
-import org.apache.camel.util.CamelContextHelper;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 
 public class GridFsComponent extends UriEndpointComponent {
 
-    private static final Logger LOG = LoggerFactory.getLogger(GridFsComponent.class);
-
-    private volatile Mongo db;
-
     public GridFsComponent() {
         super(GridFsEndpoint.class);
     }
     
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object>
parameters) throws Exception {
-        if (db == null) {
-            db = CamelContextHelper.mandatoryLookup(getCamelContext(), remaining, Mongo.class);
-            LOG.debug("Resolved the connection with the name {} as {}", remaining, db);
-        }
 
         GridFsEndpoint endpoint = new GridFsEndpoint(uri, this);
-        parameters.put("mongoConnection", db);
         endpoint.setConnectionBean(remaining);
-        endpoint.setMongoConnection(db);
         setProperties(endpoint, parameters);
         
         return endpoint;
@@ -54,10 +39,6 @@ public class GridFsComponent extends UriEndpointComponent {
 
     @Override
     protected void doShutdown() throws Exception {
-        if (db != null) {
-            LOG.debug("Closing the connection {} on {}", db, this);
-            db.close();
-        }
         super.doShutdown();
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/aa43bca2/components/camel-mongodb-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-mongodb-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsEndpoint.java
b/components/camel-mongodb-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsEndpoint.java
index cb8f686..d125972 100644
--- a/components/camel-mongodb-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsEndpoint.java
+++ b/components/camel-mongodb-gridfs/src/main/java/org/apache/camel/component/gridfs/GridFsEndpoint.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.gridfs;
 import com.mongodb.DB;
 import com.mongodb.DBCollection;
 import com.mongodb.Mongo;
+import com.mongodb.MongoClient;
 import com.mongodb.ReadPreference;
 import com.mongodb.WriteConcern;
 import com.mongodb.gridfs.GridFS;
@@ -30,6 +31,7 @@ import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.spi.UriPath;
+import org.apache.camel.util.CamelContextHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -130,10 +132,21 @@ public class GridFsEndpoint extends DefaultEndpoint {
                     + ", " + writeConcernRef + ". Aborting initialization.";
             throw new IllegalArgumentException(msg);
         }
-
+        mongoConnection = CamelContextHelper.mandatoryLookup(getCamelContext(), connectionBean,
MongoClient.class);
+        LOG.debug("Resolved the connection with the name {} as {}", connectionBean, mongoConnection);
         setWriteReadOptionsOnConnection();
         super.doStart();
     }
+    
+    @Override
+    protected void doStop() throws Exception {
+        super.doStop();
+        if (mongoConnection != null) {
+            LOG.debug("Closing connection");
+            mongoConnection.close();
+        }
+    }
+    
     private void setWriteReadOptionsOnConnection() {
         // Set the WriteConcern
         if (writeConcern != null) {


Mime
View raw message