Search in sources :

Example 1 with SourceTaskConfig

use of org.apache.connect.mongo.SourceTaskConfig in project rocketmq-externals by apache.

the class MongoSourceTask method start.

@Override
public void start(KeyValue config) {
    try {
        sourceTaskConfig = new SourceTaskConfig();
        sourceTaskConfig.load(config);
        replicaSetsContext = new ReplicaSetsContext(sourceTaskConfig);
        replicaSetManager = ReplicaSetManager.create(sourceTaskConfig.getMongoAddr());
        replicaSetManager.getReplicaConfigByName().forEach((replicaSetName, replicaSetConfig) -> {
            ByteBuffer byteBuffer = this.context.positionStorageReader().getPosition(ByteBuffer.wrap(replicaSetName.getBytes()));
            if (byteBuffer != null && byteBuffer.array().length > 0) {
                String positionJson = new String(byteBuffer.array(), StandardCharsets.UTF_8);
                Position position = JSONObject.parseObject(positionJson, Position.class);
                replicaSetConfig.setPosition(position);
            } else {
                Position position = new Position();
                position.setTimeStamp(sourceTaskConfig.getPositionTimeStamp());
                position.setInc(sourceTaskConfig.getPositionInc());
                position.setInitSync(sourceTaskConfig.isDataSync());
                replicaSetConfig.setPosition(position);
            }
            ReplicaSet replicaSet = new ReplicaSet(replicaSetConfig, replicaSetsContext);
            replicaSetsContext.addReplicaSet(replicaSet);
            replicaSet.start();
        });
    } catch (Throwable throwable) {
        logger.error("task start error", throwable);
        stop();
    }
}
Also used : Position(org.apache.connect.mongo.replicator.Position) ReplicaSetsContext(org.apache.connect.mongo.replicator.ReplicaSetsContext) SourceTaskConfig(org.apache.connect.mongo.SourceTaskConfig) ByteBuffer(java.nio.ByteBuffer) ReplicaSet(org.apache.connect.mongo.replicator.ReplicaSet)

Aggregations

ByteBuffer (java.nio.ByteBuffer)1 SourceTaskConfig (org.apache.connect.mongo.SourceTaskConfig)1 Position (org.apache.connect.mongo.replicator.Position)1 ReplicaSet (org.apache.connect.mongo.replicator.ReplicaSet)1 ReplicaSetsContext (org.apache.connect.mongo.replicator.ReplicaSetsContext)1