james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [6/7] james-project git commit: JAMES-2599 Guice injections for MetricableBlobStore
Date Thu, 22 Nov 2018 10:51:39 GMT
JAMES-2599 Guice injections for MetricableBlobStore


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/71a20047
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/71a20047
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/71a20047

Branch: refs/heads/master
Commit: 71a200476799b43abb8b3a87a69efa9474e020fc
Parents: a39ed23
Author: tran tien duc <dtran@linagora.com>
Authored: Thu Nov 22 10:21:07 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Thu Nov 22 17:50:55 2018 +0700

----------------------------------------------------------------------
 .../java/org/apache/james/blob/api/MetricableBlobStore.java | 9 ++++++++-
 .../apache/james/modules/mailbox/BlobStoreAPIModule.java    | 6 ++++++
 .../modules/objectstorage/ObjectStorageBlobStoreModule.java | 6 +++++-
 .../objectstorage/ObjectStorageBlobStoreModuleTest.java     | 5 ++++-
 .../james/modules/mailbox/CassandraObjectStoreModule.java   | 6 +++++-
 .../james/modules/blobstore/BlobStoreChoosingModule.java    | 3 +++
 6 files changed, 31 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/71a20047/server/blob/blob-api/src/main/java/org/apache/james/blob/api/MetricableBlobStore.java
----------------------------------------------------------------------
diff --git a/server/blob/blob-api/src/main/java/org/apache/james/blob/api/MetricableBlobStore.java
b/server/blob/blob-api/src/main/java/org/apache/james/blob/api/MetricableBlobStore.java
index d40a1ac..5e76835 100644
--- a/server/blob/blob-api/src/main/java/org/apache/james/blob/api/MetricableBlobStore.java
+++ b/server/blob/blob-api/src/main/java/org/apache/james/blob/api/MetricableBlobStore.java
@@ -21,10 +21,15 @@ package org.apache.james.blob.api;
 import java.io.InputStream;
 import java.util.concurrent.CompletableFuture;
 
