polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject polygene-java git commit: POLYGENE-172 - Changed to String for host:port in Mongodb.
Date Mon, 15 May 2017 15:49:50 GMT
Repository: polygene-java
Updated Branches:
  refs/heads/develop 339784cf4 -> 240ddb702


POLYGENE-172 - Changed to String for host:port in Mongodb.

Signed-off-by: niclas <niclas@hedhman.org>


Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/240ddb70
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/240ddb70
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/240ddb70

Branch: refs/heads/develop
Commit: 240ddb702723fa1c0543480e94602ebfb0c4dc60
Parents: 339784c
Author: niclas <niclas@hedhman.org>
Authored: Mon May 15 23:49:39 2017 +0800
Committer: niclas <niclas@hedhman.org>
Committed: Mon May 15 23:49:39 2017 +0800

----------------------------------------------------------------------
 NOTICE.txt                                      |  2 -
 .../mongodb/MongoEntityStoreConfiguration.java  |  5 +-
 .../mongodb/MongoMapEntityStoreMixin.java       | 63 +++++++++++++-------
 .../mongodb/EmbedMongoMapEntityStoreTest.java   |  7 +--
 .../mongodb/MongoMapEntityStoreTest.java        |  5 +-
 5 files changed, 47 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/240ddb70/NOTICE.txt
----------------------------------------------------------------------
diff --git a/NOTICE.txt b/NOTICE.txt
index b1cec68..de8a58e 100644
--- a/NOTICE.txt
+++ b/NOTICE.txt
@@ -4,8 +4,6 @@ Copyright 2015-2016 The Apache Software Foundation.
 This product includes software developed at
 The Apache Software Foundation (http://www.apache.org/).
 
-Additional NOTICE files under each subproject.
-
 IMPORTANT:
 This distribution may include cryptographic software. The country in which you
 currently reside may have restrictions on the import, possession, use, and/or

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/240ddb70/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoEntityStoreConfiguration.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoEntityStoreConfiguration.java
b/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoEntityStoreConfiguration.java
index 5b13a31..75c95ac 100644
--- a/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoEntityStoreConfiguration.java
+++ b/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoEntityStoreConfiguration.java
@@ -19,7 +19,6 @@
  */
 package org.apache.polygene.entitystore.mongodb;
 
-import com.mongodb.ServerAddress;
 import java.util.List;
 import org.apache.polygene.api.common.Optional;
 import org.apache.polygene.api.common.UseDefaults;
@@ -36,7 +35,7 @@ public interface MongoEntityStoreConfiguration
     Property<Integer> port();
 
     @UseDefaults
-    Property<List<ServerAddress>> nodes();
+    Property<List<String>> nodes();
 
     @UseDefaults
     Property<String> username();
@@ -86,7 +85,7 @@ public interface MongoEntityStoreConfiguration
          * Exceptions are raised for network issues, and server errors;
          * waits on a majority of servers for the write operation.
          */
-        MAJORITY;
+        MAJORITY
 
     }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/240ddb70/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoMapEntityStoreMixin.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoMapEntityStoreMixin.java
b/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoMapEntityStoreMixin.java
index 106325d..3766b82 100644
--- a/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoMapEntityStoreMixin.java
+++ b/extensions/entitystore-mongodb/src/main/java/org/apache/polygene/entitystore/mongodb/MongoMapEntityStoreMixin.java
@@ -53,6 +53,7 @@ import org.bson.Document;
 import org.bson.conversions.Bson;
 
 import static com.mongodb.client.model.Filters.eq;
