Rely on MProducerSupport.active for Flux (#3423)
* Rely on `MProducerSupport.active` for `Flux` * Fix `MessageProducerSupport` to extract an `active` flag and set it before `isRunning` - the `Flux` subscription relies on the `takeWhile()` where in case of `autoStartup = false` we will never start consume because it is set to `true` already after `doStart()` * Refactor all the `MessageProducerSupport` implementation with similar `active` state to use already one from the super class **Cherry-pick to 5.3.x** * * Remove `MessageProducerSupport.setActive()` to not let to mutate it from the implementations * Set `active` to `false` in the `destroy()` * Clean up and fix typos in the affected `JmsMessageDrivenEndpoint` * * Pull `active` flag down to the `AbstractEndpoint` * Set `active = true` in the `start()` before calling `doStart()` * Do same for `active = false` in the `stop()` * Clean up `AbstractEndpoint` impls to not call `doStart/doStop` for nothing * Refactor endpoints to rely on the `active` state from the `AbstractEndpoint` not their own
This commit is contained in:
committed by
Gary Russell
parent
27b464ad27
commit
002382e647
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,20 +23,22 @@ import org.apache.commons.io.input.TailerListener;
|
||||
* File tailer that delegates to the Apache Commons Tailer.
|
||||
*
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 3.0
|
||||
*
|
||||
*/
|
||||
public class ApacheCommonsFileTailingMessageProducer extends FileTailingMessageProducerSupport
|
||||
implements TailerListener {
|
||||
|
||||
private long pollingDelay = 1000;
|
||||
|
||||
private boolean end = true;
|
||||
|
||||
private boolean reopen = false;
|
||||
|
||||
private volatile Tailer tailer;
|
||||
|
||||
private volatile long pollingDelay = 1000;
|
||||
|
||||
private volatile boolean end = true;
|
||||
|
||||
private volatile boolean reopen = false;
|
||||
|
||||
/**
|
||||
* The delay between checks of the file for new content in milliseconds.
|
||||
* @param pollingDelay The delay.
|
||||
@@ -71,8 +73,8 @@ public class ApacheCommonsFileTailingMessageProducer extends FileTailingMessageP
|
||||
@Override
|
||||
protected void doStart() {
|
||||
super.doStart();
|
||||
Tailer theTailer = new Tailer(this.getFile(), this, this.pollingDelay, this.end, this.reopen);
|
||||
this.getTaskExecutor().execute(theTailer);
|
||||
Tailer theTailer = new Tailer(getFile(), this, this.pollingDelay, this.end, this.reopen);
|
||||
getTaskExecutor().execute(theTailer);
|
||||
this.tailer = theTailer;
|
||||
}
|
||||
|
||||
@@ -88,9 +90,9 @@ public class ApacheCommonsFileTailingMessageProducer extends FileTailingMessageP
|
||||
|
||||
@Override
|
||||
public void fileNotFound() {
|
||||
this.publish("File not found: " + this.getFile().getAbsolutePath());
|
||||
publish("File not found: " + getFile().getAbsolutePath());
|
||||
try {
|
||||
Thread.sleep(this.getMissingFileDelay());
|
||||
Thread.sleep(getMissingFileDelay());
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
@@ -99,7 +101,7 @@ public class ApacheCommonsFileTailingMessageProducer extends FileTailingMessageP
|
||||
|
||||
@Override
|
||||
public void fileRotated() {
|
||||
this.publish("File rotated: " + this.getFile().getAbsolutePath());
|
||||
publish("File rotated: " + getFile().getAbsolutePath());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -109,7 +111,7 @@ public class ApacheCommonsFileTailingMessageProducer extends FileTailingMessageP
|
||||
|
||||
@Override
|
||||
public void handle(Exception ex) {
|
||||
this.publish(ex.getMessage());
|
||||
publish(ex.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -145,7 +145,6 @@ public abstract class FileTailingMessageProducerSupport extends MessageProducerS
|
||||
|
||||
@Override
|
||||
protected void doStart() {
|
||||
super.doStart();
|
||||
if (this.idleEventInterval > 0) {
|
||||
this.idleEventScheduledFuture = getTaskScheduler().scheduleWithFixedDelay(() -> {
|
||||
long now = System.currentTimeMillis();
|
||||
@@ -162,7 +161,6 @@ public abstract class FileTailingMessageProducerSupport extends MessageProducerS
|
||||
|
||||
@Override
|
||||
protected void doStop() {
|
||||
super.doStop();
|
||||
if (this.idleEventScheduledFuture != null) {
|
||||
this.idleEventScheduledFuture.cancel(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user