MokaByte
Numero 19 - Maggio 1998
|
|||
Paolo Ciancarini & Davide Rossi |
for Java agents |
||
The access to an object space is performed using a set of methods of the ObjectSpace class. Such operations are out (to put an object in the object space), in and read (to get or to read associatively an object from the object space), and others, mostly inspired by the Linda language.
Jada does not extends the syntax of Java because it is a set of classes. We show how it changes the way we design multiuser, distributed applications (such as the ones based on the WWW) allowing easy interactions between software components and agents.
Under this perspective we can outline a system of any scale which uses the dynamic linking capability of Java to distribute the code and the coordination facility of Jada to handle distributed entities inter-relations.
Although Java is multithreaded and allows remote dynamic code loading, it is not a language for distributed programming. The only facility offered by the language for supporting distributed processing is a sockets library. However, programming distributed systems using sockets is notoriously boring, difficult and error-prone. An alternative strategy consists of adding to Java high-level coordination mechanisms: this is the theme of this paper.
The language model is somehow limited but its strongest point is its great simplicity.
Java programs are made of objects. Java objects are instances of classes. A class can inherit from a base class (just one, multiple inheritance is not supported) to extend the behavior of that base class.
Java programs are compiled into a binary format that can be executed on many platforms without recompilation using a ``bytecode interpreter'', also known as Java Virtual Machine (JavaVM). The bytecode is linked on the fly when loaded to be run. All the dependencies in the byte-code are symbolic and are resolved only at load time. The loading of a class code happens only when it is required. Furthermore the user can extend the manner in which the Java Virtual Machine dynamically loads classes, creating, for example, a network class loader in order to load a class code from a remote server, implementing code mobility.
Thus, the JavaVM contains mechanisms to check the code it has to run, in order to avoid viruses and security violations.
Java is architecture neutral: every machine-dependent code is not part of the language itself but of its standard library. Java libraries are collections of classes called ``packages''. We can think of Java as an environment built by the language itself and its standard packages. Several aspects of the language depend indeed from the standard packages as defined by Java designers. For instance, multithreading is native in Java, but there is no way to create a thread other than using a method of the Thread class.
In the standard Java environment a set of packages is provided; these packages are:
An applet is the byte-code result of a compilation of a class that extends the class Applet contained in the java.applet package. This means that each applet inherits a standard behaviour from Applet and has to comply with a set of conventions which let them run within a Java-compatible browser.
In a first attempt to seriously overcome this kind of limitations a distributed object model for Java has been proposed: the remote method invocation (RMI).RMI uses the well known CORBA approach which, while allows easy distributed objects basic interactions, doesn't allows any kind of mobility. Our approach is a step further: we want add to Java coordination capabilities in order to allow any kind of complex interactions between potentially remote objects.
We designed Jada aiming to simplicity rather than performance. Jada, like Linda, is a minimalist coordination language. Differently from other Linda-like implementations, which usually include a preprocessor necessary because Linda slightly changes (i.e. it constrains) the host language syntax, Jada is based on a set of classes to be used to access an object space, allowing the users to keep their standard Java development tools.
To create an object space we write:
ObjectSpace my_object_space=new ObjectSpace();To put an object in the object space we can write:
my_object_space.out(new String("foo"));To access the ObjectSpace for getting objects we use an associative mechanism: when the user calls the in method he have to pass it an object which is used as a matching pattern. The object the in method will return (if any) is an object from the object space that matches the given matching pattern (the same applies to the read method; the difference between read and in is that in removes the returned object from the object space).
To allow enough flexibility to the matching operations we introduce the concepts of formal and actual objects: a formal object is an instance of the Class class (the meta-class used by Java). Any other object is an actual object.
The Jada matching rules are:
These matching rules are quite simple yet very powerful; but are sometimes not enough expressive to match the requests of the user. Thus we introduce the Tuple class, an object container class with an extended matching mechanism which is more expressive.
This is an example of Jada tuple:
Tuple my_tuple=new Tuple(new Integer(10),"test");Such a tuple includes two items (we say that its cardinality is two); the first item is an Integer object, the second one is a String object. We define actual and formal items within a tuple the same way we defined them for Jada.
To use associative object space access with tuples we can use the tuples' matching mechanism:
two tuples a and b are matching if they have the same cardinality and each item of a matches the corresponding item of b. The usual Jada mechanism is used to check if the items are matching.
Thus, the tuple
Tuple a=new Tuple(new Integer(10),"test");matches the tuple:
Tuple b=new Tuple(new Integer(10),new String().getClass());Note that to exchange a tuple (and generally any kind of object) two threads do not need to perform a pair of out and read operations at the same time (Jada does not need rendez-vous communication). In fact, suppose the threads ta and tb want to exchange a message: ta will put a message inside the object space, tb will read the message from the object space. If ta performs the out operation before tb performs the read operation it does not have to wait for tb: it simply continues its execution, the tuple is now stored into the object space. When tb performs the read operation it will be able to read it.
Instead, if tb performs the read operation before ta performs the out operation, tb will be blocked until an object that satisfy the read request will become available (i.e. until ta performs the out operation).
The in and read methods are indeed blocking. If you want the thread not to be blocked when a matching object for the in and read operations is not available you can use the in_nb and read_nb methods: they access the object space the same way as in and read but if no matching object is available they simply return null (a more sophisticated flavor of in and read that aborts after a time-out is available too).
The object space server is addressed using the IP address of the host it runs on and with its own port number (as usual with socket connections). This way we can run (almost) as many object space servers as we like in a network, so that applications can independently operate on several, distributed object spaces. ObjectServer is a multithreaded server class which translates requests received from the ObjectClient class in calls to the methods of the ObjectSpace class.
In fact, both ObjectServer and ObjectClient are based on ObjectSpace.
ObjectServer and ObjectClient communicate using sockets.The ObjectClient class extends ObjectSpace changing its internals but keeping its interface and behavior (apart from some new constructor and few new methods). Thus, a ObjectClient object is used just like a ObjectSpace one, except that it provides access to a remote object space which can run in any host of the network.ObjectServer uses ObjectSpace to perform the requested operations.
What ObjectClient does is to interface with a remote ObjectServer object (which holds the real object space) and requests it to perform the in, read and out operations and (eventually) to return the result.
An object space can be either local to the application or applet (ObjectSpace, to be shared between threads) or remote (ObjectClient, to be shared between applications or applets) in order to build a distributed application.
In the latter case an object space server (ObjectServer) must be running in a host of the network.
In Fig.1 we graphically outline how an application can access a remote tuple space.
Figure 1:
Client/Server relationships in Jada
Serialization must, of course, also be supported by tuples' items (we indeed need to know how to dump/restore them in order to dump/restore a tuple).
The Tuple class itself implements the JadaItem interface so we can use a Tuple object as a field of a tuple.
The methods are the usual in, read and out (along with their multiple, non-blocking and time out-aware variants). All these methods are actually just wrappers for the doInRead and doOut methods, which are the real ``engines'' for this class. All the synchronization and repository management code is part of these methods. This allows to easily redefine ObjectSpace behaviour by extending its class just like we did with ObjectClient. For example the doOut method of ObjectSpace takes care of putting the specified object in the object space or use it to reply pending in or read requests. The ObjectClient's version of doOut, instead, sends the tuples to an object server and asks it to manage the storing/replying. The same applies for ObjectClient's version of doInRead. We need indeed just to change these two methods to deal with a remote tuple manager (which is a ObjectServer object) and use socket connections to talk with it.
If we analyze the behavior of a Jada program we can distinguish two main cases:
Figure 2:
Local threads accessing an object space
Each shape in such a picture represents a thread running within an application. Thread1, Thread2, and Thread3 are interacting with the object space (using ObjectSpace methods). The ObjectSpace object manages their access and takes care of handling critical regions managing. Note that some of the thread may have blocked calling a method to perform a blocking in or read operation.
Figure 3:
Remote threads accessing an object space
Thread1 and Thread2 are now part of an application while Thread3 is part of a different one. The former are using the same ObjectClient object to access the object space, while the latter uses a private one. When a thread performs a request calling a method of the ObjectClient object, the request if forwarded to the ObjectServer object, using a network connection, which runs a thread to handle it. Each thread run by the object server then corresponds to a remote thread which performed a request (this is actually not always true because of the optimizations we did to the package, this general concept, however, is more easy to understand).
We are using Jada as coordination kernel for implementing more complex Internet languages and architectures. In particular, we are developing on top of Jada the Shade/Java agent based coordination language, and PageSpace, a coordination architecture for using the WWW as middleware for building cooperative applications (eg. groupware, electronic commerce) over the Internet.
In fact, although it explicitly refers to Linda, the WWWinda approach is quite different from what we have described here. Since the integration between WWW browsers and their helper applications is extremely rudimental (it is only possible to activate the external application and to deliver the data to be displayed), the WWWinda research team designed a flexible, modular WWW browser architecture based on the Linda programming language. Several independent tools, each implementing a different part of the whole WWW browser, are activated according to needs, sharing screen space, HTTP responses, and user interaction. This allows for a highly modular architecture, where new services and tools can be added without modifications in a homogeneous framework. In order to allow cooperation among helper modules, these all make use of a shared tuple space. Tuples allow to upgrade the simple ``activate with these data'' paradigm of browsers' helper applications to a more complete coordination protocol. For instance, WWWinda has been used to coordinate a distributed digital orchestra, in which several browsers simulating musical instruments (possibly running on different machines) extract from the shared tuple space the tune to be played note by note. No instrument is aware of how many other instruments are present, and new ones can be added on the fly, even in the middle of a performance.
All features of WWWinda, that we define a ``client-side coordination toolkit'' are easily implementable in Jada.
Instead, the WU Linda Toolkit is a simple interface between a WWW browser and a WWW server implementing a tuple space service. Access to the shared tuple space is provided to clients: users can fill in an HTML form with the appropriate Linda command to interact with the tuple space. The main application on show is a disc-load viewer that allows a first glance check of current disk usage of the computers of a cluster of workstations. Each workstation hosts a WU Linda client which posts tuples in the shared tuple space describing the current load of the disks it controls. These tuples are then collected and rendered in a user-friendly way via HTMl to any browser querying the application.
Again, all features of WU Linda, that we define a ``server-side coordination toolkit'' are easily implementable in Jada.
Jada applets are very similar to Oblets, or ``distributed active objects''. An oblet is a program written in Obliq and executed on a browser. Each oblet can use high-level primitives to communicate with other oblets running on possibly remote browsers.
The Bauhaus ``Turingware Web'' designed in Yale (the homeland of Linda) is similar at least in spirit to the WU Linda toolkit. The main idea consists of using a standard browser to access a Bauhaus server. Bauhaus is a coordination language based on nested multiple tuple spaces (multisets) which can be used in this case for both controlling the hierarchical structure of the pages of a web site, and for associating agents and their activities to the pages themselves. For instance, one attribute of a page could be the list of users ``acting'' in such a page, who are displayed by a graphic icon and can interact using some ad-hoc cooperation services.
This application of coordination technology to the WWW is based on a language richer than Linda. We are also investigating similar extensions, based on multiple tuple spaces, in a coordination language called Shade, whose kernel is currently written in Jada.
|
||
|
||
MokaByte ricerca
nuovi collaboratori
|
||
|