diff --git a/pom.xml b/pom.xml
index 0d2d0f7c5..0e1975adf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -150,8 +150,8 @@
org.springframework.cloud
- spring-cloud-stream-tools
- 1.1.0.BUILD-SNAPSHOT
+ spring-cloud-build-tools
+ 1.2.0.RELEASE
@@ -160,8 +160,6 @@
validate
checkstyle.xml
- checkstyle-header.txt
- checkstyle-suppressions.xml
UTF-8
true
true
diff --git a/spring-cloud-stream-reactive/src/main/java/org/springframework/cloud/stream/reactive/reactor/core/scheduler/ElasticScheduler.java b/spring-cloud-stream-reactive/src/main/java/org/springframework/cloud/stream/reactive/reactor/core/scheduler/ElasticScheduler.java
index 8101de45b..2403dc364 100644
--- a/spring-cloud-stream-reactive/src/main/java/org/springframework/cloud/stream/reactive/reactor/core/scheduler/ElasticScheduler.java
+++ b/spring-cloud-stream-reactive/src/main/java/org/springframework/cloud/stream/reactive/reactor/core/scheduler/ElasticScheduler.java
@@ -50,297 +50,300 @@ import reactor.util.concurrent.OpenHashSet;
* @author Stephane Maldini
*/
final class ElasticScheduler implements Scheduler {
- static final AtomicLong COUNTER = new AtomicLong();
+ static final AtomicLong COUNTER = new AtomicLong();
- static final ThreadFactory EVICTOR_FACTORY = r -> {
- Thread t = new Thread(r, "elastic-evictor-" + COUNTER.incrementAndGet());
- t.setDaemon(true);
- return t;
- };
+ static final ThreadFactory EVICTOR_FACTORY = r -> {
+ Thread t = new Thread(r, "elastic-evictor-" + COUNTER.incrementAndGet());
+ t.setDaemon(true);
+ return t;
+ };
- final ThreadFactory factory;
-
- final int ttlSeconds;
-
- static final int DEFAULT_TTL_SECONDS = 60;
-
- final Queue cache;
+ final ThreadFactory factory;
- final Queue all;
+ final int ttlSeconds;
- final ScheduledExecutorService evictor;
-
- static final ExecutorService SHUTDOWN;
- static {
- SHUTDOWN = Executors.newSingleThreadExecutor();
- SHUTDOWN.shutdownNow();
- }
-
- volatile boolean shutdown;
-
- public ElasticScheduler(ThreadFactory factory, int ttlSeconds) {
- this.ttlSeconds = ttlSeconds;
- this.factory = factory;
- this.cache = new ConcurrentLinkedQueue<>();
- this.all = new ConcurrentLinkedQueue<>();
- this.evictor = Executors.newScheduledThreadPool(1, EVICTOR_FACTORY);
- this.evictor.scheduleAtFixedRate(this::eviction, ttlSeconds, ttlSeconds, TimeUnit.SECONDS);
- }
-
- @Override
- public void start() {
- throw new UnsupportedOperationException("Restarting not supported yet");
- }
-
- @Override
- public void shutdown() {
- if (shutdown) {
- return;
- }
- shutdown = true;
-
- evictor.shutdownNow();
-
- cache.clear();
-
- ExecutorService exec;
-
- while ((exec = all.poll()) != null) {
- exec.shutdownNow();
- }
- }
-
- ExecutorService pick() {
- if (shutdown) {
- return SHUTDOWN;
- }
- ExecutorService result;
- ExecutorServiceExpiry e = cache.poll();
- if (e != null) {
- return e.executor;
- }
-
- result = Executors.newSingleThreadExecutor(factory);
- all.offer(result);
- if (shutdown) {
- all.remove(result);
- return SHUTDOWN;
- }
- return result;
- }
+ static final int DEFAULT_TTL_SECONDS = 60;
- @Override
- public Cancellation schedule(Runnable task) {
- ExecutorService exec = pick();
-
- Runnable wrapper = () -> {
- try {
- try {
- task.run();
- } catch (Throwable ex) {
- Exceptions.throwIfFatal(ex);
- Operators.onErrorDropped(ex);
- }
- } finally {
- release(exec);
- }
- };
- Future> f;
-
- try {
- f = exec.submit(wrapper);
- } catch (RejectedExecutionException ex) {
- Operators.onErrorDropped(ex);
- return REJECTED;
- }
- return () -> f.cancel(true);
- }
+ final Queue cache;
- @Override
- public Worker createWorker() {
- ExecutorService exec = pick();
- return new CachedWorker(exec, this);
- }
-
- void release(ExecutorService exec) {
- if (exec != SHUTDOWN && !shutdown) {
- ExecutorServiceExpiry e = new ExecutorServiceExpiry(exec, System.currentTimeMillis() + ttlSeconds * 1000L);
- cache.offer(e);
- if (shutdown) {
- if (cache.remove(e)) {
- exec.shutdownNow();
- }
- }
- }
- }
-
- void eviction() {
- long now = System.currentTimeMillis();
-
- List list = new ArrayList<>(cache);
- for (ExecutorServiceExpiry e : list) {
- if (e.expireMillis < now) {
- if (cache.remove(e)) {
- e.executor.shutdownNow();
- }
- }
- }
- }
+ final Queue all;
- static final class ExecutorServiceExpiry {
- final ExecutorService executor;
- final long expireMillis;
+ final ScheduledExecutorService evictor;
- public ExecutorServiceExpiry(ExecutorService executor, long expireMillis) {
- this.executor = executor;
- this.expireMillis = expireMillis;
- }
- }
-
- static final class CachedWorker implements Worker {
+ static final ExecutorService SHUTDOWN;
- final ExecutorService executor;
+ static {
+ SHUTDOWN = Executors.newSingleThreadExecutor();
+ SHUTDOWN.shutdownNow();
+ }
- final ElasticScheduler parent;
+ volatile boolean shutdown;
- volatile boolean shutdown;
-
- OpenHashSet tasks;
-
- public CachedWorker(ExecutorService executor, ElasticScheduler parent) {
- this.executor = executor;
- this.parent = parent;
- this.tasks = new OpenHashSet<>();
- }
+ public ElasticScheduler(ThreadFactory factory, int ttlSeconds) {
+ this.ttlSeconds = ttlSeconds;
+ this.factory = factory;
+ this.cache = new ConcurrentLinkedQueue<>();
+ this.all = new ConcurrentLinkedQueue<>();
+ this.evictor = Executors.newScheduledThreadPool(1, EVICTOR_FACTORY);
+ this.evictor.scheduleAtFixedRate(this::eviction, ttlSeconds, ttlSeconds, TimeUnit.SECONDS);
+ }
- @Override
- public Cancellation schedule(Runnable task) {
- if (shutdown) {
- return REJECTED;
- }
-
- CachedTask ct = new CachedTask(task, this);
-
- synchronized (this) {
- if (shutdown) {
- return REJECTED;
- }
- tasks.add(ct);
- }
-
- Future> f;
- try {
- f = executor.submit(ct);
- } catch (RejectedExecutionException ex) {
- Operators.onErrorDropped(ex);
- return REJECTED;
- }
-
- ct.setFuture(f);
-
- return ct;
- }
+ @Override
+ public void start() {
+ throw new UnsupportedOperationException("Restarting not supported yet");
+ }
- @Override
- public void shutdown() {
- if (shutdown) {
- return;
- }
-
- OpenHashSet set;
- synchronized (this) {
- if (shutdown) {
- return;
- }
- shutdown = true;
- set = tasks;
- tasks = null;
- }
-
- if (!set.isEmpty()) {
- Object[] keys = set.keys();
- for (Object o : keys) {
- if (o != null) {
- ((CachedTask)o).cancelFuture();
- }
- }
- }
-
- parent.release(executor);
- }
-
- void remove(CachedTask task) {
- if (shutdown) {
- return;
- }
-
- synchronized (this) {
- if (shutdown) {
- return;
- }
- tasks.remove(task);
- }
- }
-
- static final class CachedTask
- extends AtomicReference>
- implements Runnable, Cancellation {
- /** */
- private static final long serialVersionUID = 6799295393954430738L;
+ @Override
+ public void shutdown() {
+ if (shutdown) {
+ return;
+ }
+ shutdown = true;
- final Runnable run;
-
- final CachedWorker parent;
-
- volatile boolean cancelled;
+ evictor.shutdownNow();
- static final FutureTask