Package com.mongodb

Examples of com.mongodb.ServerAddress


            for (String serverAuthority : StringUtils.split(_serverAuthorities, ',')) {
                String[] serverAuthorityParts = StringUtils.split(StringUtils.trimToEmpty(serverAuthority), ":");

                if (serverAuthorityParts.length == 1) {
                    serverAddressList.add(new ServerAddress(serverAuthorityParts[0]));
                } else {
                    serverAddressList.add(new ServerAddress(serverAuthorityParts[0], Integer.parseInt(serverAuthorityParts[1])));
                }
            }

            if (_sLog.isInfoEnabled()) {
                _sLog.info("Initializing mongoDB '" + _databaseName + "' with servers: " + serverAddressList);
View Full Code Here


        // It has multiple nodes
        StringTokenizer st = new StringTokenizer(seeds, ",");
        List<ServerAddress> addrs = new ArrayList<ServerAddress>();
        while (st.hasMoreElements()) {
          String serverName = st.nextElement().toString();
          ServerAddress server = new ServerAddress(serverName);
          addrs.add(server);
        }
        mongoClient = new MongoClient(addrs);
      } else
        mongoClient = new MongoClient(seeds);
View Full Code Here

        {
            List<ServerAddress> serverAddrs = new ArrayList();
            if (remains.length() == 0)
            {
                // "mongodb:"
                serverAddrs.add(new ServerAddress());
            }
            else
            {
                StringTokenizer tokeniser = new StringTokenizer(remains, ",");
                while (tokeniser.hasMoreTokens())
                {
                    String token = tokeniser.nextToken();
                    String serverName = "localhost";
                    if (token.charAt(0) != '/')
                    {
                        // server name (and optional port)
                        int serverEndPos = remains.indexOf('/');
                        if (serverEndPos > 0)
                        {
                            serverName = token.substring(0, serverEndPos);
                            token = token.substring(serverEndPos);
                        }
                        else
                        {
                            serverName = token;
                            remains = "";
                        }
                    }

                    // Create a ServerAddress for this specification
                    ServerAddress addr = null;
                    int portSeparatorPos = serverName.indexOf(':');
                    if (portSeparatorPos > 0)
                    {
                        addr = new ServerAddress(serverName.substring(0, portSeparatorPos),
                            Integer.valueOf(serverName.substring(portSeparatorPos+1)).intValue());
                    }
                    else
                    {
                        addr = new ServerAddress(serverName);
                    }
                    serverAddrs.add(addr);

                    if (token.charAt(0) == '/' && token.length() > 1)
                    {
View Full Code Here

    public static Operation putDatabaseDetails(Operation op, DB db) {
        op.put("dbName", db.getName());

        Mongo mongo = db.getMongo();
        ServerAddress address = mongo.getAddress();
        op.put("host", address.getHost());
        op.put("port", address.getPort());
        return op;
    }
View Full Code Here

    @Test
    public void testDbCommandWithHost() throws Exception {
        final String HOST = "7.3.6.5";
        final int PORT = 27017;
        Mongo mongo = mock(Mongo.class);
        ServerAddress address = mock(ServerAddress.class);
        when(address.getHost()).thenReturn(HOST);
        when(address.getPort()).thenReturn(PORT);
        when(mongo.getAddress()).thenReturn(address);

        Operation op = assertCommandOperation(new DBDummy(mongo, "testDbCommandWithHost"));
        assertEquals("Mismatched host", HOST, op.get("host", String.class));
        assertEquals("Mismatched port", 27017, op.getInt("port", (-1)));
View Full Code Here

      }
     
      // Create the MongoClient.
      mongo =
        new MongoClient(
          new ServerAddress(getDatabaseAddress(), getDatabasePort()),
          credentials);
    }
    catch(UnknownHostException e) {
      throw new OmhException("The database could not setup.", e);
    }
View Full Code Here

    public static void contributeMongoDBSource(OrderedConfiguration<ServerAddress> configuration)
    {
        try
        {
            configuration.add("test", new ServerAddress("localhost", 12345));
        }
        catch (UnknownHostException e)
        {
            throw new RuntimeException(e);
        }
View Full Code Here

    }

    @Override
    protected Mongo createInstance() throws Exception {
        if (StringUtils.hasText(this.hostname )) {
            return new Mongo(new ServerAddress(hostname,port), getMongoOptions());
        } else {
            return new Mongo();
        }
    }
View Full Code Here

        serverAddresses = new ArrayList<>();
        int port = config.port().get() == null ? 27017 : config.port().get();
        if( config.nodes().get().isEmpty() )
        {
            String hostname = config.hostname().get() == null ? "127.0.0.1" : config.hostname().get();
            serverAddresses.add( new ServerAddress( hostname, port ) );
        }
        else
        {
            if( config.hostname().get() != null && !config.hostname().get().isEmpty() )
            {
                serverAddresses.add( new ServerAddress( config.hostname().get(), port ) );
            }
            serverAddresses.addAll( config.nodes().get() );
        }

        // If database name not configured, set it to qi4j:entitystore
View Full Code Here

        server = new MongoServer(new MemoryBackend());

        // bind on a random local port
        InetSocketAddress serverAddress = server.bind();

        client = new MongoClient(new ServerAddress(serverAddress));
        collection = client.getDB("testdb").getCollection("testcollection");
    }
View Full Code Here

TOP

Related Classes of com.mongodb.ServerAddress

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.