Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/org.eclipse.etrice.runtime.java/src/org/eclipse')
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageService.java66
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/RTObject.java51
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/InterfaceItemBase.java57
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/RTSystemProtocol.java30
4 files changed, 107 insertions, 97 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 dedc9b461..72d119378 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
@@ -4,10 +4,10 @@
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* CONTRIBUTORS:
* Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
- *
+ *
*******************************************************************************/
@@ -22,7 +22,7 @@ import java.util.concurrent.TimeUnit;
/**
* The MessageService is the backbone of the asynchronous communication inside a SubSystem
* It usually contains a thread a message queue and a dispatcher
- *
+ *
* @author Thomas Schuetz (initial contribution)
* @author Henrik Rentz-Reichert (extending RTObject, implementing Runnable)
*
@@ -30,22 +30,22 @@ import java.util.concurrent.TimeUnit;
public class MessageService extends AbstractMessageService {
private boolean running = false;
-
+
private Thread thread;
private int priority;
private long lastMessageTimestamp;
-
+
private long pollingInterval = -1;
private ScheduledExecutorService pollingScheduler = null;
public MessageService(IRTObject parent, ExecMode mode, int node, int thread, String name) {
this(parent, mode, 0, node, thread, name, Thread.NORM_PRIORITY);
}
-
+
public MessageService(IRTObject parent, ExecMode mode, long nsec, int node, int thread, String name) {
this(parent, mode, nsec, node, thread, name, Thread.NORM_PRIORITY);
}
-
+
public MessageService(IRTObject parent, ExecMode mode, long nsec, int node, int thread, String name, int priority) {
super(parent, "MessageService_"+name, node, thread);
@@ -54,31 +54,31 @@ public class MessageService extends AbstractMessageService {
// priority = Thread.NORM_PRIORITY generated fixed
this.priority = priority;
- assert priority >= Thread.MIN_PRIORITY : ("priority smaller than Thread.MIN_PRIORITY (" + "Thread.MIN_PRIORITY" + ")");
- assert priority <= Thread.MAX_PRIORITY : ("priority bigger than Thread.MAX_PRIORITY (" + "Thread.MAX_PRIORITY" + ")");
-
+ assert priority >= Thread.MIN_PRIORITY : ("priority smaller than Thread.MIN_PRIORITY (" + "Thread.MIN_PRIORITY" + ")");
+ assert priority <= Thread.MAX_PRIORITY : ("priority bigger than Thread.MAX_PRIORITY (" + "Thread.MAX_PRIORITY" + ")");
+
if(mode == ExecMode.MIXED || mode == ExecMode.POLLED){
pollingInterval = nsec;
pollingScheduler = Executors.newScheduledThreadPool(1, new PollingThreadFactory());
-
+
assert pollingInterval > 0 : ("polling interval is 0 or negative");
}
}
public void run() {
running = true;
-
+
if(pollingScheduler != null)
pollingScheduler.scheduleAtFixedRate(new PollingTask(), pollingInterval, pollingInterval, TimeUnit.NANOSECONDS);
-
+
while (running) {
Message msg = null;
-
+
// get next Message from Queue
synchronized(this) {
msg = getMessageQueue().pop();
}
-
+
if (msg == null) {
// no message in queue -> wait until Thread is notified
try {
@@ -105,11 +105,11 @@ public class MessageService extends AbstractMessageService {
@Override
public synchronized void receive(Message msg) {
super.receive(msg);
-
+
// wake up thread to process message
notifyAll();
}
-
+
/* (non-Javadoc)
* @see org.eclipse.etrice.runtime.java.messaging.AbstractMessageService#getFreeAddress()
*/
@@ -117,7 +117,7 @@ public class MessageService extends AbstractMessageService {
public synchronized Address getFreeAddress() {
return super.getFreeAddress();
}
-
+
/* (non-Javadoc)
* @see org.eclipse.etrice.runtime.java.messaging.AbstractMessageService#addMessageReceiver(org.eclipse.etrice.runtime.java.messaging.IMessageReceiver)
*/
@@ -133,17 +133,17 @@ public class MessageService extends AbstractMessageService {
public synchronized void removeMessageReceiver(IMessageReceiver receiver) {
super.removeMessageReceiver(receiver);
}
-
+
@Override
public synchronized void addPollingMessageReceiver(IMessageReceiver receiver) {
super.addPollingMessageReceiver(receiver);
}
-
+
@Override
public synchronized void removePollingMessageReceiver(IMessageReceiver receiver) {
super.removePollingMessageReceiver(receiver);
}
-
+
/* (non-Javadoc)
* @see org.eclipse.etrice.runtime.java.messaging.AbstractMessageService#freeAddress(org.eclipse.etrice.runtime.java.messaging.Address)
*/
@@ -151,15 +151,15 @@ public class MessageService extends AbstractMessageService {
public synchronized void freeAddress(Address addr) {
super.freeAddress(addr);
}
-
+
public synchronized void terminate() {
+ if(pollingScheduler != null)
+ pollingScheduler.shutdown();
+
if (running) {
running = false;
notifyAll();
}
-
- if(pollingScheduler != null)
- pollingScheduler.shutdown();
}
/* (non-Javadoc)
@@ -167,7 +167,7 @@ public class MessageService extends AbstractMessageService {
*/
public void setThread(Thread thread) {
this.thread = thread;
-
+
thread.setPriority(priority);
}
@@ -181,29 +181,29 @@ public class MessageService extends AbstractMessageService {
protected long getLastMessageTimestamp() {
return lastMessageTimestamp;
}
-
+
private class PollingTask implements Runnable{
-
+
@Override
public void run() {
if(running){
Message msg = new Message(getMessageDispatcher().getAddress());
receive(msg);
- }
+ }
}
-
+
}
-
+
private class PollingThreadFactory implements ThreadFactory{
@Override
public Thread newThread(Runnable arg0) {
Thread thread = new Thread(arg0, getName()+"_PollingThread");
thread.setPriority(priority);
-
+
return thread;
}
-
+
}
}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/RTObject.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/RTObject.java
index 39705aeb1..d68ca3e1c 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/RTObject.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/RTObject.java
@@ -13,7 +13,7 @@ import java.util.ArrayList;
/**
* An implementation of the IRTObject interface using a hierarchical structure
* to assemble paths.
- *
+ *
* @author Henrik Rentz-Reichert
*
*/
@@ -22,23 +22,26 @@ public class RTObject implements IRTObject {
private String name = NO_NAME;
private IRTObject parent = null;
ArrayList<IRTObject> children = new ArrayList<IRTObject>();
-
+
protected RTObject(IRTObject parent, String name){
this.parent = parent;
this.name = name;
-
+
if (parent!=null)
parent.getChildren().add(this);
}
+ @Override
public String getName() {
return name;
}
-
+
+ @Override
public IRTObject getParent() {
return parent;
}
+ @Override
public ArrayList<IRTObject> getChildren() {
return children;
}
@@ -55,37 +58,40 @@ public class RTObject implements IRTObject {
parent = null;
}
}
-
+
+ @Override
public IRTObject getRoot() {
IRTObject root = this;
while (root.getParent()!=null)
root = root.getParent();
-
+
return root;
}
-
+
+ @Override
public IRTObject getChild(String name) {
for (IRTObject child : children) {
if (child.getName().equals(name))
return child;
}
-
+
return null;
}
-
+
+ @Override
public IRTObject getObject(String path) {
boolean isAbsolute = path.charAt(0)==PATH_DELIM;
if (isAbsolute && getParent()!=null)
return getParent().getObject(path);
-
+
if (isAbsolute)
path = path.substring(1);
-
+
String[] segments = path.split(Character.toString(PATH_DELIM));
if (segments.length>0) {
IRTObject current = this;
-
+
String first = segments[0];
for (String segment : segments) {
if (isAbsolute && segment==first) {
@@ -100,23 +106,26 @@ public class RTObject implements IRTObject {
}
return current;
}
-
+
return null;
}
-
+
+ @Override
public String getInstancePath(char delim) {
String path = delim + name;
-
+
if (parent!=null)
path = parent.getInstancePath(delim)+path;
-
+
return path;
}
-
+
+ @Override
public String getInstancePath() {
return getInstancePath(PATH_DELIM);
}
+ @Override
public String getInstancePathName() {
return getInstancePath(PATHNAME_DELIM);
}
@@ -130,10 +139,10 @@ public class RTObject implements IRTObject {
return parent.getThreadForPath(path);
return -1;
}
-
+
private String toStringRecursive(String indent) {
StringBuilder result = new StringBuilder(indent+toString()+"\n");
-
+
indent = " "+indent;
for (IRTObject child : getChildren()) {
if (child instanceof RTObject)
@@ -143,11 +152,11 @@ public class RTObject implements IRTObject {
}
return result.toString();
}
-
+
public String toStringRecursive() {
return toStringRecursive("");
}
-
+
@Override
public String toString() {
return getName();
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/InterfaceItemBase.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/InterfaceItemBase.java
index df4441621..89d03c66d 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/InterfaceItemBase.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/InterfaceItemBase.java
@@ -18,11 +18,11 @@ import org.eclipse.etrice.runtime.java.messaging.RTServices;
/**
* The abstract base class for actor class interface items like {@link PortBase}
* and {@link InterfaceItemBroker}s.
- *
+ *
* @author Henrik Rentz-Reichert
*/
public abstract class InterfaceItemBase extends AbstractMessageReceiver implements IInterfaceItem {
-
+
/**
* If this is part of an {@link IReplicatedInterfaceItem} then the
* owner of this item is stored in this field.
@@ -30,18 +30,18 @@ public abstract class InterfaceItemBase extends AbstractMessageReceiver implemen
* disconnected then it is also removed from its parent and destroyed.
*/
private IReplicatedInterfaceItem replicator = null;
-
- protected IMessageService ownMsgReceiver;
- protected IMessageReceiver peerMsgReceiver;
+
+ private IMessageService ownMsgReceiver;
+ private IMessageReceiver peerMsgReceiver;
private int localId;
private int idx;
- protected Address peerAddress = null;
+ private Address peerAddress = null;
private IInterfaceItem peer;
/**
* The constructor determines the thread of its {@link IEventReceiver}
- *
+ *
* @param owner
* @param name
* @param localId
@@ -49,20 +49,20 @@ public abstract class InterfaceItemBase extends AbstractMessageReceiver implemen
*/
public InterfaceItemBase (IInterfaceItemOwner owner, String name, int localId, int idx) {
super(owner.getEventReceiver(), name);
-
+
this.localId = localId;
this.idx = idx;
-
+
if (owner instanceof IReplicatedInterfaceItem)
replicator = (IReplicatedInterfaceItem) owner;
-
+
int thread = owner.getEventReceiver().getThread();
if (thread>=0) {
IMessageService msgSvc = RTServices.getInstance().getMsgSvcCtrl().getMsgSvc(thread);
Address addr = msgSvc.getFreeAddress();
setAddress(addr);
msgSvc.addMessageReceiver(this);
-
+
this.ownMsgReceiver = msgSvc;
}
}
@@ -70,30 +70,30 @@ public abstract class InterfaceItemBase extends AbstractMessageReceiver implemen
public synchronized IInterfaceItem connectWith(IInterfaceItem peer) {
if (peer!=null) {
this.peer = peer;
-
+
if (peer instanceof IInterfaceItemBroker) {
this.peer = peer.connectWith(this);
return this.peer;
}
-
+
if (peer instanceof IReplicatedInterfaceItem)
peer = ((IReplicatedInterfaceItem) peer).createSubInterfaceItem();
-
+
if (peer instanceof InterfaceItemBase) {
InterfaceItemBase thePeer = (InterfaceItemBase) peer;
-
+
// connect with each other
peerAddress = thePeer.getAddress();
thePeer.peerAddress = getAddress();
this.peerMsgReceiver = thePeer.ownMsgReceiver;
thePeer.peerMsgReceiver = ownMsgReceiver;
}
-
+
}
-
+
return peer;
}
-
+
protected synchronized void disconnect() {
disconnectInternal();
if (peer!=null) {
@@ -106,11 +106,12 @@ public abstract class InterfaceItemBase extends AbstractMessageReceiver implemen
private void disconnectInternal() {
peerAddress = null;
peerMsgReceiver = null;
-
+
if (replicator!=null)
destroy();
}
-
+
+
protected IMessageReceiver getMsgReceiver() {
return ownMsgReceiver;
}
@@ -122,7 +123,7 @@ public abstract class InterfaceItemBase extends AbstractMessageReceiver implemen
protected synchronized IMessageReceiver getPeerMsgReceiver() {
return peerMsgReceiver;
}
-
+
public IEventReceiver getActor() {
return (IEventReceiver) getParent();
}
@@ -134,7 +135,7 @@ public abstract class InterfaceItemBase extends AbstractMessageReceiver implemen
public int getIdx() {
return idx;
}
-
+
/* (non-Javadoc)
* @see org.eclipse.etrice.runtime.java.messaging.RTObject#destroy()
*/
@@ -143,26 +144,26 @@ public abstract class InterfaceItemBase extends AbstractMessageReceiver implemen
if (peerAddress!=null) {
disconnect();
}
-
+
if (replicator!=null) {
replicator.removeItem(this);
}
-
+
ownMsgReceiver.removeMessageReceiver(this);
ownMsgReceiver.freeAddress(getAddress());
-
+
super.destroy();
}
-
+
@Override
public String toString() {
return ((replicator!=null)?"sub ":"")+"port "+getName()+" "+getAddress()+" <-> "+getPeerAddress();
}
-
+
public static void connect(IRTObject obj, String path1, String path2) {
IRTObject obj1 = obj.getObject(path1);
IRTObject obj2 = obj.getObject(path2);
-
+
if (obj1 instanceof IInterfaceItem && obj2 instanceof IInterfaceItem) {
((IInterfaceItem)obj1).connectWith((IInterfaceItem) obj2);
}
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/RTSystemProtocol.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/RTSystemProtocol.java
index dcd2973c6..f4ccd974e 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/RTSystemProtocol.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/modelbase/RTSystemProtocol.java
@@ -4,10 +4,10 @@
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* CONTRIBUTORS:
* Henrik Rentz-Reichert (initial contribution)
- *
+ *
*******************************************************************************/
package org.eclipse.etrice.runtime.java.modelbase;
@@ -21,14 +21,14 @@ import org.eclipse.etrice.runtime.java.modelbase.RTSystemServicesProtocol.RTSyst
*
*/
public class RTSystemProtocol {
-
+
private static final String RT_SYSTEM_PORT_NAME = "RTSystemPort";
-
+
public static class RTSystemPort extends RTSystemServicesProtocolPort {
-
+
public RTSystemPort(IInterfaceItemOwner actor, int localId) {
super(actor, RT_SYSTEM_PORT_NAME, localId);
-
+
// since we have no mapping for the system ports we connect them directly here
IReplicatedInterfaceItem systemPort = actor.getSystemPort();
if (systemPort!=null) {
@@ -36,17 +36,17 @@ public class RTSystemProtocol {
connectWith(peer);
}
}
-
+
protected void connectWithPeer() {
}
-
+
@Override
- protected void destroy() {
+ public void destroy() {
super.destroy();
}
-
+
}
-
+
public static class RTSystemConjPort extends RTSystemServicesProtocolConjReplPort {
public RTSystemConjPort(IInterfaceItemOwner actor, int localId) {
@@ -57,17 +57,17 @@ public class RTSystemProtocol {
protected InterfaceItemBase createInterfaceItem(IInterfaceItemOwner rcv, String name, int lid, int idx) {
return new RTSystemConjSubPort(rcv, name, lid, idx);
}
-
+
}
-
+
public static class RTSystemConjSubPort extends RTSystemServicesProtocolConjPort {
public RTSystemConjSubPort(IInterfaceItemOwner actor, String name, int localId, int idx) {
super(actor, name, localId, idx);
}
-
+
protected void connectWithPeer() {
}
-
+
}
}

Back to the top