diff options
Diffstat (limited to 'runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageService.java')
-rw-r--r-- | runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageService.java | 75 |
1 files changed, 41 insertions, 34 deletions
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageService.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageService.java index 9ca624c85..99d7bc3ef 100644 --- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageService.java +++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageService.java @@ -61,10 +61,34 @@ public class MessageService extends RTObject implements IMessageService { return address; } - public synchronized void run() { + public void run() { running = true; + while (running) { - pollOneMessage(); + Message msg = null; + + // get next Message from Queue + synchronized(this) { + msg = messageQueue.pop(); + } + + if (msg == null) { + // no message in queue -> wait until Thread is notified + try { + synchronized(this) { + if (!running) + return; + wait(); + } + } + catch (InterruptedException e) { + } + } + else { + // process message + lastMessageTimestamp = System.currentTimeMillis(); + messageDispatcher.receive(msg); + } } } @@ -76,44 +100,14 @@ public class MessageService extends RTObject implements IMessageService { } } - private synchronized void pollOneMessage() { - Message msg = messageQueue.pop(); // get next Message from Queue - if (msg == null) { - // no message in queue -> wait till Thread is notified - try { - wait(); - } - catch (InterruptedException e) { - } - } - else { - lastMessageTimestamp = System.currentTimeMillis(); - messageDispatcher.receive(msg); - } - - } - - public Address getFreeAddress() { + public synchronized Address getFreeAddress() { return messageDispatcher.getFreeAddress(); } - public void freeAddress(Address addr) { + public synchronized void freeAddress(Address addr) { messageDispatcher.freeAddress(addr); } - // protected methods for sole use by test cases - protected MessageSeQueue getMessageQueue() { - return messageQueue; - } - - protected synchronized MessageDispatcher getMessageDispatcher() { - return messageDispatcher; - } - - protected synchronized long getLastMessageTimestamp() { - return lastMessageTimestamp; - } - public synchronized void terminate() { if (running) { running = false; @@ -146,5 +140,18 @@ public class MessageService extends RTObject implements IMessageService { public void removeMessageReceiver(IMessageReceiver receiver) { messageDispatcher.removeMessageReceiver(receiver); } + + // protected methods for sole use by test cases + protected MessageSeQueue getMessageQueue() { + return messageQueue; + } + + protected synchronized MessageDispatcher getMessageDispatcher() { + return messageDispatcher; + } + + protected synchronized long getLastMessageTimestamp() { + return lastMessageTimestamp; + } } |