Example usage for com.mongodb Bytes QUERYOPTION_NOTIMEOUT

List of usage examples for com.mongodb Bytes QUERYOPTION_NOTIMEOUT

Introduction

In this page you can find the example usage for com.mongodb Bytes QUERYOPTION_NOTIMEOUT.

Prototype

int QUERYOPTION_NOTIMEOUT

To view the source code for com.mongodb Bytes QUERYOPTION_NOTIMEOUT.

Click Source Link

Document

The server normally times out idle cursors after an inactivity period (10 minutes) to prevent excess memory use.

Usage

From source file:act.server.MongoDB.java

License:Open Source License

public DBIterator getDbIteratorOverSeq(BasicDBObject matchCriterion, BasicDBObject keys) {
    if (keys == null) {
        keys = new BasicDBObject();
    }/* ww w .  ja v  a 2  s . co  m*/

    DBCursor cursor = this.dbSeq.find(matchCriterion, keys);
    cursor = cursor.addOption(Bytes.QUERYOPTION_NOTIMEOUT);
    return new DBIterator(cursor);
}

From source file:act.server.MongoDB.java

License:Open Source License

public DBIterator getIteratorOverChemicals(BasicDBObject matchCriterion, BasicDBObject keys) {
    if (keys == null) {
        keys = new BasicDBObject();
    }/*from   w w  w  .j  av a2s  .  c om*/
    DBCursor cursor = this.dbChemicals.find(matchCriterion, keys);
    cursor = cursor.addOption(Bytes.QUERYOPTION_NOTIMEOUT);

    return new DBIterator(cursor); // DBIterator is just a wrapper class
}

From source file:act.server.MongoDB.java

License:Open Source License

public DBIterator getIteratorOverReactions(BasicDBObject matchCriterion, BasicDBObject keys) {

    if (keys == null) {
        keys = new BasicDBObject();
    }// w  w  w.j  av  a 2s .c om

    DBCursor cursor = this.dbReactions.find(matchCriterion, keys);
    cursor = cursor.addOption(Bytes.QUERYOPTION_NOTIMEOUT);
    return new DBIterator(cursor); // DBIterator is just a wrapper classs
}

From source file:act.server.MongoDB.java

License:Open Source License

public DBIterator getDbIteratorOverOrgs(BasicDBObject matchCriterion, BasicDBObject keys) {
    if (keys == null) {
        keys = new BasicDBObject();
    }/*w  w w .j a  v a  2s .c  o  m*/

    DBCursor cursor = this.dbOrganismNames.find(matchCriterion, keys);
    cursor = cursor.addOption(Bytes.QUERYOPTION_NOTIMEOUT);
    return new DBIterator(cursor);
}

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

License:Apache License

public static String queryOptionsToString(int options) {
    String opt = "";
    if ((options & Bytes.QUERYOPTION_TAILABLE) != 0) {
        opt += "TAILABLE ";
    }//w ww .  j av  a2 s .  co m
    if ((options & Bytes.QUERYOPTION_SLAVEOK) != 0) {
        opt += "SLAVEOK ";
    }
    if ((options & Bytes.QUERYOPTION_OPLOGREPLAY) != 0) {
        opt += "OPLOGREPLAY ";
    }
    if ((options & Bytes.QUERYOPTION_NOTIMEOUT) != 0) {
        opt += "NOTIMEOUT ";
    }
    if ((options & Bytes.QUERYOPTION_AWAITDATA) != 0) {
        opt += "AWAITDATA ";
    }
    if ((options & Bytes.QUERYOPTION_EXHAUST) != 0) {
        opt += "EXHAUST ";
    }
    return opt;
}

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

License:Apache License