+import javax.inject.Inject;
+import javax.inject.Named;
+
 import org.apache.james.metrics.api.MetricFactory;
 
 public class MetricableBlobStore implements BlobStore {
 
+    public static final String BLOB_STORE_IMPLEMENTATION = "blobStoreImplementation";
+
     static final String BLOB_STORE_METRIC_PREFIX = "blobStore:";
     static final String SAVE_BYTES_TIMER_NAME = BLOB_STORE_METRIC_PREFIX + "saveBytes";
     static final String SAVE_INPUT_STREAM_TIMER_NAME = BLOB_STORE_METRIC_PREFIX + "saveInputStream";
@@ -34,7 +39,9 @@ public class MetricableBlobStore implements BlobStore {
     private final MetricFactory metricFactory;
     private final BlobStore blobStoreImpl;
 
-    public MetricableBlobStore(MetricFactory metricFactory, BlobStore blobStoreImpl) {
+    @Inject
+    public MetricableBlobStore(MetricFactory metricFactory,
+                               @Named(BLOB_STORE_IMPLEMENTATION) BlobStore blobStoreImpl)
{
         this.metricFactory = metricFactory;
         this.blobStoreImpl = blobStoreImpl;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/71a20047/server/container/guice/blob-api-guice/src/main/java/org/apache/james/modules/mailbox/BlobStoreAPIModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/blob-api-guice/src/main/java/org/apache/james/modules/mailbox/BlobStoreAPIModule.java
b/server/container/guice/blob-api-guice/src/main/java/org/apache/james/modules/mailbox/BlobStoreAPIModule.java
index 4887488..a2d95a9 100644
--- a/server/container/guice/blob-api-guice/src/main/java/org/apache/james/modules/mailbox/BlobStoreAPIModule.java
+++ b/server/container/guice/blob-api-guice/src/main/java/org/apache/james/modules/mailbox/BlobStoreAPIModule.java
@@ -20,15 +20,21 @@
 package org.apache.james.modules.mailbox;
 
 import org.apache.james.blob.api.BlobId;
+import org.apache.james.blob.api.BlobStore;
 import org.apache.james.blob.api.HashBlobId;
+import org.apache.james.blob.api.MetricableBlobStore;
 
 import com.google.inject.AbstractModule;
 import com.google.inject.Scopes;
 
 public class BlobStoreAPIModule extends AbstractModule {
+
     @Override
     protected void configure() {
         bind(HashBlobId.Factory.class).in(Scopes.SINGLETON);
         bind(BlobId.Factory.class).to(HashBlobId.Factory.class);
+
+        bind(MetricableBlobStore.class).in(Scopes.SINGLETON);
+        bind(BlobStore.class).to(MetricableBlobStore.class);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/71a20047/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageBlobStoreModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageBlobStoreModule.java
b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageBlobStoreModule.java
index be0ff04..630db75 100644
--- a/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageBlobStoreModule.java
+++ b/server/container/guice/blob-objectstorage-guice/src/main/java/org/apache/james/modules/objectstorage/ObjectStorageBlobStoreModule.java
@@ -20,16 +20,20 @@
 package org.apache.james.modules.objectstorage;
 
 import org.apache.james.blob.api.BlobStore;
+import org.apache.james.blob.api.MetricableBlobStore;
 import org.apache.james.blob.objectstorage.ObjectStorageBlobsDAO;
 
 import com.google.inject.AbstractModule;
+import com.google.inject.name.Names;
 
 public class ObjectStorageBlobStoreModule extends AbstractModule {
 
     @Override
     protected void configure() {
         install(new ObjectStorageDependenciesModule());
-        bind(BlobStore.class).to(ObjectStorageBlobsDAO.class);
+        bind(BlobStore.class)
+            .annotatedWith(Names.named(MetricableBlobStore.BLOB_STORE_IMPLEMENTATION))
+            .to(ObjectStorageBlobsDAO.class);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/71a20047/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/ObjectStorageBlobStoreModuleTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/ObjectStorageBlobStoreModuleTest.java
b/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/ObjectStorageBlobStoreModuleTest.java
index 3c8e679..692c2b7 100644
--- a/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/ObjectStorageBlobStoreModuleTest.java
+++ b/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/ObjectStorageBlobStoreModuleTest.java
@@ -25,6 +25,7 @@ import java.util.UUID;
 import java.util.stream.Stream;
 
 import org.apache.james.blob.api.BlobStore;
+import org.apache.james.blob.api.MetricableBlobStore;
 import org.apache.james.blob.objectstorage.ContainerName;
 import org.apache.james.blob.objectstorage.DockerSwift;
 import org.apache.james.blob.objectstorage.DockerSwiftExtension;
@@ -51,6 +52,8 @@ import org.junit.jupiter.params.provider.ArgumentsSource;
 
 import com.google.inject.Guice;
 import com.google.inject.Injector;
+import com.google.inject.Key;
+import com.google.inject.name.Names;
 import com.google.inject.util.Modules;
 
 @ExtendWith(DockerSwiftExtension.class)
@@ -122,7 +125,7 @@ class ObjectStorageBlobStoreModuleTest {
         ObjectStorageBlobsDAO dao = injector.getInstance(ObjectStorageBlobsDAO.class);
         dao.createContainer(configuration.getNamespace());
 
-        BlobStore blobStore = injector.getInstance(BlobStore.class);
+        BlobStore blobStore = injector.getInstance(Key.get(BlobStore.class, Names.named(MetricableBlobStore.BLOB_STORE_IMPLEMENTATION)));
 
         assertThatCode(() -> blobStore.save(new byte[] {0x00})).doesNotThrowAnyException();
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/71a20047/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraObjectStoreModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraObjectStoreModule.java
b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraObjectStoreModule.java
index 558a713..2a7e041 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraObjectStoreModule.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraObjectStoreModule.java
@@ -21,19 +21,23 @@ package org.apache.james.modules.mailbox;
 
 import org.apache.james.backends.cassandra.components.CassandraModule;
 import org.apache.james.blob.api.BlobStore;
+import org.apache.james.blob.api.MetricableBlobStore;
 import org.apache.james.blob.cassandra.CassandraBlobModule;
 import org.apache.james.blob.cassandra.CassandraBlobsDAO;
 
 import com.google.inject.AbstractModule;
 import com.google.inject.Scopes;
 import com.google.inject.multibindings.Multibinder;
+import com.google.inject.name.Names;
 
 public class CassandraObjectStoreModule extends AbstractModule {
     @Override
     protected void configure() {
         bind(CassandraBlobsDAO.class).in(Scopes.SINGLETON);
 
-        bind(BlobStore.class).to(CassandraBlobsDAO.class);
+        bind(BlobStore.class)
+            .annotatedWith(Names.named(MetricableBlobStore.BLOB_STORE_IMPLEMENTATION))
+            .to(CassandraBlobsDAO.class);
 
         Multibinder<CassandraModule> cassandraDataDefinitions = Multibinder.newSetBinder(binder(),
CassandraModule.class);
         cassandraDataDefinitions.addBinding().toInstance(CassandraBlobModule.MODULE);

http://git-wip-us.apache.org/repos/asf/james-project/blob/71a20047/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/modules/blobstore/BlobStoreChoosingModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/modules/blobstore/BlobStoreChoosingModule.java
b/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/modules/blobstore/BlobStoreChoosingModule.java
index 737033b..a8be32e7 100644
--- a/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/modules/blobstore/BlobStoreChoosingModule.java
+++ b/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/modules/blobstore/BlobStoreChoosingModule.java
@@ -21,6 +21,7 @@ package org.apache.james.modules.blobstore;
 
 import java.io.FileNotFoundException;
 
+import javax.inject.Named;
 import javax.inject.Provider;
 import javax.inject.Singleton;
 
@@ -28,6 +29,7 @@ import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.james.backends.cassandra.components.CassandraModule;
 import org.apache.james.blob.api.BlobStore;
+import org.apache.james.blob.api.MetricableBlobStore;
 import org.apache.james.blob.cassandra.CassandraBlobModule;
 import org.apache.james.blob.cassandra.CassandraBlobsDAO;
 import org.apache.james.blob.objectstorage.ObjectStorageBlobsDAO;
@@ -69,6 +71,7 @@ public class BlobStoreChoosingModule extends AbstractModule {
 
     @VisibleForTesting
     @Provides
+    @Named(MetricableBlobStore.BLOB_STORE_IMPLEMENTATION)
     @Singleton
     BlobStore provideBlobStore(BlobStoreChoosingConfiguration choosingConfiguration,
                                Provider<CassandraBlobsDAO> cassandraBlobStoreProvider,


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message