300 likes | 678 Views
Formal dialogues. A new approach to remote object communication implemented as an extension to C# on ROTOR/.NET Raphael Güntensperger Jürg Gutknecht ETH Zürich. Agenda. Overview Concepts Model Implementation Development platform for tiny devices (outlook). Communication model
E N D
Formal dialogues A new approach to remote object communication implemented as an extension to C# on ROTOR/.NET Raphael Güntensperger Jürg Gutknecht ETH Zürich
Agenda • Overview • Concepts • Model • Implementation • Development platform for tiny devices (outlook)
Communication model Formal dialogues Syntactic integration in C# Development environment for small wearable devices Burn-down of programmed logic Overview Use .NET as a cross-development platform for programmed ‘wearable’ devices. 1. 2.
Concept: Activity Concept: Channels Concepts • Motivation • Autonomous behavior of hardware objects • Independent activities • Asynchronous execution • Example: Clock • Rich interface to the environment • More than only a set of methods • Dialog-based interfaces • Objects have a status
Concepts • A new model for remote objects • Active Objects (activities) • Formal Dialogues (channels) • Universal encoding of syntactic Tokens • No: RPC, RMI, IDL, Proxies, Marshalling • Optimal Support by C# and .NET runtime • Compiler integration • Small library (System.Channels)
Concepts • Activities • Separate thread of control • Member of a class • Started at instantiation time of the object Defines an Active Object activity { … }
Passive Object Active Object Concepts • More about activities • No activity, one or more activities per class • Derived classes can define their own activities • All activities are started at instantiation time (incl. Base class activities) and run in parallel class ActiveObj { …. activity { … } activity { … } } class DerivedActiveObj : ActiveObj { … activity { … } … }
Concepts • Channels • Vehicle for the implementation of formal dialogues • Channel type formal dialogue Interface • Channel instance dialogue in execution • Channel implementation syntax parser Parser code channel MyChannel { … }
Set of implemented protocols Concepts • More about channels • Remote Interface of an object • Channel instances run in separate threads • Opened and closed by a client • Member of a class • In contrast to activities: • controlled by client • one instance (thread) per connection • communication capabilities (through accessors)
back direction Concepts • Communication follows a formal dialogue • Exchange of syntactic tokens • Can be described by an EBNF syntax • bi-directional definition • Parser defines semantic actions • Strongly typed tokens • Dialogue has its own status Example: ParkingLot = GetFree freeList parkingLot success freeList = { parkingLot } Partners do not store the status
Concepts Intrinsic activity of object Client A Channel protocoldefined as2 player syntax Channel instance Server Client B
d Channel type D? open D exchange syntactic tokens Concepts • Example: A B [ACK]
Save precondition for programming language independency Concepts • Advantages to Remote Method Invocation: • Sender is not blocked • State of the dialogue is completely captured by the channel • Tokens are typed by the underlying grammar and encoded according to universal rules.
Model Components & data flow abstraction
Implemented as public static methods inline (private) Model • Channel accessors: • open Instantiate channel, invoke parser • close abort parser thread • send pass token to buffer of remote channel • receive read token from buffer of remote channel • put pass token to internal channel buffer • get read token from internal channel buffer
Concrete example-implementation: TCP/IP Separation: Independent implementation Model 3 layer model for remote channels Implemented by the parser of a channel and the client which opens the channel Handling of channel instances. Abstraction of the communication technology Implementation of the transport technology. Responsible to transmit data blocks between destination. Exchangeable for any transport technology.
Model { c = new b.C }
Model • Gateway channels • Abstraction of a remotely available channel in the clients address space • ONE gateway (instead of proxies) • Implemented as member of channel manager • ChannelManager.RemoteChannel • Buffer content is directlysent to the remotechannel managerand vice versa
Model • Transmit Buffer-Content by channel manager • Channel Provider: Tracking buffers of channel instances • Client: Tracking buffers of RemoteChannel instances • Channel instances are identified by GUID
Model • Home Channel: • Query for implemented protocols • Implicitly implemented (by the compiler) for any channel provider • Provides a query mechanism comparable to COM (IUnknown) • Behaves exactly like any other channelbut follows a fixed syntax • Syntax • List names of implemented channels “list” nOfChannels { “channel”ChannelTypeName }
Implementation (Compiler) Channel variable (reference)
Implementation (Compiler) • Threading model • Thread represents channel instance • Buffer references stored relative to thread context • Thread is started by open accessor • Code example Advantage: Possibility to call channel accessors outside the parser method Named thread slots IL_001d: ldstr "$outBuf$“ IL_0022: call class [mscorlib]System.LocalDataStoreSlot [mscorlib]System.Threading.Thread::GetNamedDataSlot(string) IL_0027: ldloca.s V_0 IL_0029: ldfld class System.Channels.Buffer System.Channels.ChannelManager/RemoteChannel::$outBuf$ IL_002e: call void [mscorlib]System.Threading.Thread::SetData(class [mscorlib]System.LocalDataStoreSlot, object)
Implementation (Library) • Token • Map a set of basic types:char, int, long, float, double, keyword, string, bool, block, escape • Define their own encoding • Basic Format: tagByte { dataByte } • Shortest encoding for most frequently used types • Use value bits in the tag byte (for small data types) • Buffer • Ring-buffer implementation • enlarged automatically if the get full • Limit can be specified enumerations
Implementation (Library) • Channel manager • Responsible to handle channel instances and map their corresponding parts (local/remote) • Defines gateway channel • Channel manager messages: • Open/Close requests • Data transmission • Close enquiry • Acknowledgements GUID close idle channels
Implementation (Library) • Transport manager • Abstract class • Must be implemented for a specific technology • Current implementations: TCP/IP, Nullmodem • Must provide reliable transmission of encoded data • Destination Abstraction of the communication end-point
Implementation (Compiler/Library) • Implicit interface for channel providers • Defined in library, implemented by compiler • ChannelManager calls OpenChannel method of specific channel implementation • OpenChannel method • Implicitly generated by the compiler • Maps channel names to channel types • Returns buffer and thread references by ChannelNode structure public interface IChannel { ChannelNode OpenChannel(string name); }
class ParkingService {bool[] freeList;channel ParkingLot { Token currentToken; …while(true) { ?currentToken;if(currentToken is TokenKeyword && (Keywords) currentToken.Value == Keywords.GetFree) { SendFreeList(); ?currentToken; success = Park((int) (currentToken.Value)); !Token.NewToken(success); } } … } } Server Client Implementation (Example) ParkingLot = GetFree freeList parkingLot success int number, chosed; bool parked;// get free parking lotsmyChannel!Token.NewToken(Keywords.GetFree);myChannel?receivedToken;while((int) receivedToken.Value != -1) { Console.Write("{0} ", (int) receivedToken.Value); myChannel?receivedToken; }// chose one of the free parking lotsmyChannel!Token.NewToken(chosed);myChannel?receivedToken;parked = (bool) receivedToken.Value; enum
Development platform for tiny devices (outlook) • Cross compiler: IL StrongARM • Limited to the functionality demanded by tiny devices • Device represents active object • Implement a specific transport technology • Bluetooth / Smart-Its (University of Karlsruhe) • ‘Burn’ mechanism invokes cross compiler and builds operating system environment of the small device
Reference • .NET Developer’s Journal, Volume 01, Issue 3 • A New Approach to Remote Object Communication • http://www.sys-con.com/dotnet/