REMOTE OBJECT ACTIVATION
&OBJECTSERIALIZATION
Presented By,
N. Siva keerthana,
I - M . Sc(Computer Science),
Department of Computer Science,
Nadar Saraswathi college of Arts and Science
2.
DEFINITION
Activatable and theRMI daemon, rmid, programs can be written to register
information about remote object implementations that should be created and execute
"on demand", rather than running all the time.
CREATING AN ACTIVATABLE OBJECT:
Client.java, the class which will invoke a method on an activatable object
MyRemoteInterface.java, the interface that extends java.rmi.Remote,
implemented by:
ActivatableImplementation.java, the class which will be activated
Setup.java, the class which registers information about the activatable class
with the RMI registry and the RMI daemon.
3.
CREATING THE IMPLEMENTATIONCLASS
There are four steps to create an implementation class:
1. Make the appropriate imports in the implementation class
2. Extend your class from java.rmi.activation.Activatable
3. Declare a two-argument constructor in the implementation class
4. Implement the remote interface method(s)
STEP 1:
Make the appropriate imports in the implementation class
import java.rmi.*;
import java.rmi.activation.*;
4.
STEP 2:
Extend yourclass from java.rmi.activation.Activatable
public class ActivatableImplementation extends Activatable
implements examples.activation.MyRemoteInterface {
STEP 3:
Declare a two-argument constructor in the implementation class
public ActivatableImplementation(ActivationID id, MarshalledObject data)
throws RemoteException {
// Register the object with the activation system
// then export it on an anonymous port super(id, 0);
}
DEFINITION
Serialization is amechanism of writing the state of an object into a bytes-
stream. The reverse operation of serialization is called deserialization where byte-stream
is converted into an object.
The serialization and deserialization process is platform independent, it means
you can serialize an object on one platform and deserialize it on a different platform.
serializing - writeObject() method ObjectOutputStream class
deserialization - readObject() method ObjectInputStream class.
7.
DIAGRAM
The Serializable interfacemust be implemented by the class whose object needs
to be persisted.
The String class and all the wrapper classes implement the java.io.Serializable
interface by default.
8.
EXAMPLE
1. import java.io.Serializable;
2.public class Student implements Serializable{
3. int id;
4. String name;
5. public Student(int id, String name) {
6. this.id = id;
7. this.name = name;
8. }
9. }
In the above example, Student class implements Serializable interface. Now its objects
can be converted into stream.
9.
OBJECT OUTPUT STREAMCLASS
The ObjectOutputStream class is used to write primitive data types, and Java objects
to an OutputStream.
Constructor:
public ObjectOutputStream(OutputStream out) throws IO Exception {}- It creates
an ObjectOutputStream that writes to the specified OutputStream.
Important Methods:
public final void writeObject(Object obj) throws IO Exception {}- It writes the
specified object to the ObjectOutputStream.
public void flush() throws IO Exception {}- It flushes the current output stream.
public void close() throws IO Exception {} -It closes the current output stream.
10.
OBJECT INPUTSTREAM CLASS
AnObjectInputStream deserializes objects and primitive data written using an
ObjectOutputStream.
Constructor:
public ObjectInputStream(InputStream in) throws IO Exception {}- It creates an
ObjectInputStream that reads from the specified InputStream.
Important Methods:
public final Object readObject() throws IO Exception
classNotFoundException{} -It reads an object from the input stream.
public void close() throws IO Exception {} -It closes ObjectInputStream.