类com.mongodb.MongoSocketException源码实例Demo

下面列出了怎么用com.mongodb.MongoSocketException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: canal-mongo   文件: DataService.java
public void insertData(String schemaName, String tableName, DBObject naive, DBObject complete) {
    int i = 0;
    DBObject logObj = (DBObject) ObjectUtils.clone(complete);
    //保存原始数据
    try {
        String path = "/" + schemaName + "/" + tableName + "/" + CanalEntry.EventType.INSERT.getNumber();
        i++;
        naiveMongoTemplate.getCollection(tableName).insert(naive);
        i++;
        SpringUtil.doEvent(path, complete);
        i++;
    } catch (MongoClientException | MongoSocketException clientException) {
        //客户端连接异常抛出,阻塞同步,防止mongodb宕机
        throw clientException;
    } catch (Exception e) {
        logError(schemaName, tableName, 1, i, logObj, e);
    }
}
 
源代码2 项目: canal-mongo   文件: DataService.java
public void updateData(String schemaName, String tableName, DBObject query, DBObject obj) {
    String path = "/" + schemaName + "/" + tableName + "/" + CanalEntry.EventType.UPDATE.getNumber();
    int i = 0;
    DBObject newObj = (DBObject) ObjectUtils.clone(obj);
    DBObject logObj = (DBObject) ObjectUtils.clone(obj);
    //保存原始数据
    try {
        obj.removeField("id");
        i++;
        naiveMongoTemplate.getCollection(tableName).update(query, obj);
        i++;
        SpringUtil.doEvent(path, newObj);
        i++;
    } catch (MongoClientException | MongoSocketException clientException) {
        //客户端连接异常抛出,阻塞同步,防止mongodb宕机
        throw clientException;
    } catch (Exception e) {
        logError(schemaName, tableName, 2, i, logObj, e);
    }
}
 
源代码3 项目: canal-mongo   文件: DataService.java
public void deleteData(String schemaName, String tableName, DBObject obj) {
    int i = 0;
    String path = "/" + schemaName + "/" + tableName + "/" + CanalEntry.EventType.DELETE.getNumber();
    DBObject newObj = (DBObject) ObjectUtils.clone(obj);
    DBObject logObj = (DBObject) ObjectUtils.clone(obj);
    //保存原始数据
    try {
        i++;
        if (obj.containsField("id")) {
            naiveMongoTemplate.getCollection(tableName).remove(new BasicDBObject("_id", obj.get("id")));
        }
        i++;
        SpringUtil.doEvent(path, newObj);
    } catch (MongoClientException | MongoSocketException clientException) {
        //客户端连接异常抛出,阻塞同步,防止mongodb宕机
        throw clientException;
    } catch (Exception e) {
        logError(schemaName, tableName, 3, i, logObj, e);
    }
}
 
源代码4 项目: elepy   文件: MongoDao.java
private void createIndexes() {
    try {
        Arrays.stream(schema.getJavaClass().getAnnotationsByType(MongoIndex.class))
                .forEach(this::createIndex);


        schema.getProperties().stream().filter(Property::isUnique)
                .forEach(property -> mongoCollection.createIndex(new BasicDBObject(property.getName(), 1)));
    } catch (MongoSocketException e) {
        logger.error("Failed at creating index", e);
    }

}
 
源代码5 项目: brave   文件: TraceMongoCommandListener.java
/**
 * Uses {@link ThreadLocalSpan} as there's no attribute namespace shared between callbacks, but
 * all callbacks happen on the same thread.
 */
@Override public void commandStarted(CommandStartedEvent event) {
  Span span = threadLocalSpan.next();
  if (span == null || span.isNoop()) return;

  String commandName = event.getCommandName();
  String databaseName = event.getDatabaseName();
  BsonDocument command = event.getCommand();
  String collectionName = getCollectionName(command, commandName);

  span.name(getSpanName(commandName, collectionName))
    .kind(CLIENT)
    .remoteServiceName("mongodb-" + databaseName)
    .tag("mongodb.command", commandName);

  if (collectionName != null) {
    span.tag("mongodb.collection", collectionName);
  }

  ConnectionDescription connectionDescription = event.getConnectionDescription();
  if (connectionDescription != null) {
    ConnectionId connectionId = connectionDescription.getConnectionId();
    if (connectionId != null) {
      span.tag("mongodb.cluster_id", connectionId.getServerId().getClusterId().getValue());
    }

    try {
      InetSocketAddress socketAddress =
        connectionDescription.getServerAddress().getSocketAddress();
      span.remoteIpAndPort(socketAddress.getAddress().getHostAddress(), socketAddress.getPort());
    } catch (MongoSocketException ignored) {

    }
  }

  span.start();
}
 
 类所在包
 同包方法