From 9cf56e98c500b02fc19e3ec419fc2ffcac63fcf4 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Wed, 9 Oct 2024 20:50:40 +0200 Subject: [PATCH] ActorThread --- wash/src/actor/ActorThread.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/wash/src/actor/ActorThread.java b/wash/src/actor/ActorThread.java index d4a9f7b..9a93b3b 100644 --- a/wash/src/actor/ActorThread.java +++ b/wash/src/actor/ActorThread.java @@ -1,25 +1,26 @@ package actor; -public abstract class ActorThread extends Thread { +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; - // TODO: one suitable attribute here +public class ActorThread extends Thread { + + private final LinkedBlockingQueue q = new LinkedBlockingQueue<>(); /** Called by another thread, to send a message to this thread. */ public void send(M message) { - // TODO: implement this method (one or a few lines) + q.offer(message); } /** Returns the first message in the queue, or blocks if none available. */ protected M receive() throws InterruptedException { - // TODO: implement this method (one or a few lines) - return null; + return q.take(); } /** Returns the first message in the queue, or blocks up to 'timeout' milliseconds if none available. Returns null if no message is obtained within 'timeout' milliseconds. */ protected M receiveWithTimeout(long timeout) throws InterruptedException { - // TODO: implement this method (one or a few lines) - return null; + return q.poll(timeout, TimeUnit.MILLISECONDS); } } \ No newline at end of file