void update(int options, WriteConcern wc, ReadPreference rp) {
    // reset/*from www . ja v a  2s.c o  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:com.edgytech.umongo.OptionDialog.java

License:Apache License

int getQueryOptions() {
    int options = 0;
    if (getBooleanFieldValue(Item.tailable))
        options |= Bytes.QUERYOPTION_TAILABLE;
    if (getBooleanFieldValue(Item.slaveOk))
        options |= Bytes.QUERYOPTION_SLAVEOK;
    if (getBooleanFieldValue(Item.opLogReplay))
        options |= Bytes.QUERYOPTION_OPLOGREPLAY;
    if (getBooleanFieldValue(Item.noTimeout))
        options |= Bytes.QUERYOPTION_NOTIMEOUT;
    if (getBooleanFieldValue(Item.awaitData))
        options |= Bytes.QUERYOPTION_AWAITDATA;
    if (getBooleanFieldValue(Item.exhaust))
        options |= Bytes.QUERYOPTION_EXHAUST;
    if (getBooleanFieldValue(Item.partial))
        options |= Bytes.QUERYOPTION_PARTIAL;
    return options;
}

From source file:com.ikanow.infinit.e.data_model.custom.InfiniteMongoInputSplit.java

License:Apache License

@SuppressWarnings("deprecation")
@Override/*from  w w w.  j a v a2s.  c o m*/
protected DBCursor getCursor() {
    //added the limit and skip
    if (_createCursor && (_cursor == null)) {

        DBObject query = null;
        BasicBSONObject queryObj = (BasicBSONObject) _querySpec.get("$query");
        BasicBSONObject minObj = (BasicBSONObject) _querySpec.get("$min");
        BasicBSONObject maxObj = (BasicBSONObject) _querySpec.get("$max");
        if (null == queryObj) {
            if ((null != minObj) || (null != maxObj)) { // one of min/max specified
                query = new BasicDBObject();
            } else { // no $query, $max or $min => this is the query
                query = _querySpec;
            }
        } else {
            query = new BasicDBObject(queryObj);
        }
        _cursor = InfiniteMongoConfigUtil.getCollection(_mongoURI).find(query, _fieldSpec).sort(_sortSpec)
                .limit(_limit).skip(_skip);

        if (null != minObj) {

            Iterator<Map.Entry<String, Object>> it = minObj.entrySet().iterator();
            while (it.hasNext()) { // remove upper/lower limit objects because not sure about new mongo syntax 
                Map.Entry<String, Object> keyVal = it.next();
                if (keyVal.getValue() instanceof org.bson.types.MinKey) {
                    it.remove();
                }
            }
            if (!minObj.isEmpty()) {
                _cursor = _cursor.addSpecial("$min", new BasicDBObject(minObj));
            }
        }
        if (null != maxObj) {
            Iterator<Map.Entry<String, Object>> it = maxObj.entrySet().iterator();
            while (it.hasNext()) { // remove upper/lower limit objects because not sure about new mongo syntax 
                Map.Entry<String, Object> keyVal = it.next();
                if (keyVal.getValue() instanceof org.bson.types.MaxKey) {
                    it.remove();
                }
            }
            if (!maxObj.isEmpty()) {
                _cursor = _cursor.addSpecial("$max", new BasicDBObject(maxObj));
            }
        }

        //DEBUG
        //log.info( "Created InfiniteMongoInputSplit cursor: min=" + minObj + ", max=" + maxObj + ", query=" + query );

        if (_notimeout)
            _cursor.setOptions(Bytes.QUERYOPTION_NOTIMEOUT);
        _cursor.slaveOk();
    }

    return _cursor;
}

From source file:com.jive.myco.seyren.mongo.MongoStore.java

License:Apache License

private void addTargetHashToAlerts() {
    LOGGER.info("Adding targetHash field to any alerts which don't have it");
    DBCursor alerts = getAlertsCollection()
            .find(new BasicDBObject("targetHash", new BasicDBObject("$exists", false)));
    alerts.addOption(Bytes.QUERYOPTION_NOTIMEOUT);
    int alertCount = alerts.count();
    if (alertCount > 0) {
        LOGGER.info("Found {} alert(s) which need updating", alertCount);
    }// ww w .  java 2s .c o  m
    while (alerts.hasNext()) {
        DBObject alertObject = alerts.next();
        Alert alert = mapper.alertFrom(alertObject);
        getAlertsCollection().save(mapper.alertToDBObject(alert));
    }
}

From source file:com.zjy.mongo.input.MongoInputSplit.java

License:Apache License

public DBCursor getCursor() {
    if (this.cursor == null) {
        DBCollection coll;//from w  w w .  j a v  a  2s  .c  o  m
        if (this.authURI != null) {
            coll = MongoConfigUtil.getCollectionWithAuth(this.inputURI, this.authURI);
        } else {
            coll = MongoConfigUtil.getCollection(this.inputURI);
        }

        this.cursor = coll.find(this.query, this.fields).sort(this.sort);
        if (this.notimeout) {
            this.cursor.setOptions(Bytes.QUERYOPTION_NOTIMEOUT);
        }
        if (this.min != null) {
            this.cursor.addSpecial("$min", this.min);
        }
        if (this.max != null) {
            this.cursor.addSpecial("$max", this.max);
        }
    }
    return this.cursor;
}