Java Kernel API
Class BinarySemaphore java.lang.object +--BinarySemaphore public final class BinarySemaphore extends java.lang.object This class represents a binary semaphore. The value of a binary semaphore can be either 0 or 1. Constructor Summary BinarySemaphore(int value) Constructs a binary semaphore. Method Summary void binsignal() Increments the semaphore if it is 0. void binwait() Decrements the semaphore if it is 1. Methods inherited from class java.lang.object clone, equals, finalize, getclass, hashcode, notify, notifyall, tostring, wait, wait, wait Constructor Detail BinarySemaphore public BinarySemaphore(int value) Constructs a binary semaphore. 1
2 Class BinarySemaphore value - The initial value of the semaphore (0 or 1). Method Detail binwait public void binwait() Decrements the semaphore if it is 1. Blocks until binsignal() is called if it is 0. binsignal public void binsignal() Increments the semaphore if it is 0. Undefined if it is 1.
Class EventSet java.lang.object +--EventSet public class EventSet extends java.lang.object This class represents a set of events. Constructor Summary EventSet() Constructs an empty set of events. EventSet(EventSet eventset) Constructs a set of events containing the same events as another set. EventSet(int e1) Constructs a set of one event. EventSet(int e1, int e2) EventSet(int e1, int e2, int e3) EventSet(int e1, int e2, int e3, int e4) EventSet(int e1, int e2, int e3, int e4, int e5) Method Summary EventSet copy() Returns a copy of this set. void copy(eventset eventset) Overwrites (copies into) this set with another set, destroying this set. void copy(int e) Removes all events from the set, except for one event, which is added. boolean empty() Checks to see of the set is empty. boolean equals(eventset ceventset) 3
4 Class EventSet Checks to see if two sets are equal. void excl(eventset eventset) Removes a set of event from the this set. void excl(int e) boolean has(int e) Checks if an event is included in the set. void incl(eventset eventset) Adds a set of events to this set. void incl(int e) Adds an event to this set. void intersection(eventset eventset) Makes this set of ervent the intersection of this set and the supplied set. Methods inherited from class java.lang.object clone, equals, finalize, getclass, hashcode, notify, notifyall, tostring, wait, wait, wait Constructor Detail EventSet public EventSet() Constructs an empty set of events. EventSet public EventSet(int e1) Constructs a set of one event. e1 - The event to be a member of the set. EventSet public EventSet(int e1, int e2)
Class EventSet 5 EventSet public EventSet(int e1, int e2, int e3) EventSet public EventSet(int e1, int e2, int e3, int e4) EventSet public EventSet(int e1, int e2, int e3, int e4, int e5) EventSet public EventSet(EventSet eventset) Constructs a set of events containing the same events as another set. eventset - The set of events to be contained in this set. Method Detail incl public void incl(eventset eventset) Adds a set of events to this set. eventset - The set of events to add.
6 Class EventSet incl public void incl(int e) Adds an event to this set. i - the ervent to add excl public void excl(eventset eventset) Removes a set of event from the this set. eventset - The event to remove. excl public void excl(int e) copy public EventSet copy() Returns a copy of this set. Returns: The copy. copy public void copy(eventset eventset) Overwrites (copies into) this set with another set, destroying this set. eventset - The set to overwrite this set with.
Class EventSet 7 copy public void copy(int e) Removes all events from the set, except for one event, which is added. i - The event to add. intersection public void intersection(eventset eventset) Makes this set of ervent the intersection of this set and the supplied set. eventset - The set to take intersection with. has public boolean has(int e) Checks if an event is included in the set. e - The event to check. Returns: true if the event is in the set; false otherwise. empty public boolean empty() Checks to see of the set is empty. Returns: true if the set is empty. equals public boolean equals(eventset ceventset) Checks to see if two sets are equal. ceventset - The set to check with.
Class GeneralSemaphore Class GeneralSemaphore java.lang.object +--GeneralSemaphore public final class GeneralSemaphore extends java.lang.object This class represents a general semaphore. The value of a general semaphore can be greater than or equal to 0. Constructor Summary GeneralSemaphore(int i) Constructs a general semaphore. Method Summary void gensignal() Increments the semaphore. void genwait() Decrements the semaphore if it is larger than 0. Methods inherited from class java.lang.object clone, equals, finalize, getclass, hashcode, notify, notifyall, tostring, wait, wait, wait Constructor Detail GeneralSemaphore public GeneralSemaphore(int i) Constructs a general semaphore. 8
Class GeneralSemaphore 9 i - The initial value of the semaphore ( 0). Method Detail genwait public void genwait() Decrements the semaphore if it is larger than 0. Blocks until binsignal() is called if it is 0. gensignal public void gensignal() Increments the semaphore.
Class Kernel java.lang.object +--java.lang.thread +--Kernel All Implemented Interfaces: java.lang.runnable public abstract class Kernel extends java.lang.thread This class is an extension to java that supports multiple processes and message passing synchronization as well as event handling. The kernel has two modes of operation: init-mode and normal-mode. In init-mode, the kernel operates exactly as a normal java program. Init mode is intended for process creation and general setup. Processes are created with the createstdprocess() method call. After the setup and process creation is finished, the kernel can be switched to normal-mode with the startprocesses() method call. The call to startprocesses() will never return, but all processes created with createstdprocess() will start to execute concurrently. This is a simple example that shows basic process creation: public class Exempel1 { public static void main(string[] args) { //create objects representing the process Kernel process1 = new TestProcess("Process 1", "Hello Anna!"); Kernel process2 = new TestProcess("Process 2", "Hello Bertil!"); } } //start processes (leave init-mode) Kernel.startProcesses(); public class TestProcess extends Kernel { private String message; TestProcess(String name, String message) { 10
Class Kernel 11 //tell the kernel that this is a process createstdprocess(name, NoTimer); } this.message = message; } //this method represents the process public void run() { System.out.println(message); } Field Summary protected static int Alarm This is used as argument to createstdprocess and means that the process will receive a timeevent after i milliseconds, where i is the argument of settimebase(). protected static int ev0 protected static int ev1 protected static int ev10 protected static int ev11 protected static int ev12 protected static int ev13 protected static int ev2 protected static int ev3 protected static int ev4 protected static int ev5
12 Class Kernel protected static int ev6 protected static int ev7 protected static int ev8 protected static int ev9 protected static int MonoStable This is used as argument to createstdprocess and means that select() or await() will wait at most i milliseconds before they will receive a timeevent, where i is the argument of settimebase() protected java.lang.object NoData A dummy message. protected static int NoTimer This is used as argument to createstdprocess and means that no timer will be used for this process. protected static int Periodic This is used as argument to createstdprocess and means that a timeevent will be sent to this process every i:th millisecond, where i is the argument of settimebase(). protected static int TimeEvent This is the event that is received after invoking settimebase(). Fields inherited from class java.lang.thread MAX PRIORITY, MIN PRIORITY, NORM PRIORITY Constructor Summary Kernel() Method Summary protected java.lang.object asyncreceive() Receives an asynchronous message. protected void asyncsend(java.lang.object message) Sends an asynchronous message to this process. protected void await(int event) Waits for an event.
Class Kernel 13 protected Kernel createstdprocess(java.lang.string name, int timermode) Creates a process and sets the timermode of the process. protected void nap(long ms) Makes the process block for a specified amount of time. protected Message receive() Extracts a pending message sent by protected void reply(java.lang.object message) Sends the reply message to a process that has invoked sendwait() on this process. protected int select(eventset eventset) Waits for a set of events. protected java.lang.object sendwait(int event, java.lang.object message) Implements extended rendezvous. protected void settimebase(long ms) Sets the timebase for this process. protected void signal(int event) Sends an event to this process. void start() static void startprocesses() Starts all defined processes. protected java.lang.object syncreceive() Receives a synchronous message. protected void syncsend(java.lang.object cmessage) Sends a synchronous message to this process. Methods inherited from class java.lang.thread activecount, checkaccess, countstackframes, currentthread, destroy, dump- Stack, enumerate, getcontextclassloader, getname, getpriority, getthread- Group, interrupt, interrupted, isalive, isdaemon, isinterrupted, join, join, join, resume, run, setcontextclassloader, setdaemon, setname, setpriority, sleep, sleep, stop, stop, suspend, tostring, yield Methods inherited from class java.lang.object clone, equals, finalize, getclass, hashcode, notify, notifyall, wait, wait, wait Field Detail TimeEvent protected static final int TimeEvent This is the event that is received after invoking settimebase().
14 Class Kernel ev0 protected static final int ev0 ev1 protected static final int ev1 ev2 protected static final int ev2 ev3 protected static final int ev3 ev4 protected static final int ev4 ev5 protected static final int ev5
Class Kernel 15 ev6 protected static final int ev6 ev7 protected static final int ev7 ev8 protected static final int ev8 ev9 protected static final int ev9 ev10 protected static final int ev10 ev11 protected static final int ev11
16 Class Kernel ev12 protected static final int ev12 ev13 protected static final int ev13 NoTimer protected static final int NoTimer This is used as argument to createstdprocess and means that no timer will be used for this process. This means that a call to settimebase() will be an error. Periodic protected static final int Periodic This is used as argument to createstdprocess and means that a timeevent will be sent to this process every i:th millisecond, where i is the argument of settimebase(). MonoStable protected static final int MonoStable This is used as argument to createstdprocess and means that select() or await() will wait at most i milliseconds before they will receive a timeevent, where i is the argument of settimebase() Alarm protected static final int Alarm This is used as argument to createstdprocess and means that the process will receive a timeevent after i milliseconds, where i is the argument of settimebase().
Class Kernel 17 NoData protected final java.lang.object NoData A dummy message. Use when no message is needed. Constructor Detail Kernel public Kernel() Method Detail start public final void start() Overrides: start in class java.lang.thread startprocesses public static final void startprocesses() Starts all defined processes. Processes are defined through createstd- Process(). settimebase protected final void settimebase(long ms) Sets the timebase for this process. After invoking this method, a timeevent will be generated according to the timermode of the process. The timermode for the process is defined through createstdprocess. ms - The timebase for this process, in milliseconds.
18 Class Kernel nap protected final void nap(long ms) Makes the process block for a specified amount of time. This requires the process to have timer, which means that you cannot supply NoTimer to createstdprocess(). ms - Milliseconds to block. createstdprocess protected Kernel createstdprocess(java.lang.string name, int timermode) Creates a process and sets the timermode of the process. Returns: name - The name of the process. timermode - The timermode of the process. Can be NoTimer, Periodic, Monostable or Alarm. A reference to the created process (same as the object reference to the object representing the process). sendwait protected final java.lang.object sendwait(int event, java.lang.object message) Implements extended rendezvous. A process can send a message to this process by invoking this method on this process. This process will then receive an event and a message. The event should be received by await() or select() and the message should be received by receive(). This process should then reply to the sender, who is blocked, with reply() and the sender will then receive the message supplied to reply(). event - The event that this process should receive. message - The message that this process should receive.
Class Kernel 19 receive protected final Message receive() Extracts a pending message sent by Returns: An instance of Message that contains the message received and the sender of the message (a reference). signal protected final void signal(int event) Sends an event to this process. This should be invoked by a process that wants this process to receive an event. event - The event to be sent. await protected final void await(int event) Waits for an event. The event can be generated by signal(), sendwait(), or can be a TimeEvent. This method will block until the event is received. event - The event to wait for. reply protected final void reply(java.lang.object message) Sends the reply message to a process that has invoked sendwait() on this process. This will release that process. message - The reply message.
20 Class Kernel select protected final int select(eventset eventset) Waits for a set of events. This method will block until an event included in the set is received. Returns: ceventset - The set of events to wait for. The event received. syncsend protected final void syncsend(java.lang.object cmessage) Sends a synchronous message to this process. A process invoking this method will block until this process (the recipient) invokes syncreceive(). cmessage - The message to send. syncreceive protected final java.lang.object syncreceive() Receives a synchronous message. Send() is invoked on this process. Returns: The message received. This method will block until sync- asyncsend protected final void asyncsend(java.lang.object message) Sends an asynchronous message to this process. A process invoking this will not block. message - The message to send.
Class Kernel 21 asyncreceive protected final java.lang.object asyncreceive() Receives an asynchronous message. This method will block until async- Send() is invoked on this process. Returns: The message received.
Class MailBox java.lang.object +--MailBox public class MailBox extends java.lang.object This class is implements a mailbox, also known as asynchronous channel. Constructor Summary MailBox() Constructs an empty mailbox. Method Summary java.lang.object check() Retrives a mail from the mailbox. void mail(java.lang.object cmessage) Posts an object to the mailbox. Methods inherited from class java.lang.object clone, equals, finalize, getclass, hashcode, notify, notifyall, tostring, wait, wait, wait Constructor Detail MailBox public MailBox() Constructs an empty mailbox. Method Detail 22
Class MailBox 23 mail public void mail(java.lang.object cmessage) Posts an object to the mailbox. object - The object to post to the mailbox. check public java.lang.object check() Retrives a mail from the mailbox. This method will block if the mailbox is empty until there is an object in the mailbox.
Class MChannel java.lang.object +--MChannel public class MChannel extends java.lang.object This class represents a synchronous many-to-many channel. Constructor Summary MChannel() Constructs a synchronous many-to-many channel. Method Summary java.lang.object read() Reads an object from the channel (blocks until write() is invoked). void write(java.lang.object object) Writes an object into the channel and waits for a receiver. Methods inherited from class java.lang.object clone, equals, finalize, getclass, hashcode, notify, notifyall, tostring, wait, wait, wait Constructor Detail MChannel public MChannel() Constructs a synchronous many-to-many channel. Method Detail 24
Class MChannel 25 write public void write(java.lang.object object) Writes an object into the channel and waits for a receiver. object - The object to put in the channel. read public java.lang.object read() Reads an object from the channel (blocks until write() is invoked). Returns: The object supplied to write().
Class Message java.lang.object +--Message public class Message extends java.lang.object This class represents a message received by the Kernel.receive() method in Kernel. Method Summary java.lang.object getmessage() Returns the message. Kernel getprocess() Returns the process reference. Methods inherited from class java.lang.object clone, equals, finalize, getclass, hashcode, notify, notifyall, tostring, wait, wait, wait Method Detail getprocess public Kernel getprocess() Returns the process reference. Returns: The sending process. When the Messsage object is returned by Kernel.receive(), this is a reference to the sending process. 26
Class Message 27 getmessage public java.lang.object getmessage() Returns the message. Returns: The message sent. When returned by Kernel.receive(), this is the message sent (passed to Kernel.sendWait() of the sending process).