task.initialize(taskContext); task.start(taskConfigs.get(0)); connectorCallback.ifPresent(ConnectorCallback::taskStarted); try { logger.debug("Embedded engine is polling task for records on thread " + runningThread.get()); changeRecords = task.poll(); // blocks until there are values ... logger.debug("Embedded engine returned from polling task for records"); task.stop(); connectorCallback.ifPresent(ConnectorCallback::taskStopped);
@Override public synchronized void markProcessed(SourceRecord record) throws InterruptedException { task.commitRecord(record); recordsSinceLastCommit += 1; offsetWriter.offset(record.sourcePartition(), record.sourceOffset()); }
flush.get(Math.max(timeout - clock.currentTimeInMillis(), 0), TimeUnit.MILLISECONDS); task.commit(); recordsSinceLastCommit = 0; timeOfLastCommitMillis = clock.currentTimeInMillis();
sourceTask.initialize(sourceTaskContext); sourceTask.start(stringConfig);
/** * Start the worker. * * @return itself */ public SourceThread start() { try { task.start(config); running.set(true); } catch (Throwable t) { LOGGER.error("Unable to start task " + task.getClass().getCanonicalName(), t); try { task.stop(); } catch (Throwable tt) { //swallow } throw t; } return this; }
@Override public void initialize(SourceTaskContext context) { super.initialize(context); }
@Override public void close() throws Exception { sourceTask.stop(); } }
protected List<SourceRecord> poll() throws InterruptedException { try { return task.poll(); } catch (RetriableException e) { log.warn("{} failed to poll records from SourceTask. Will retry operation.", this, e); // Do nothing. Let the framework poll whenever it's ready. return null; } }
@Override public void execute() { try { task.initialize(new WorkerSourceTaskContext(offsetReader, this, configState)); task.start(taskConfig); log.info("{} Source task finished initialization and start", this); synchronized (this) {
/** * Construct a new instance. * * @param taskClass The task to execute. * @param config the task configuration * @param sharedSourceTaskContext the shared task context. */ public SourceThread(Class<? extends SourceTask> taskClass, Map<String, String> config, SharedSourceTaskContext sharedSourceTaskContext) throws IllegalAccessException, InstantiationException { this.task = taskClass.newInstance(); this.config = Collections.unmodifiableMap(config); this.sharedSourceTaskContext = sharedSourceTaskContext; task.initialize(sharedSourceTaskContext); }
private synchronized void tryStop() { if (!stopped) { try { task.stop(); stopped = true; } catch (Throwable t) { log.warn("Could not stop task", t); } } }
@Override public Record<byte[]> read() throws Exception { while (true) { if (currentBatch == null) { flushFuture = new CompletableFuture<>(); currentBatch = sourceTask.poll().iterator(); } if (currentBatch.hasNext()) { return processSourceRecord(currentBatch.next()); } else { boolean hasOutstandingRecords; synchronized (this) { hasOutstandingRecords = !outstandingRecords.isEmpty(); } if (hasOutstandingRecords) { // there is no records any more, then waiting for the batch to complete writing // to sink and the offsets are committed as well flushFuture.get(); flushFuture = null; } currentBatch = null; } } }
/** * Tell the work loop to end any activity ASAP. */ public void stop() { running.set(false); try { task.stop(); } catch (Exception e) { LOGGER.warn("Unable to properly stop task " + task, e ); } } }
@Override public void run() { while (running.get()) { try { List<SourceRecord> records = task.poll(); if (records != null) { records.forEach(sourceRecord -> sharedSourceTaskContext.offer(sourceRecord, LongOffset.apply(sourceRecord.sourceOffset() == null || sourceRecord.sourceOffset().isEmpty() ? UUID.randomUUID().hashCode() :sourceRecord.sourceOffset().hashCode()), task)); } } catch (InterruptedException ie) { break; } catch (Exception e) { LOGGER.warn("Unexpected error occurred while polling task " + task.getClass().getCanonicalName(), e); } } }
private void commitTaskRecord(SourceRecord record) { try { task.commitRecord(record); } catch (Throwable t) { log.error("{} Exception thrown while calling task.commitRecord()", this, t); } }
private void commitSourceTask() { try { this.task.commit(); } catch (Throwable t) { log.error("{} Exception thrown while calling task.commit()", this, t); } }
try { if (current._3() != null) { current._3().commitRecord(current._1());