com.mongodb.MongoSocketException Java Examples

The following examples show how to use com.mongodb.MongoSocketException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DataService.java    From canal-mongo with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #2
Source File: DataService.java    From canal-mongo with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #3
Source File: DataService.java    From canal-mongo with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #4
Source File: MongoDao.java    From elepy with Apache License 2.0 5 votes vote down vote up
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);
    }

}
 
Example #5
Source File: TraceMongoCommandListener.java    From brave with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}