+import static java.util.stream.Collectors.toList;
 
 /**
  * MongoDB implementation of MapEntityStore.
@@ -112,7 +113,8 @@ public class MongoMapEntityStoreMixin
         // If no configuration, use 127.0.0.1:27017
         serverAddresses = new ArrayList<>();
         int port = config.port().get() == null ? 27017 : config.port().get();
-        if( config.nodes().get().isEmpty() )
+        List<String> nodes = config.nodes().get();
+        if( nodes.isEmpty() )
         {
             String hostname = config.hostname().get() == null ? "127.0.0.1" : config.hostname().get();
             serverAddresses.add( new ServerAddress( hostname, port ) );
@@ -123,7 +125,10 @@ public class MongoMapEntityStoreMixin
             {
                 serverAddresses.add( new ServerAddress( config.hostname().get(), port ) );
             }
-            serverAddresses.addAll( config.nodes().get() );
+            serverAddresses.addAll( nodes.stream()
+                                         .map( this::parseNode )
+                                         .collect( toList() )
+                                  );
         }
 
         // If database name not configured, set it to polygene:entitystore
@@ -143,27 +148,27 @@ public class MongoMapEntityStoreMixin
         // If write concern not configured, set it to normal
         switch( config.writeConcern().get() )
         {
-            case W1:
-                writeConcern = WriteConcern.W1;
-                break;
-            case W2:
-                writeConcern = WriteConcern.W2;
-                break;
-            case W3:
-                writeConcern = WriteConcern.W3;
-                break;
-            case UNACKNOWLEDGED:
-                writeConcern = WriteConcern.UNACKNOWLEDGED;
-                break;
-            case JOURNALED:
-                writeConcern = WriteConcern.JOURNALED;
-                break;
-            case MAJORITY:
-                writeConcern = WriteConcern.MAJORITY;
-                break;
-            case ACKNOWLEDGED:
-            default:
-                writeConcern = WriteConcern.ACKNOWLEDGED;
+        case W1:
+            writeConcern = WriteConcern.W1;
+            break;
+        case W2:
+            writeConcern = WriteConcern.W2;
+            break;
+        case W3:
+            writeConcern = WriteConcern.W3;
+            break;
+        case UNACKNOWLEDGED:
+            writeConcern = WriteConcern.UNACKNOWLEDGED;
+            break;
+        case JOURNALED:
+            writeConcern = WriteConcern.JOURNALED;
+            break;
+        case MAJORITY:
+            writeConcern = WriteConcern.MAJORITY;
+            break;
+        case ACKNOWLEDGED:
+        default:
+            writeConcern = WriteConcern.ACKNOWLEDGED;
         }
 
         // Username and password are defaulted to empty strings
@@ -171,6 +176,18 @@ public class MongoMapEntityStoreMixin
         password = config.password().get().toCharArray();
     }
 
+    private <R> ServerAddress parseNode( String nodeString )
+    {
+        String[] parts = nodeString.split( ":" );
+        String host = parts[ 0 ];
+        if( parts.length == 2 )
+        {
+            int port = Integer.parseInt( parts[ 1 ] );
+            return new ServerAddress( host, port );
+        }
+        return new ServerAddress( host );
+    }
+
     @Override
     public void passivateService()
         throws Exception

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/240ddb70/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/EmbedMongoMapEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/EmbedMongoMapEntityStoreTest.java
b/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/EmbedMongoMapEntityStoreTest.java
index 2341777..699bcab 100644
--- a/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/EmbedMongoMapEntityStoreTest.java
+++ b/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/EmbedMongoMapEntityStoreTest.java
@@ -45,14 +45,14 @@ public class EmbedMongoMapEntityStoreTest extends AbstractEntityStoreTest
     private static int port;
     private static MongodExecutable mongod;
 
-
     @BeforeClass
-    public static void startEmbedMongo() throws IOException
+    public static void startEmbedMongo()
+        throws IOException
     {
         port = FreePortFinder.findFreePortOnLoopback();
         mongod = MONGO_STARTER.prepare( new MongodConfigBuilder()
                                             .version( Version.Main.PRODUCTION )
-					.net( new Net( "localhost", port, Network.localhostIsIPv6() ) )
+                                            .net( new Net( "localhost", port, Network.localhostIsIPv6()
) )
                                             .build() );
         mongod.start();
     }
@@ -77,7 +77,6 @@ public class EmbedMongoMapEntityStoreTest extends AbstractEntityStoreTest
 
         new MongoDBEntityStoreAssembler().withConfig( config, Visibility.layer ).assemble(
module );
 
-
         MongoEntityStoreConfiguration mongoConfig = config.forMixin( MongoEntityStoreConfiguration.class
)
                                                           .declareDefaults();
         mongoConfig.writeConcern().set( MongoEntityStoreConfiguration.WriteConcern.MAJORITY
);

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/240ddb70/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/MongoMapEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/MongoMapEntityStoreTest.java
b/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/MongoMapEntityStoreTest.java
index aa9b9e3..9c48fe5 100644
--- a/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/MongoMapEntityStoreTest.java
+++ b/extensions/entitystore-mongodb/src/test/java/org/apache/polygene/entitystore/mongodb/MongoMapEntityStoreTest.java
@@ -34,8 +34,7 @@ import static org.apache.polygene.test.util.Assume.assumeConnectivity;
  * Test the MongoMapEntityStoreService.
  * <p>Installing mongodb and starting it should suffice as the test use mongodb defaults:
127.0.0.1:27017</p>
  */
-public class MongoMapEntityStoreTest
-    extends AbstractEntityStoreTest
+public class MongoMapEntityStoreTest extends AbstractEntityStoreTest
 {
     @BeforeClass
     public static void beforeRedisMapEntityStoreTests()
@@ -64,6 +63,7 @@ public class MongoMapEntityStoreTest
         mongoConfig.collection().set( "polygene:test:entities" );
         // START SNIPPET: assembly
     }
+
     // END SNIPPET: assembly
     private Mongo mongo;
     private String dbName;
@@ -76,7 +76,6 @@ public class MongoMapEntityStoreTest
         MongoMapEntityStoreService es = serviceFinder.findService( MongoMapEntityStoreService.class
).get();
         mongo = es.mongoInstanceUsed();
         dbName = es.dbInstanceUsed().getName();
-
     }
 
     @Override


Mime
View raw message