當前位置: 首頁>>代碼示例>>Java>>正文


Java MongoClient.close方法代碼示例

本文整理匯總了Java中com.mongodb.MongoClient.close方法的典型用法代碼示例。如果您正苦於以下問題:Java MongoClient.close方法的具體用法?Java MongoClient.close怎麽用?Java MongoClient.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.mongodb.MongoClient的用法示例。


在下文中一共展示了MongoClient.close方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testInsert

import com.mongodb.MongoClient; //導入方法依賴的package包/類
@Test
@Ignore
public void testInsert() {
    MongoClient mongoClient = new MongoClient("localhost", 27017);
    try {
        MongoDatabase db = mongoClient.getDatabase("prova");
        MongoCollection<Document> coll = db.getCollection("prova");
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("signature", "void test()");
        map.put("param", convert(new Object[0]));
        map.put("returnValue", 1);
        map.put("exception", convert(new IllegalAccessError("prova")));
        Document doc = new Document(map);
        coll.insertOne(doc);
        LOG.info(doc);
    } catch (Exception e) {
        LOG.error(e);
    } finally {
        mongoClient.close();
    }
}
 
開發者ID:sap-nocops,項目名稱:Jerkoff,代碼行數:22,代碼來源:MongoTest.java

示例2: testMongo1

import com.mongodb.MongoClient; //導入方法依賴的package包/類
@POST
@Path("testMongo1")
public void testMongo1(String jsonString) {

    MongoClient client = new MongoClient();
    client.listDatabaseNames().first();
    MongoDatabase db = client.getDatabase("apphubDataStore");
    db.listCollectionNames().first();
    MongoCollection<Document> collection = db.getCollection("test");
    collection.listIndexes().first();
    Document doc = new Document("name", "Amarcord Pizzeria")
            .append("contact",
                    new Document("phone", "264-555-0193").append("email", "[email protected]")
                            .append("location", Arrays.asList(-73.88502, 40.749556)))
            .append("stars", 2).append("categories", Arrays.asList("Pizzeria", "Italian", "Pasta"));
    collection.insertOne(doc);
    collection.find().first();

    MongoClient client2 = new MongoClient("localhost:27017");
    db = client2.getDatabase("apphubDataStore");
    db.listCollectionNames().first();
    collection = db.getCollection("test");
    collection.listIndexes().first();

    client.close();
    client2.close();
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:28,代碼來源:TestRestService.java

示例3: testRead

import com.mongodb.MongoClient; //導入方法依賴的package包/類
@Test
@Ignore
public void testRead() {
    MongoClient mongoClient = new MongoClient("localhost", 27017);
    try {
        MongoDatabase db = mongoClient.getDatabase("prova");
        MongoCollection<Document> coll = db.getCollection("prova");
        FindIterable<Document> res = coll.find();
        for (Document doc : res) {
            String thisObj = doc.getString("this");
            LOG.info(thisObj);
            String thisClass = doc.getString("thisClass");
            LOG.info(thisClass);
            Gson gson = new Gson();
            Class<?> cl = Class.forName(thisClass);
            Object obj = gson.fromJson(thisObj, cl);
            LOG.info(obj);
        }
    } catch (Exception e) {
        LOG.error(e);
    } finally {
        mongoClient.close();
    }
}
 
開發者ID:sap-nocops,項目名稱:Jerkoff,代碼行數:25,代碼來源:MongoTest.java

示例4: test_mongoservice_not_enabled

import com.mongodb.MongoClient; //導入方法依賴的package包/類
@Test
public void test_mongoservice_not_enabled() throws InitializationException {
    final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);
    final StandardMongoClientService service = new StandardMongoClientService();

    runner.addControllerService("test-mongo-closed", service);
    runner.enableControllerService(service);

    // Close MongoClient
    MongoClient client = service.getMongoClient();

    // NOTE: This test requires mongo to be running
    assertEquals("localhost:27017", client.getConnectPoint());

    // Close the mongo connection
    client.close();

    // Now, this should throw an illegal state exception
    thrown.expect(IllegalStateException.class);
    client.getConnectPoint();
}
 
開發者ID:Asymmetrik,項目名稱:nifi-nars,代碼行數:22,代碼來源:StandardMongoClientServiceIT.java

示例5: closeMongoClient

import com.mongodb.MongoClient; //導入方法依賴的package包/類
/**
 * close the mongo client 
 * 
 * @param mongoClient - client which is have to close 
 */
public void closeMongoClient(MongoClient mongoClient) {
	try {
		if (mongoClient != null) {
			mongoClient.close();
		}
	} catch (MongoException e) {
		log.error("Exception occurred while close MongoClient : " + e, e);
	}
}
 
開發者ID:sundarcse1216,項目名稱:mongodb-crud,代碼行數:15,代碼來源:MongoConnectionUtils.java

示例6: test

import com.mongodb.MongoClient; //導入方法依賴的package包/類
/**
 * 測試用例
 * 
 * @return
 */
