Example usage for com.mongodb MongoClient getAllAddress

List of usage examples for com.mongodb MongoClient getAllAddress

Introduction

In this page you can find the example usage for com.mongodb MongoClient getAllAddress.

Prototype

@Deprecated
public List<ServerAddress> getAllAddress() 

Source Link

Document

Gets a list of all server addresses used when this Mongo was created

Usage

From source file:com.edgytech.umongo.MongoPanel.java

License:Apache License

@Override
protected void updateComponentCustom(JPanel old) {
    try {//  w  ww  . j  av a 2 s.co m
        MongoClient mongo = getMongoNode().getMongoClient();
        setStringFieldValue(Item.version, mongo.getVersion());

        ServerAddress master = mongo.getAddress();
        if (master != null) {
            setStringFieldValue(Item.masterServer, getServerAddressString(master));
        }
        List<ServerAddress> addrs = mongo.getAllAddress();
        String html = "<html>";
        for (ServerAddress addr : addrs) {
            html += getServerAddressString(addr) + "<br/>";
        }
        html += "</html>";
        setStringFieldValue(Item.seedServers, html);

        addrs = mongo.getServerAddressList();
        html = "<html>";
        for (ServerAddress addr : addrs) {
            //                String ports = MongoUtils.makeInfoString("used", mongo.getConnector().getDBPortPool(addr).inUse(),
            //                        "available", mongo.getConnector().getDBPortPool(addr).available(),
            //                        "created", mongo.getConnector().getDBPortPool(addr).everCreated());
            String txt = getServerAddressString(addr);
            html += txt + "<br/>";
        }
        setStringFieldValue(Item.activeServers, html);

        setStringFieldValue(Item.queryOptions, MongoUtils.queryOptionsToString(mongo.getOptions()));
        ((DocField) getBoundUnit(Item.writeConcern)).setDoc(mongo.getWriteConcern().getCommand());
        ((DocField) getBoundUnit(Item.readPreference)).setDoc(mongo.getReadPreference().toDBObject());
        setStringFieldValue(Item.maxObjectSize, String.valueOf(mongo.getMaxBsonObjectSize()));
    } catch (Exception e) {
        UMongo.instance.showError(this.getClass().getSimpleName() + " update", e);
    }
}

From source file:com.setronica.ucs.server.MessageServer.java

License:LGPL

private static ClassPathXmlApplicationContext bootstrapMongo(String mongoUrls) throws UnknownHostException {
    List<ServerAddress> seeds = new ArrayList<>();
    for (String s : mongoUrls.split(",")) {
        int idx = s.indexOf(":");
        ServerAddress address;/*from ww w .j  av  a  2 s  . c om*/
        if (idx > 0) {
            address = new ServerAddress(s.substring(0, idx), Integer.parseInt(s.substring(idx + 1)));
        } else {
            address = new ServerAddress(s);
        }
        seeds.add(address);
    }
    //create parent BeanFactory
    DefaultListableBeanFactory parentBeanFactory = new DefaultListableBeanFactory();
    //register your pre-fabricated object in it
    parentBeanFactory.registerSingleton("addresses", seeds);
    ClassPathXmlApplicationContext applicationContext = initApplication("mongo", parentBeanFactory);

    MongoClient client = (MongoClient) applicationContext.getBean("mongoClient");
    logger.info("addresses: " + client.getAllAddress());
    return applicationContext;
}

From source file:com.vino.AppModule.java

License:Apache License

@Provides
public AutoStartable mongoConnectionLogger(final @Named("restx.server.id") Optional<String> serverId,
        final @Named("mongo.db") String dbName,
        final @Named(MongoModule.MONGO_CLIENT_NAME) MongoClient client) {
    return new AutoStartable() {
        @Override/*from  w  w  w  . ja  v a 2s.c o m*/
        public void start() {
            logger.info("{} - connected to Mongo db '{}' @ {}", serverId.or("-"), dbName,
                    client.getAllAddress());
        }
    };
}