use of org.apache.kafka.connect.util.LoggingContext in project kafka by apache.
the class Worker method stopTask.
private void stopTask(ConnectorTaskId taskId) {
try (LoggingContext loggingContext = LoggingContext.forTask(taskId)) {
WorkerTask task = tasks.get(taskId);
if (task == null) {
log.warn("Ignoring stop request for unowned task {}", taskId);
return;
}
log.info("Stopping task {}", task.id());
if (task instanceof WorkerSourceTask)
sourceTaskOffsetCommitter.remove(task.id());
ClassLoader savedLoader = plugins.currentThreadLoader();
try {
savedLoader = Plugins.compareAndSwapLoaders(task.loader());
task.stop();
} finally {
Plugins.compareAndSwapLoaders(savedLoader);
}
}
}
use of org.apache.kafka.connect.util.LoggingContext in project kafka by apache.
the class WorkerTask method run.
@Override
public void run() {
// Clear all MDC parameters, in case this thread is being reused
LoggingContext.clear();
try (LoggingContext loggingContext = LoggingContext.forTask(id())) {
ClassLoader savedLoader = Plugins.compareAndSwapLoaders(loader);
String savedName = Thread.currentThread().getName();
try {
Thread.currentThread().setName(THREAD_NAME_PREFIX + id);
doRun();
onShutdown();
} catch (Throwable t) {
onFailure(t);
if (t instanceof Error)
throw (Error) t;
} finally {
Thread.currentThread().setName(savedName);
Plugins.compareAndSwapLoaders(savedLoader);
shutdownLatch.countDown();
}
}
}
use of org.apache.kafka.connect.util.LoggingContext in project kafka by apache.
the class Worker method stopConnector.
/**
* Stop a connector managed by this worker.
*
* @param connName the connector name.
*/
private void stopConnector(String connName) {
try (LoggingContext loggingContext = LoggingContext.forConnector(connName)) {
WorkerConnector workerConnector = connectors.get(connName);
log.info("Stopping connector {}", connName);
if (workerConnector == null) {
log.warn("Ignoring stop request for unowned connector {}", connName);
return;
}
ClassLoader savedLoader = plugins.currentThreadLoader();
try {
savedLoader = Plugins.compareAndSwapLoaders(workerConnector.loader());
workerConnector.shutdown();
} finally {
Plugins.compareAndSwapLoaders(savedLoader);
}
}
}
use of org.apache.kafka.connect.util.LoggingContext in project kafka by apache.
the class WorkerConnector method run.
@Override
public void run() {
// Clear all MDC parameters, in case this thread is being reused
LoggingContext.clear();
try (LoggingContext loggingContext = LoggingContext.forConnector(connName)) {
ClassLoader savedLoader = Plugins.compareAndSwapLoaders(loader);
String savedName = Thread.currentThread().getName();
try {
Thread.currentThread().setName(THREAD_NAME_PREFIX + connName);
doRun();
} finally {
Thread.currentThread().setName(savedName);
Plugins.compareAndSwapLoaders(savedLoader);
}
} finally {
// In the rare case of an exception being thrown outside the doRun() method, or an
// uncaught one being thrown from within it, mark the connector as shut down to avoid
// unnecessarily blocking and eventually timing out during awaitShutdown
shutdownLatch.countDown();
}
}
use of org.apache.kafka.connect.util.LoggingContext in project kafka by apache.
the class SourceTaskOffsetCommitter method schedule.
public void schedule(final ConnectorTaskId id, final WorkerSourceTask workerTask) {
long commitIntervalMs = config.getLong(WorkerConfig.OFFSET_COMMIT_INTERVAL_MS_CONFIG);
ScheduledFuture<?> commitFuture = commitExecutorService.scheduleWithFixedDelay(() -> {
try (LoggingContext loggingContext = LoggingContext.forOffsets(id)) {
commit(workerTask);
}
}, commitIntervalMs, commitIntervalMs, TimeUnit.MILLISECONDS);
committers.put(id, commitFuture);
}
Aggregations