use of io.openmessaging.connector.api.source.SourceTaskContext in project rocketmq-externals by apache.
the class RedisSourceTaskTest method initAndStartTask.
@Before
public void initAndStartTask() {
try {
initKeyValue();
this.task = new RedisSourceTask();
this.task.initialize(new SourceTaskContext() {
@Override
public PositionStorageReader positionStorageReader() {
return new PositionStorageReader() {
@Override
public ByteBuffer getPosition(ByteBuffer byteBuffer) {
return null;
}
@Override
public Map<ByteBuffer, ByteBuffer> getPositions(Collection<ByteBuffer> collection) {
return null;
}
};
}
@Override
public KeyValue configs() {
return keyValue;
}
});
this.task.start(this.keyValue);
} catch (JedisConnectionException e) {
}
}
use of io.openmessaging.connector.api.source.SourceTaskContext in project rocketmq-externals by apache.
the class WorkerSourceTask method run.
/**
* Start a source task, and send data entry to MQ cyclically.
*/
@Override
public void run() {
try {
producer.start();
log.info("Source task producer start.");
state.compareAndSet(WorkerTaskState.NEW, WorkerTaskState.PENDING);
sourceTask.initialize(new SourceTaskContext() {
@Override
public PositionStorageReader positionStorageReader() {
return positionStorageReader;
}
@Override
public KeyValue configs() {
return taskConfig;
}
});
sourceTask.start(taskConfig);
state.compareAndSet(WorkerTaskState.PENDING, WorkerTaskState.RUNNING);
log.info("Source task start, config:{}", JSON.toJSONString(taskConfig));
while (WorkerState.STARTED == workerState.get() && WorkerTaskState.RUNNING == state.get()) {
try {
Collection<SourceDataEntry> toSendEntries = sourceTask.poll();
if (null != toSendEntries && toSendEntries.size() > 0) {
sendRecord(toSendEntries);
}
} catch (Exception e) {
log.error("Source task runtime exception", e);
state.set(WorkerTaskState.ERROR);
}
}
sourceTask.stop();
state.compareAndSet(WorkerTaskState.STOPPING, WorkerTaskState.STOPPED);
log.info("Source task stop, config:{}", JSON.toJSONString(taskConfig));
} catch (Exception e) {
log.error("Run task failed.", e);
state.set(WorkerTaskState.ERROR);
} finally {
if (producer != null) {
producer.shutdown();
log.info("Source task producer shutdown.");
}
}
}
use of io.openmessaging.connector.api.source.SourceTaskContext in project rocketmq-externals by apache.
the class WorkerDirectTask method startSourceTask.
private void startSourceTask() {
state.compareAndSet(WorkerTaskState.NEW, WorkerTaskState.PENDING);
sourceTask.initialize(new SourceTaskContext() {
@Override
public PositionStorageReader positionStorageReader() {
return positionStorageReader;
}
@Override
public KeyValue configs() {
return taskConfig;
}
});
sourceTask.start(taskConfig);
state.compareAndSet(WorkerTaskState.PENDING, WorkerTaskState.RUNNING);
log.info("Source task start, config:{}", JSON.toJSONString(taskConfig));
}
Aggregations