@GET
@Path("test")
public String test() {

    MongoClient client = new MongoClient();
    client.listDatabaseNames().first();
    MongoDatabase db = client.getDatabase("apphubDataStore");
    db.listCollectionNames().first();
    MongoCollection<Document> collection = db.getCollection("test");
    collection.listIndexes().first();
    Document doc = new Document("name", "Amarcord Pizzeria")
            .append("contact",
                    new Document("phone", "264-555-0193").append("email", "[email protected]")
                            .append("location", Arrays.asList(-73.88502, 40.749556)))
            .append("stars", 2).append("categories", Arrays.asList("Pizzeria", "Italian", "Pasta"));
    collection.insertOne(doc);
    collection.find().first();

    // MongoClient client2 = new MongoClient("localhost:27017");
    // db = client2.getDatabase("apphubDataStore");
    // db.listCollectionNames().first();
    // collection = db.getCollection("test");
    // collection.listIndexes().first();

    client.close();
    // client2.close();
    return "mongo perfect";
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:34,代碼來源:MongoService.java

示例7: main

import com.mongodb.MongoClient; //導入方法依賴的package包/類
public static void main(String args[]) {

        ConsoleLogger cl = new ConsoleLogger("test");

        cl.setDebugable(true);

        UAVServer.instance().setLog(cl);

        UAVServer.instance().putServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR, ServerVendor.TOMCAT);

        MongoClientHookProxy p = new MongoClientHookProxy("test", Collections.emptyMap());

        p.doInstallDProxy(null, "testApp");

        MongoClient client = new MongoClient();
        client.listDatabaseNames().first();
        MongoDatabase db = client.getDatabase("apphubDataStore");
        db.listCollectionNames().first();
        MongoCollection<Document> collection = db.getCollection("test");
        collection.listIndexes().first();
        Document doc = new Document("name", "Amarcord Pizzeria")
                .append("contact",
                        new Document("phone", "264-555-0193").append("email", "[email protected]")
                                .append("location", Arrays.asList(-73.88502, 40.749556)))
                .append("stars", 2).append("categories", Arrays.asList("Pizzeria", "Italian", "Pasta"));
        collection.insertOne(doc);
        collection.find().first();

        MongoClient client2 = new MongoClient("localhost:27017");
        db = client2.getDatabase("apphubDataStore");
        db.listCollectionNames().first();
        collection = db.getCollection("test");
        collection.listIndexes().first();

        client.close();
        client2.close();
    }
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:38,代碼來源:DoTestMongoClientProxy.java

示例8: MongoTransporterConfig

import com.mongodb.MongoClient; //導入方法依賴的package包/類
public MongoTransporterConfig(Config config) {
    try {
        MongoClientOptions.Builder builder = MongoClientOptions.builder().connectTimeout(5000).socketTimeout(5000).serverSelectionTimeout(3000);
        client = new MongoClient(new ServerAddress(config.getConfigString("host"), config.getConfigInt("port")), builder.build());
        client.getAddress();
        database = client.getDatabase(config.getConfigString("database"));
        collection = database.getCollection(config.getConfigString("collection"));
    } catch (MongoTimeoutException e) {
        client.close();
        log.error("MongoClient initial failed", e);
        throw new LogregatorException();
    }
}
 
開發者ID:geminiKim,項目名稱:logregator,代碼行數:14,代碼來源:MongoTransporterConfig.java

示例9: tearDown

import com.mongodb.MongoClient; //導入方法依賴的package包/類
@After
public void tearDown() throws Exception {
    if (null != mongo) {
        MongoClient client = mongo.getMongoClient();
        if (client != null) {
            MongoDatabase db = client.getDatabase(MONGO_DATABASE_NAME);
            if (db != null) {
                db.drop();
            }
            client.close();
        }
    }
}
 
開發者ID:Asymmetrik,項目名稱:nifi-nars,代碼行數:14,代碼來源:StoreInMongoIT.java

示例10: tearDown

import com.mongodb.MongoClient; //導入方法依賴的package包/類
@After
public void tearDown() throws Exception {
    if (null != mongo) {
        MongoClient client = mongo.getMongoClient();
        MongoDatabase db = client.getDatabase(MONGO_DATABASE_NAME);
        if (db != null) {
            db.drop();
        }
        client.close();
    }
}
 
開發者ID:Asymmetrik,項目名稱:nifi-nars,代碼行數:12,代碼來源:QueryMongoIT.java

示例11: destroyTestStorageGuard

import com.mongodb.MongoClient; //導入方法依賴的package包/類
/**
 * A method that destroys the test storage guard.
 */
private void destroyTestStorageGuard() {
  MongoClient testMongoClient = testStorageGuard.getMongo();
  testMongoClient.dropDatabase(TEST_DATABASE_NAME);
  testMongoClient.close();
}
 
開發者ID:catalincraciun,項目名稱:scancode,代碼行數:9,代碼來源:ScancodeStorageTests.java

示例12: main

import com.mongodb.MongoClient; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static void main(String[] args) {

	try {

		MongoClient mongoClient = new MongoClient(host, port);

		MongoDatabase db = mongoClient.getDatabase(database);

		MongoCollection<Document> jugsCollection = db.getCollection(collection);

		System.out.println("-------- MongoDB JUG List from REGION 4 (Java Driver only) ------------");

		List<Document> mongodbDocuments = jugsCollection.find(eq("region", "Sudeste"))
				.into(new ArrayList<Document>());

		List<JUG> jugsList = new ArrayList<JUG>();

		System.out.println(mongodbDocuments);
		List<Document> jugsDocument = (List<Document>) mongodbDocuments.get(0).get("jugs");

		jugsList = jugsDocument.stream().map(obj -> new JUG((String) obj.get("name"),
				(String) obj.get("description"), (String) obj.get("local"), (String) obj.get("url")))
				.collect(Collectors.toList());

		jugsList.stream().forEach(System.out::println);

		mongoClient.close();

	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:boaglio,項目名稱:mongodb-java-examples,代碼行數:34,代碼來源:JUGsList.java


注:本文中的com.mongodb.MongoClient.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。