This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new af9e93b3aa3d CAMEL-27530: camel-mllp - the producer keeps one idle 
check across reconnects and restarts, and rejects process() when stopped 
(#30823)
af9e93b3aa3d is described below

commit af9e93b3aa3dcfcbe07b63286f7ffa8271d03fa6
Author: allthingssecurity <[email protected]>
AuthorDate: Thu Nov 26 13:30:45 2026 +0530

    CAMEL-27530: camel-mllp - the producer keeps one idle check across 
reconnects and restarts, and rejects process() when stopped (#30823)
    
    With idleTimeout set, checkConnection() scheduled an idle check for every
    new connection and nothing cancelled the one already scheduled, and run()
    rescheduled itself as long as the connection in the socket field was open,
    whichever connection it was scheduled for:
    - every reconnect (the receiver or the network dropped the connection,
      process() reconnects and resends) added one more check chain; they only
      ended once the connection was idle for a whole idleTimeout, and each one
      takes the producer lock;
    - doStop called shutdown() on the executor, which still runs its delayed
      tasks: after a start, the check of the previous start found the new
      connection open and rescheduled itself on the new executor;
    - process() did not check the state of the producer: a call that waited
      for the lock while the producer stopped opened a connection, then failed
      with a NullPointerException on the null executor; the connection stayed
      open, and after the next start it was used with no idle check.
    
    The producer now keeps the future of its idle check in a field (guarded by
    the lock). Each schedule, for a new connection and in run(), cancels the
    pending check first, so there is at most one. run() cancels too because a
    check the executor thread already took cannot be stopped by a cancel: it
    waits for the lock while process() reconnects (or while the producer stops
    and starts), then replaces the check of the new connection instead of
    adding one. doStop cancels the check and calls shutdownNow() on the
    executor, which doStart creates for this producer only. process() fails
    the exchange with a RejectedExecutionException when the producer is not
    started, before it connects.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../component/mllp/MllpTcpClientProducer.java      |  39 +-
 .../mllp/MllpTcpClientProducerIdleCheckTest.java   | 484 +++++++++++++++++++++
 2 files changed, 519 insertions(+), 4 deletions(-)

diff --git 
a/components/camel-mllp/src/main/java/org/apache/camel/component/mllp/MllpTcpClientProducer.java
 
b/components/camel-mllp/src/main/java/org/apache/camel/component/mllp/MllpTcpClientProducer.java
index 30acd1a86497..42ffbb87c772 100644
--- 
a/components/camel-mllp/src/main/java/org/apache/camel/component/mllp/MllpTcpClientProducer.java
+++ 
b/components/camel-mllp/src/main/java/org/apache/camel/component/mllp/MllpTcpClientProducer.java
@@ -24,7 +24,9 @@ import java.net.SocketTimeoutException;
 import java.nio.charset.Charset;
 import java.util.Date;
 import java.util.concurrent.Executors;
+import java.util.concurrent.RejectedExecutionException;
 import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
 
@@ -59,6 +61,8 @@ public class MllpTcpClientProducer extends DefaultProducer 
implements Runnable {
     Socket socket;
 
     ScheduledExecutorService idleTimeoutExecutor;
+    // the pending idle connection check, at most one per producer; guarded by 
lock
+    ScheduledFuture<?> idleTimeoutCheck;
     private String cachedLocalAddress;
     private String cachedRemoteAddress;
     private String cachedCombinedAddress;
@@ -124,8 +128,14 @@ public class MllpTcpClientProducer extends DefaultProducer 
implements Runnable {
 
     @Override
     protected void doStop() throws Exception {
+        if (idleTimeoutCheck != null) {
+            idleTimeoutCheck.cancel(false);
+            idleTimeoutCheck = null;
+        }
         if (idleTimeoutExecutor != null) {
-            idleTimeoutExecutor.shutdown();
+            // the executor is created by doStart for this producer only: drop 
its pending checks, which would
+            // otherwise still run after the stop and reschedule themselves on 
the executor of the next start
+            idleTimeoutExecutor.shutdownNow();
             idleTimeoutExecutor = null;
         }
 
@@ -138,6 +148,14 @@ public class MllpTcpClientProducer extends DefaultProducer 
implements Runnable {
     public void process(Exchange exchange) throws MllpException {
         lock.lock();
         try {
+            if (!isRunAllowed()) {
+                // process() waited for the lock while the producer stopped: 
do not open a connection that nothing
+                // closes, and that no idle check guards after the next start
+                String endpointKey = getEndpoint().getEndpointKey();
+                exchange.setException(new RejectedExecutionException(
+                        "The MLLP producer for " + 
StringHelper.before(endpointKey, "?", endpointKey) + " is not started"));
+                return;
+            }
             log.trace("process({}) [{}] - entering", exchange.getExchangeId(), 
socket);
             getEndpoint().updateLastConnectionActivityTicks();
 
@@ -504,7 +522,7 @@ public class MllpTcpClientProducer extends DefaultProducer 
implements Runnable {
             if (getConfiguration().hasIdleTimeout()) {
                 log.debug("Scheduling initial idle producer connection check 
of {} in {} milliseconds", getConnectionAddress(),
                         getConfiguration().getIdleTimeout());
-                idleTimeoutExecutor.schedule(this, 
getConfiguration().getIdleTimeout(), TimeUnit.MILLISECONDS);
+                scheduleIdleTimeoutCheck(getConfiguration().getIdleTimeout());
             }
         } else {
             log.debug("checkConnection() - Connection {} is still valid - no 
new connection required", socket);
@@ -623,13 +641,13 @@ public class MllpTcpClientProducer extends 
DefaultProducer implements Runnable {
                                 log.debug("Scheduling idle producer connection 
check of {} in {} milliseconds",
                                         getConnectionAddress(), delay);
                             }
-                            idleTimeoutExecutor.schedule(this, delay, 
TimeUnit.MILLISECONDS);
+                            scheduleIdleTimeoutCheck(delay);
                         }
                     } else {
                         log.debug(
                                 "No activity detected since initial connection 
- scheduling idle producer connection check in {} milliseconds",
                                 getConfiguration().getIdleTimeout());
-                        idleTimeoutExecutor.schedule(this, 
getConfiguration().getIdleTimeout(), TimeUnit.MILLISECONDS);
+                        
scheduleIdleTimeoutCheck(getConfiguration().getIdleTimeout());
                     }
                 }
             }
@@ -638,6 +656,19 @@ public class MllpTcpClientProducer extends DefaultProducer 
implements Runnable {
         }
     }
 
+    /**
+     * Schedules the idle connection check in place of the pending one, so a 
producer has at most one, also when it
+     * reconnects (a new connection schedules a check while the check of the 
previous connection is pending) and when a
+     * check that was already running when it was cancelled reschedules 
itself. Called with the lock held.
+     */
+    private void scheduleIdleTimeoutCheck(long delay) {
+        if (idleTimeoutCheck != null) {
+            // does not interrupt a check that is running (this one, or one 
that waits for the lock)
+            idleTimeoutCheck.cancel(false);
+        }
+        idleTimeoutCheck = idleTimeoutExecutor.schedule(this, delay, 
TimeUnit.MILLISECONDS);
+    }
+
     static class IdleTimeoutThreadFactory implements ThreadFactory {
         final String endpointKey;
 
diff --git 
a/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/MllpTcpClientProducerIdleCheckTest.java
 
b/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/MllpTcpClientProducerIdleCheckTest.java
new file mode 100644
index 000000000000..1f84fd5ee785
--- /dev/null
+++ 
b/components/camel-mllp/src/test/java/org/apache/camel/component/mllp/MllpTcpClientProducerIdleCheckTest.java
@@ -0,0 +1,484 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.mllp;
+
+import java.net.Socket;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.AbstractExecutorService;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.Delayed;
+import java.util.concurrent.RejectedExecutionException;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.support.DefaultExchange;
+import org.apache.camel.test.junit.rule.mllp.MllpServerResource;
+import org.apache.camel.test.mllp.Hl7TestMessageGenerator;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import static org.awaitility.Awaitility.await;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The producer keeps one idle connection check when it reconnects, when the 
check runs while process() reconnects, and
+ * across a stop and start; and process() called while the producer stops 
opens no connection. The idle checks run on a
+ * manual executor that the test installs after start(), so the test decides 
when a check runs.
+ */
+@Timeout(60)
+class MllpTcpClientProducerIdleCheckTest {
+
+    // long enough that only the test runs the checks; the idle time is set 
through the endpoint's activity ticks
+    static final int IDLE_TIMEOUT = 60000;
+
+    @RegisterExtension
+    MllpServerResource mllpServer = new MllpServerResource("localhost", 0);
+
+    private CamelContext context;
+    private TestProducer producer;
+
+    @BeforeEach
+    void startContext() {
+        context = new DefaultCamelContext();
+        context.start();
+    }
+
+    @AfterEach
+    void stopProducerAndContext() {
+        if (producer != null) {
+            producer.stop();
+        }
+        context.stop();
+    }
+
+    @Test
+    void reconnectReplacesTheIdleCheckOfThePreviousConnection() throws 
Exception {
+        // the receiver closes the connection instead of acknowledging the 
second message of each connection: every
+        // send after the first one reconnects and resends inside process()
+        mllpServer.setCloseSocketBeforeAcknowledgementModulus(2);
+        producer = startProducer("?idleTimeout=" + IDLE_TIMEOUT);
+        ManualExecutor executor = producer.installManualExecutor();
+
+        Socket previous = null;
+        for (int i = 1; i <= 5; i++) {
+            assertNull(send().getException(), "message " + i);
+            assertNotSame(previous, producer.socket, "message " + i + " is 
sent on a new connection");
+            previous = producer.socket;
+            assertEquals(i, executor.scheduled.size(), "one check scheduled 
per connection");
+            assertEquals(1, executor.pending().size(), "pending idle checks 
after message " + i);
+        }
+
+        // the connection is idle: the one check closes it and the chain ends
+        
producer.getEndpoint().updateLastConnectionActivityTicks(System.currentTimeMillis()
 - IDLE_TIMEOUT - 1000);
+        executor.fire(executor.pending().get(0));
+        assertTrue(producer.socket.isClosed());
+        assertEquals(0, executor.pending().size());
+    }
+
+    @Test
+    void idleCheckThatRunsWhileProcessReconnectsDoesNotAddAChain() throws 
Exception {
+        mllpServer.setCloseSocketBeforeAcknowledgementModulus(2);
+        producer = startProducer("?idleTimeout=" + IDLE_TIMEOUT);
+        ManualExecutor executor = producer.installManualExecutor();
+        assertNull(send().getException());
+        ManualCheck firstCheck = executor.pending().get(0);
+
+        ReentrantLock lock = producer.serviceLock();
+        AtomicReference<Throwable> checkFailure = new AtomicReference<>();
+        Thread checkThread = new Thread(() -> {
+            try {
+                executor.fire(firstCheck);
+            } catch (Throwable t) {
+                checkFailure.set(t);
+            }
+        }, "idle-check");
+        Exchange exchange;
+        lock.lock();
+        try {
+            // the check of the first connection is due and waits for the 
lock, held by a process() call
+            checkThread.start();
+            await().atMost(10, TimeUnit.SECONDS).until(() -> 
lock.hasQueuedThread(checkThread));
+            // process() (the lock is reentrant) reconnects: the receiver 
closes the connection before the ack
+            exchange = send();
+        } finally {
+            lock.unlock();
+        }
+        checkThread.join(10000);
+
+        assertFalse(checkThread.isAlive());
+        assertNull(checkFailure.get());
+        assertNull(exchange.getException());
+        assertFalse(producer.socket.isClosed(), "the check does not close the 
connection that was just used");
+        assertEquals(1, executor.pending().size(), "the check found the new 
connection open and rescheduled itself");
+    }
+
+    @Test
+    void idleCheckClosingTheConnectionRacesASend() throws Exception {
+        // control: the lock orders the two, in either order the message is 
acknowledged and one check is pending
+        producer = startProducer("?idleTimeout=" + IDLE_TIMEOUT);
+        ManualExecutor executor = producer.installManualExecutor();
+        assertNull(send().getException());
+        ManualCheck firstCheck = executor.pending().get(0);
+        
producer.getEndpoint().updateLastConnectionActivityTicks(System.currentTimeMillis()
 - IDLE_TIMEOUT - 1000);
+
+        ReentrantLock lock = producer.serviceLock();
+        AtomicReference<Exchange> sent = new AtomicReference<>();
+        AtomicReference<Throwable> failure = new AtomicReference<>();
+        Thread checkThread = new Thread(() -> {
+            try {
+                executor.fire(firstCheck);
+            } catch (Throwable t) {
+                failure.set(t);
+            }
+        }, "idle-check");
+        Thread sendThread = new Thread(() -> {
+            try {
+                sent.set(send());
+            } catch (Throwable t) {
+                failure.set(t);
+            }
+        }, "send");
+        lock.lock();
+        try {
+            checkThread.start();
+            sendThread.start();
+            await().atMost(10, TimeUnit.SECONDS)
+                    .until(() -> lock.hasQueuedThread(checkThread) && 
lock.hasQueuedThread(sendThread));
+        } finally {
+            lock.unlock();
+        }
+        checkThread.join(10000);
+        sendThread.join(10000);
+
+        assertFalse(checkThread.isAlive());
+        assertFalse(sendThread.isAlive());
+        assertNull(failure.get());
+        assertNull(sent.get().getException());
+        assertFalse(producer.socket.isClosed());
+        assertEquals(1, executor.pending().size());
+    }
+
+    @Test
+    void idleCheckOfThePreviousStartDoesNotRunAfterARestart() throws Exception 
{
+        producer = startProducer("?idleTimeout=" + IDLE_TIMEOUT);
+        ManualExecutor first = producer.installManualExecutor();
+        assertNull(send().getException());
+        assertEquals(1, first.pending().size());
+
+        producer.stop();
+        // the executor of the first start keeps no check to run after the stop
+        assertEquals(0, first.runnableAfterShutdown().size(), "checks of the 
first start left after the stop");
+        producer.start();
+        ManualExecutor second = producer.installManualExecutor();
+        assertNull(send().getException());
+        assertEquals(1, second.pending().size());
+
+        // run what the executor of the first start still runs after the stop
+        List<ManualCheck> leftOver = first.runnableAfterShutdown();
+        for (ManualCheck check : leftOver) {
+            first.fire(check);
+        }
+        assertEquals(1, second.pending().size(), "pending idle checks after 
the restart");
+    }
+
+    @Test
+    void 
idleCheckWaitingForTheLockDuringAStopDoesNotAddAChainAfterTheRestart() throws 
Exception {
+        producer = startProducer("?idleTimeout=" + IDLE_TIMEOUT);
+        ManualExecutor first = producer.installManualExecutor();
+        assertNull(send().getException());
+        ManualCheck firstCheck = first.pending().get(0);
+
+        ReentrantLock lock = producer.serviceLock();
+        AtomicReference<Throwable> checkFailure = new AtomicReference<>();
+        Thread checkThread = new Thread(() -> {
+            try {
+                first.fire(firstCheck);
+            } catch (Throwable t) {
+                checkFailure.set(t);
+            }
+        }, "idle-check");
+        ManualExecutor second;
+        lock.lock();
+        try {
+            // the executor of the first start took the check, which waits for 
the lock while the producer stops,
+            // starts again and sends on a new connection
+            checkThread.start();
+            await().atMost(10, TimeUnit.SECONDS).until(() -> 
lock.hasQueuedThread(checkThread));
+            producer.stop();
+            producer.start();
+            second = producer.installManualExecutor();
+            assertNull(send().getException());
+        } finally {
+            lock.unlock();
+        }
+        checkThread.join(10000);
+
+        assertFalse(checkThread.isAlive());
+        assertNull(checkFailure.get());
+        assertEquals(1, second.pending().size(), "pending idle checks after 
the restart");
+    }
+
+    @Test
+    void processWaitingForTheLockWhileTheProducerStopsOpensNoConnection() 
throws Exception {
+        producer = startProducer("?idleTimeout=" + IDLE_TIMEOUT);
+        producer.installManualExecutor();
+        processWaitingDuringStopIsRejected();
+
+        // after a start, the next message gets a new connection with its idle 
check
+        producer.start();
+        ManualExecutor executor = producer.installManualExecutor();
+        assertNull(send().getException());
+        assertFalse(producer.socket.isClosed());
+        assertEquals(1, executor.pending().size());
+    }
+
+    @Test
+    void 
processWaitingForTheLockWhileTheProducerStopsOpensNoConnectionWithoutIdleTimeout()
 throws Exception {
+        producer = startProducer("");
+        processWaitingDuringStopIsRejected();
+    }
+
+    private void processWaitingDuringStopIsRejected() throws Exception {
+        assertNull(send().getException());
+        Socket first = producer.socket;
+
+        ReentrantLock lock = producer.serviceLock();
+        AtomicReference<Exchange> sent = new AtomicReference<>();
+        AtomicReference<Throwable> failure = new AtomicReference<>();
+        Thread sendThread = new Thread(() -> {
+            try {
+                sent.set(send());
+            } catch (Throwable t) {
+                failure.set(t);
+            }
+        }, "send");
+        lock.lock();
+        try {
+            // the route thread called process() and waits for the lock while 
the producer stops
+            sendThread.start();
+            await().atMost(10, TimeUnit.SECONDS).until(() -> 
lock.hasQueuedThread(sendThread));
+            producer.stop();
+        } finally {
+            lock.unlock();
+        }
+        sendThread.join(10000);
+
+        assertFalse(sendThread.isAlive());
+        assertNull(failure.get(), "process() does not throw");
+        assertInstanceOf(RejectedExecutionException.class, 
sent.get().getException());
+        assertSame(first, producer.socket, "no new connection");
+        assertTrue(producer.socket.isClosed());
+    }
+
+    private TestProducer startProducer(String options) {
+        MllpEndpoint endpoint = context.getEndpoint(
+                "mllp://" + mllpServer.getListenHost() + ":" + 
mllpServer.getListenPort() + options, MllpEndpoint.class);
+        TestProducer testProducer = new TestProducer(endpoint);
+        testProducer.start();
+        return testProducer;
+    }
+
+    private Exchange send() throws Exception {
+        Exchange exchange = new DefaultExchange(context);
+        
exchange.getMessage().setBody(Hl7TestMessageGenerator.generateMessage());
+        producer.process(exchange);
+        return exchange;
+    }
+
+    static class TestProducer extends MllpTcpClientProducer {
+        TestProducer(MllpEndpoint endpoint) {
+            super(endpoint);
+        }
+
+        ReentrantLock serviceLock() {
+            return (ReentrantLock) lock;
+        }
+
+        ManualExecutor installManualExecutor() {
+            idleTimeoutExecutor.shutdownNow();
+            ManualExecutor executor = new ManualExecutor();
+            idleTimeoutExecutor = executor;
+            return executor;
+        }
+    }
+
+    /**
+     * Keeps the scheduled checks until the test runs them. Like the 
ScheduledThreadPoolExecutor of
+     * Executors.newSingleThreadScheduledExecutor: a check that has started 
runs to its end when it is cancelled; after
+     * shutdown() the checks that are not cancelled still run 
(executeExistingDelayedTasksAfterShutdown is true by
+     * default); after shutdownNow() none of the checks that did not start 
runs.
+     */
+    static class ManualExecutor extends AbstractExecutorService implements 
ScheduledExecutorService {
+        final List<ManualCheck> scheduled = new CopyOnWriteArrayList<>();
+        volatile boolean shutdown;
+        volatile boolean shutdownNow;
+
+        List<ManualCheck> pending() {
+            List<ManualCheck> answer = new ArrayList<>();
+            for (ManualCheck check : scheduled) {
+                if (!check.cancelled && !check.started && !shutdownNow) {
+                    answer.add(check);
+                }
+            }
+            return answer;
+        }
+
+        List<ManualCheck> runnableAfterShutdown() {
+            return shutdown ? pending() : List.of();
+        }
+
+        void fire(ManualCheck check) {
+            check.started = true;
+            try {
+                check.command.run();
+            } finally {
+                check.done = true;
+            }
+        }
+
+        @Override
+        public ScheduledFuture<?> schedule(Runnable command, long delay, 
TimeUnit unit) {
+            if (shutdown) {
+                throw new RejectedExecutionException("shut down");
+            }
+            ManualCheck check = new ManualCheck(command, unit.toMillis(delay));
+            scheduled.add(check);
+            return check;
+        }
+
+        @Override
+        public <V> ScheduledFuture<V> schedule(Callable<V> callable, long 
delay, TimeUnit unit) {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long 
initialDelay, long period, TimeUnit unit) {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, 
long initialDelay, long delay, TimeUnit unit) {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public void execute(Runnable command) {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public void shutdown() {
+            shutdown = true;
+        }
+
+        @Override
+        public List<Runnable> shutdownNow() {
+            List<Runnable> notStarted = new ArrayList<>();
+            for (ManualCheck check : pending()) {
+                notStarted.add(check.command);
+            }
+            shutdown = true;
+            shutdownNow = true;
+            return notStarted;
+        }
+
+        @Override
+        public boolean isShutdown() {
+            return shutdown;
+        }
+
+        @Override
+        public boolean isTerminated() {
+            return shutdown;
+        }
+
+        @Override
+        public boolean awaitTermination(long timeout, TimeUnit unit) {
+            return shutdown;
+        }
+    }
+
+    static class ManualCheck implements ScheduledFuture<Object> {
+        final Runnable command;
+        final long delayMillis;
+        volatile boolean started;
+        volatile boolean cancelled;
+        volatile boolean done;
+
+        ManualCheck(Runnable command, long delayMillis) {
+            this.command = command;
+            this.delayMillis = delayMillis;
+        }
+
+        @Override
+        public boolean cancel(boolean mayInterruptIfRunning) {
+            // as FutureTask: a check that is running is marked cancelled, and 
runs to its end
+            if (cancelled || done) {
+                return false;
+            }
+            cancelled = true;
+            return true;
+        }
+
+        @Override
+        public boolean isCancelled() {
+            return cancelled;
+        }
+
+        @Override
+        public boolean isDone() {
+            return cancelled || done;
+        }
+
+        @Override
+        public Object get() {
+            return null;
+        }
+
+        @Override
+        public Object get(long timeout, TimeUnit unit) {
+            return null;
+        }
+
+        @Override
+        public long getDelay(TimeUnit unit) {
+            return unit.convert(delayMillis, TimeUnit.MILLISECONDS);
+        }
+
+        @Override
+        public int compareTo(Delayed other) {
+            return Long.compare(getDelay(TimeUnit.MILLISECONDS), 
other.getDelay(TimeUnit.MILLISECONDS));
+        }
+    }
+}

Reply via email to