com.mongodb.Mongo.close()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(4.8k)|赞(0)|评价(0)|浏览(218)

本文整理了Java中com.mongodb.Mongo.close()方法的一些代码示例,展示了Mongo.close()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mongo.close()方法的具体详情如下:
包路径:com.mongodb.Mongo
类名称:Mongo
方法名:close

Mongo.close介绍

[英]Closes all resources associated with this instance, in particular any open network connections. Once called, this instance and any databases obtained from it can no longer be used.
[中]关闭与此实例关联的所有资源,尤其是任何打开的网络连接。一旦调用,此实例和从中获得的任何数据库都将无法再使用。

代码示例

代码示例来源:origin: org.mongodb/mongo-java-driver

/**
 * Closes all resources associated with this instance, in particular any open network connections. Once called, this instance and any
 * databases obtained from it can no longer be used.
 */
public void close() {
  super.close();
}

代码示例来源:origin: org.mongodb/mongo-java-driver

/**
 * Attempts to find an existing MongoClient instance matching that URI in the holder, and returns it if exists. Otherwise creates a
 * new Mongo instance based on this URI and adds it to the holder.
 *
 * @param uri the Mongo URI
 * @return the client
 * @throws MongoException if there's a failure
 */
public Mongo connect(final MongoClientURI uri) {
  String key = toKey(uri);
  Mongo client = clients.get(key);
  if (client == null) {
    Mongo newbie = new MongoClient(uri);
    client = clients.putIfAbsent(key, newbie);
    if (client == null) {
      client = newbie;
    } else {
      newbie.close();
    }
  }
  return client;
}

代码示例来源:origin: Impetus/Kundera

@Override
public void destroy()
{
  indexManager.close();
  if (schemaManager != null)
  {
    schemaManager.dropSchema();
  }
  if (mongoDB != null)
  {
    logger.info("Closing connection to mongodb.");
    mongoDB.getMongo().close();
    logger.info("Closed connection to mongodb.");
  }
  else
  {
    logger.warn("Can't close connection to MONGODB, it was already disconnected");
  }
  externalProperties = null;
  schemaManager = null;
}

代码示例来源:origin: org.apache.jackrabbit/oak-mongomk

/**
   * Closes the underlying Mongo instance
   */
  public void close() {
    if (mongo != null) {
      mongo.close();
    }
  }
}

代码示例来源:origin: org.mongodb/mongodb-driver

/**
 * Closes all resources associated with this instance, in particular any open network connections. Once called, this instance and any
 * databases obtained from it can no longer be used.
 */
public void close() {
  super.close();
}

代码示例来源:origin: com.sangupta/jerry

@Override
public void run() {
  if(mongo != null) {
    mongo.close();
    mongo = null;
  }
}

代码示例来源:origin: com.sangupta/jerry-services

@Override
public void run() {
  if(mongo != null) {
    mongo.close();
    mongo = null;
  }
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-io-mongodb

@Override
 public void close() throws IOException {
  if (mongo != null) {
   mongo.close();
  }
 }
}

代码示例来源:origin: com.sangupta/jerry

/**
 * @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
 */
@Override
public void onApplicationEvent(ContextClosedEvent event) {
  if(this.mongo != null) {
    this.mongo.close();
    this.mongo = null;
  }
}

代码示例来源:origin: com.sangupta/jerry-services

/**
 * @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
 */
@Override
public void onApplicationEvent(ContextClosedEvent event) {
  if(this.mongo != null) {
    this.mongo.close();
    this.mongo = null;
  }
}

代码示例来源:origin: palominolabs/benchpress

@Override
  public void shutdown() {
    mongo.close();
  }
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-io-mongodb

@Teardown
public void teardown() {
 mongo.close();
}

代码示例来源:origin: org.apache.jmeter/ApacheJMeter_mongodb

public void clear() {
    if(log.isDebugEnabled()) {
      log.debug("clearing");
    }

    mongo.close();
    //there is no harm in trying to clear up
    mongo = null;
  }
}

代码示例来源:origin: org.mongodb.mongo-hadoop/mongo-hadoop-core

public static void close(final Mongo client) {
    MongoClientURI uri = URI_MAP.get().remove(client);
    if (uri != null) {
      MongoClient remove;
      remove = CLIENTS.get().remove(uri);
      if (remove != client) {
        throw new IllegalStateException("different clients found");
      }
      client.close();
    }
}

代码示例来源:origin: fr.opensagres.mongodb/mongo-jee

/**
 * Disconnect the whole mongo instances.
 */
public static void dispose() {
  disconnect();
  Collection<Mongo> mongos = mongosCache.values();
  for (Mongo mongo : mongos) {
    mongo.close();
  }
  mongosCache.clear();
}

代码示例来源:origin: thiloplanz/jmockmongo

@Override
protected void tearDown() throws Exception {
  if (mockMongo != null)
    mockMongo.stop();
  if (mongo != null)
    mongo.close();
}

代码示例来源:origin: org.apache.camel/camel-mongodb-gridfs

@Override
protected void doStop() throws Exception {
  super.doStop();
  if (mongoConnection != null) {
    LOG.debug("Closing connection");
    mongoConnection.close();
  }
}

代码示例来源:origin: yc-huang/Hive-mongo

public void close() {
  if (db != null) {
    db.getMongo().close();
  }
}

代码示例来源:origin: org.apache.jackrabbit/oak-mongomk

@Override
public void dispose() {
  if (LOG.isDebugEnabled()) {
    LOG.debug("MongoDB time: " + timeSum);
  }
  nodes.getDB().getMongo().close();
}

代码示例来源:origin: org.eclipse.persistence/org.eclipse.persistence.nosql

/**
 * Close the AQ native session and the database connection.
 */
public void close() throws ResourceException {
  try {
    this.db.getMongo().close();
  } catch (Exception exception) {
    ResourceException resourceException = new ResourceException(exception.toString());
    resourceException.initCause(exception);
    throw resourceException;
  }
}

相关文章