Example usage for com.mongodb ReadPreference getName

List of usage examples for com.mongodb ReadPreference getName

Introduction

In this page you can find the example usage for com.mongodb ReadPreference getName.

Prototype

public abstract String getName();

Source Link

Document

Gets the name of this read preference.

Usage

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

License:Apache License

void update(int options, WriteConcern wc, ReadPreference rp) {
    // reset/*from   w w  w .j av  a  2  s. co m*/
    xmlLoadCheckpoint();

    setBooleanFieldValue(Item.tailable, (options & Bytes.QUERYOPTION_TAILABLE) != 0);
    setBooleanFieldValue(Item.slaveOk, (options & Bytes.QUERYOPTION_SLAVEOK) != 0);
    setBooleanFieldValue(Item.opLogReplay, (options & Bytes.QUERYOPTION_OPLOGREPLAY) != 0);
    setBooleanFieldValue(Item.noTimeout, (options & Bytes.QUERYOPTION_NOTIMEOUT) != 0);
    setBooleanFieldValue(Item.awaitData, (options & Bytes.QUERYOPTION_AWAITDATA) != 0);
    setBooleanFieldValue(Item.exhaust, (options & Bytes.QUERYOPTION_EXHAUST) != 0);
    setBooleanFieldValue(Item.partial, (options & Bytes.QUERYOPTION_PARTIAL) != 0);

    Object w = wc.getWObject();
    int wInt = (Integer) (w instanceof Integer ? w : 0);
    String wStr = (String) (w instanceof String ? w : "");
    setIntFieldValue(Item.writeFactor, wInt);
    setStringFieldValue(Item.writePolicy, wStr);
    setIntFieldValue(Item.writeTimeout, wc.getWtimeout());
    //        setBooleanFieldValue(Item.fsync, wc.fsync());

    DBObject rpObj = rp.toDBObject();
    ComboBox readBox = (ComboBox) getBoundUnit(Item.rpPreference);
    ReadPref rpEnm = ReadPref.primary;
    if (rp != null)
        rpEnm = ReadPref.valueOf(rp.getName());
    readBox.value = rpEnm.ordinal();
    if (rpObj.containsField("tags")) {
        List tags = (List) rpObj.get("tags");
        if (tags.size() > 0) {
            ((DocBuilderField) getBoundComponentUnit(Item.rpTag)).setDBObject((DBObject) tags.get(0));
        }
    }
}

From source file:org.apache.drill.exec.store.mongo.MongoGroupScan.java

License:Apache License

@SuppressWarnings("unchecked")
private Set<ServerAddress> getPreferredHosts(MongoClient client, List<String> hosts) {
    Set<ServerAddress> addressList = Sets.newHashSet();
    MongoDatabase db = client.getDatabase(scanSpec.getDbName());
    ReadPreference readPreference = client.getReadPreference();
    Document command = db.runCommand(new Document("isMaster", 1));

    final String primaryHost = command.getString("primary");
    final List<String> hostsList = (List<String>) command.get("hosts");

    switch (readPreference.getName().toUpperCase()) {
    case "PRIMARY":
    case "PRIMARYPREFERRED":
        if (primaryHost == null) {
            return null;
        }/*from   w w w .jav a  2s  .  c o m*/
        addressList.add(new ServerAddress(primaryHost));
        return addressList;
    case "SECONDARY":
    case "SECONDARYPREFERRED":
        if (primaryHost == null || hostsList == null) {
            return null;
        }
        hostsList.remove(primaryHost);
        for (String host : hostsList) {
            addressList.add(new ServerAddress(host));
        }
        return addressList;
    case "NEAREST":
        if (hostsList == null) {
            return null;
        }
        for (String host : hostsList) {
            addressList.add(new ServerAddress(host));
        }
        return addressList;
    default:
        return null;
    }
}

From source file:org.codinjutsu.tools.mongo.view.ServerConfigurationPanel.java

License:Apache License

public ServerConfigurationPanel(Project project, MongoManager mongoManager) {
    this.project = project;
    setLayout(new BorderLayout());
    add(rootPanel, BorderLayout.CENTER);
    this.mongoManager = mongoManager;

    labelField.setName("labelField");
    feedbackLabel.setName("feedbackLabel");

    sslConnectionField.setName("sslConnectionField");
    readPreferenceComboBox.setName("readPreferenceComboBox");
    authenticationPanel.setBorder(IdeBorderFactory.createTitledBorder("Authentication settings", true));
    serverUrlsField.setName("serverUrlsField");
    usernameField.setName("usernameField");
    passwordField.setName("passwordField");
    mongoCRAuthRadioButton.setName("mongoCRAuthField");
    scramSHA1AuthRadioButton.setName("scramSHA1AuthField");
    defaultAuthMethodRadioButton.setName("defaultAuthMethod");

    userDatabaseField.setName("userDatabaseField");
    userDatabaseField.setToolTipText(//w ww.ja  va 2 s  . c o  m
            "If your access is restricted to a specific database (e.g.: MongoLab), you can set it right here");

    autoConnectCheckBox.setName("autoConnectField");

    mongoShellOptionsPanel.setBorder(IdeBorderFactory.createTitledBorder("Mongo shell options", true));
    shellArgumentsLineField.setDialogCaption("Mongo arguments");

    testConnectionButton.setName("testConnection");

    connectionOptionPanel.setBorder(IdeBorderFactory.createTitledBorder("Connection Settings", true));
    readPreferenceComboBox.setModel(new DefaultComboBoxModel<>(new ReadPreference[] { ReadPreference.primary(),
            ReadPreference.primaryPreferred(), ReadPreference.secondary(), ReadPreference.secondaryPreferred(),
            ReadPreference.nearest() }));

    readPreferenceComboBox.setRenderer(new ColoredListCellRenderer() {
        @Override
        protected void customizeCellRenderer(JList list, Object value, int index, boolean selected,
                boolean hasFocus) {
            ReadPreference readPreference = (ReadPreference) value;
            append(readPreference.getName());
        }
    });

    readPreferenceComboBox.setSelectedItem(ReadPreference.primary());

    authMethodGroup = new ButtonGroup();
    authMethodGroup.add(mongoCRAuthRadioButton);
    authMethodGroup.add(scramSHA1AuthRadioButton);
    authMethodGroup.add(defaultAuthMethodRadioButton);

    defaultAuthMethodRadioButton.setSelected(true);
    defaultAuthMethodRadioButton.setToolTipText("Let the driver resolves the auth. mechanism");
    shellWorkingDirField.setText(null);
    initListeners();
}

From source file:org.eclipse.birt.data.oda.mongodb.internal.impl.QueryProperties.java

License:Open Source License

ReadPreference getTaggableReadPreference() {
    ReadPreference readPref = getQueryReadPreference();
    if (readPref == ReadPreference.primary())
        return readPref; // primary read preference mode does not apply tags

    DBObject tagSets = getReadPreferenceTagsAsParsedObject();
    DBObject firstTagSet = getFirstObjectSet(tagSets);
    if (firstTagSet == null)
        return readPref; // no tags in read preference

    DBObject[] remainingTagSets = getSecondaryObjectSets(tagSets);

    try {/*from   w w  w  . j a  va  2  s  . c  o m*/
        return (remainingTagSets != null)
                ? ReadPreference.valueOf(readPref.getName(), firstTagSet, remainingTagSets)
                : ReadPreference.valueOf(readPref.getName(), firstTagSet);
    } catch (RuntimeException ex) {
        // log and ignore tags
        getLogger().info(ex.getLocalizedMessage());
    }
    return readPref;
}