Title: Recap
1Recap
- BON Static Model
- Java Sockets
- Java Tools
2Today
- Remote Objects
- Programming with Java Remote Method Invocation
- Lab 3
3Distributed ObjectsMotivation
- Object orientation is useful as a structuring
mechanism for software systems. - RPC principles can be applied to objects to gain
the benefits of objects for distributed systems. - Method invocations on remote objects can give
better distribution transparency than RPCs. - Integration of type system with distributed
architecture
4Distributed ObjectsDefinitions
- Objects encapsulate data (state) and operations
on that data (methods). - The state of an object can (ideally) only be
modified through its interface. - An object may implement several interfaces.
- An interface may be implemented by multiple
objects.
5Distributed ObjectsDefinitions
- Strict separation between interface and
implementation enables us to put the interface on
one machine and the implementation on another. - An object with its implementation and interface
on separate machines is called a distributed
object. - When the implementation of a distributed object
is located on a single machine, the object is
also called a remote object.
6Distributed ObjectsTypical Remote Object
Organization
7Distributed ObjectsCompile-Time Objects
- Implementation is instance of a class declared at
compile time in an O-O language (Java, C,
Eiffel) - Upsides
- Straightforward to build distributed applications
- Objects defined entirely in terms of their
classes - Class definitions can be compiled directly into
client and server stubs - Downside
- Depends on a particular programming language
8Distributed ObjectsRuntime Objects
- Implementation is made to appear as a remote
object, but need not actually be implemented as
an object - Object Adapter wraps the implementation to create
this illusion - Objects defined solely in terms of their
interfaces - Implementations registered with an object
adapter, which makes the interfaces available for
use
9Distributed ObjectsRuntime Objects
- Upsides
- Objects need not be written in any particular
language - Distributed applications can be constructed using
many different languages - Downsides
- More complicated build process
- More heavyweight runtime systems
10Distributed ObjectsRuntime Objects
11Distributed ObjectsPersistence
- A persistent object continues to exist even when
its not in memory - Independent of any particular server process
- State is stored on disk or other secondary
storage when object isnt running - A transient object exists only as long as its in
memory - If server process dies, or object is dereferenced
and/or unallocated, its gone
12Distributed ObjectsBinding
- Unlike RPC systems, most distributed object
systems have systemwide object references - A reference to a remote object can be passed to
other remote objects as a parameter - A client must bind a reference to a remote object
- Implicit Binding client can use the reference
just like any local reference (-gt operator in
C, . operator in Java) - Explicit Binding client must call a special
function to bind the reference to the remote
object and get a local proxy
13Distributed ObjectsReferences
- RPC references include the address of the server
machine and the endpoint of the RPC service - Distributed object references can have the same
information, but there are drawbacks - Cant restart the server and assign a different
endpoint to a persistent object - Cant move the server, or individual objects, to
a different machine
14Distributed ObjectsReferences
- We can add a location server
- Keeps track of which machine is hosting which
objects - Object reference then contains location server
address, globally unique server identifier, and
object identifier - This can cause scalability problems (all object
references must talk through the location server) - References could also specify communication
protocols or downloadable proxy object
implementations, for more flexibility
15Distributed ObjectsInvocations
- Static
- Interfaces are predefined, so methods are called
just like methods on local objects - file.write(bytes)
- Dynamic
- Interfaces are not predefined, so methods are
called by referencing a method identifier - invoke(file, method(write), bytes)
16Distributed ObjectsParameter Passing
- Parameter passing usually less restricted than in
RPC, because object references can be passed - Object references are copied and passed around
only when they refer to remote objects - All other objects are passed by value
- This means that copies of objects can be
generated as side effects of method calls - This cant be hidden, but exposing it violates
distribution transparency
17Distributed ObjectsParameter Passing
18DCE Remote Objects
- Object model added to DCE when distributed
objects became the hot new abstraction - Extensions to DCE IDL
- C language bindings
- Two types of remote objects in DCE
- Distributed Dynamic Object - created on a server
on behalf of a single client, for use by only
that client - Distributed Named Object - created on a server
and listed by name in a directory service, for
use by multiple clients
19DCE Remote Objects
20DCE Remote ObjectsInvocation
- Each object invocation is done with an RPC
- Parameters are object identifier, interface
identifier, method identifier, and method
parameters - Server has an object table that is used to
resolve the call - Persistence is supported
- When a call comes in that no running object can
handle, the server can retrieve an object from
secondary storage - No mechanism for transparent object references
21Java Remote Method Invocation
- Remote objects are part of all current Java
distributions - Clients make method calls on proxy objects
- Important differences between remote objects and
local objects in Java - clone() on a proxy clones the object on the
server and returns a new proxy instead of cloning
the proxy - Synchronized methods are synchronized on the
proxy, not on the remote object - distributed
synchronization must be done explicitly using
other methods
22Java Remote Method InvocationInvocation Details
- Any primitive type or Serializable object type
can be passed as a parameter to a remote method - Local objects (and primitive types) are passed by
value, and remote objects are passed by reference - Additional exceptions must be handled
- Bytecode (or a pointer to bytecode) is sent for
classes that dont have implementations at the
destination - this works because the (virtual)
machines have identical binary architectures
23Java Remote Method InvocationClasses and
Interfaces
24Java Remote Method InvocationMarker Interfaces
- java.io.Serializable
- Interface that must be implemented by any class
used as a parameter in a remote interface - Most of the classes in the standard Java class
library implement Serializable - No methods
- java.rmi.Remote
- Interface that must be inherited by all remote
interfaces - No methods
25Java Remote Method InvocationExceptions
- All methods in remote interfaces must be declared
to throw java.rmi.RemoteException (or a
superclass, such as java.io.IOException or
java.lang.Exception) - Methods in remote interfaces may throw
application-specific exceptions other than
RemoteException - When such an exception is thrown on the server
side, it is wrapped in a RemoteException and
returned to the client side, where it is
unwrapped automatically
26Java Remote Method InvocationExample Interface
- interface RemoteHashtableInterface extends Remote
-
- public Serializable put(Serializable key,
Serializable value) - throws RemoteException, NullPointerException
- public Serializable get(Serializable key)
- throws RemoteException
- public void clear()
- throws RemoteException
27Java Remote Method InvocationCore Classes
- java.rmi.server.RemoteObject
- Includes implementations of the java.lang.Object
methods hashCode(), equals() and toString() for
remote objects - java.rmi.server.UnicastRemoteObject
- Includes methods needed to create and export
simple remote objects (references are only valid
for the lifetime of the server) - Most remote interface implementations are
subclasses of UnicastRemoteObject
28Java Remote Method InvocationExample
Implementation (Part 1)
- public class RemoteHashtable extends
UnicastRemoteObject - implements RemoteHashtableInterface
-
- private Hashtable hashtable new Hashtable()
- public Serializable put(Serializable key,
Serializable value) - throws RemoteException, NullPointerException
-
- return (Serializable) hashtable.put(key,
value) -
29Java Remote Method InvocationExample
Implementation (Part 2)
- public Serializable get(Serializable key)
- throws RemoteException
-
- return (Serializable) hashtable.get(key)
-
- public void clear() throws RemoteException
-
- hashtable.clear()
-
30Java Remote Method InvocationCore Classes
- java.rmi.activation.Activatable
- Includes methods needed to create and export
activatable objects that are executed by an
activation daemon when methods are invoked on
them - Activatable objects can easily be made persistent
- loaded into memory when needed, saved to disk
when not being used - We wont be using Javas activation framework
right away
31Java Remote Method InvocationNaming
- java.rmi.Naming
- Static methods for binding and unbinding names to
remote objects, looking up remote objects by
name, and listing all bound objects on a
particular server - Examples
- Naming.bind(//localhost8888/hashtable,hashtable
) - RemoteHashtable remoteTable
- (RemoteHashtable) Naming.lookup
- (//rmi.caltech.edu8888/hashtable)
32Java Remote Method InvocationRegistries
- Name lookups are done on an RMI registry
(analogous to portmap for RPC) - Class java.rmi.registry.LocateRegistry contains
methods to create registries - URL passed to Naming methods contains hostname
and port number of a registry, and identifier of
an object - Interface java.rmi.registry.Registry contains
methods to interact directly with a registry
without going through the Naming class
33Java Remote Method InvocationCompilation
- RMI compiler, rmic, generates stubs and skeletons
from remote object implementations - Example the command that generates the stubs and
skeletons for our RemoteHashtable class - rmic caltech.cs141.cs141.RemoteHashtable
- This is handled automatically by Ant, when
properly configured in the build file
34Lab 3
- Out now, due 235959 next Thursday
- Entirely design
- Take the API specification for JavaSpaces (a
communication method based on Java RMI) and write
a BON specification for it - Entire BON static model (high-level, plus typed
class interfaces with contracts and class
relationships) - We ignore distributed transactions and leasing