0% found this document useful (0 votes)
30 views3 pages

Java Remote Activation Example Code

This document provides an example of how to implement remote activation of objects in Java using the activation model. It involves the registry and activator. The class to be activated remotely must extend Activatable and implement a remote interface. The constructor takes an ActivationID and marshalled object. The object is registered with the activation system and its interface is published in the naming service, making it available for remote clients.

Uploaded by

balusathishkumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views3 pages

Java Remote Activation Example Code

This document provides an example of how to implement remote activation of objects in Java using the activation model. It involves the registry and activator. The class to be activated remotely must extend Activatable and implement a remote interface. The constructor takes an ActivationID and marshalled object. The object is registered with the activation system and its interface is published in the naming service, making it available for remote clients.

Uploaded by

balusathishkumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Activation Model Example

Capability: Remote activation of an object.


Involves the Registry and the Activator.
// Imports
import
import
import
import
import
import
import
import
import
import

[Link];
[Link];
[Link];
[Link];
[Link];
[Link].*;
[Link];
[Link];
[Link];
[Link];

// A class of object that can be activated remotely. The class


// must extend the Activatable class
public class RemoteActivatableObject
extends Activatable
implements RemoteInterface
{

// The constructor must have this signature


public RemoteActivatableObject(
ActivationID id, MarshalledObject data)
throws RemoteException
{

// Register the object with the activation system


super(id, 0);
}

// Test method
public String message(String message) throws RemoteException
{
String returnString = "Thanks for your message:"+message;
[Link]("Returning:"+returnString);
return "Thanks for your message:"+message;
}
1

// Main method
public static void main(String[] args) throws Exception
{
[Link](new RMISecurityManager());

// Define the location were the object can be found


[Link] location =
new [Link]("file:/src/se4/");

// Create a CodeSource object. 2nd param. is a PK, ignored here


CodeSource source = new CodeSource(location, null);

// Get the properties of the system


Properties props =
(Properties)[Link]().clone();

// Create an activation group descriptor and a group ID


ActivationGroupID agid =
[Link]().registerGroup(
new ActivationGroupDesc(props));

// Marshall the parameters


MarshalledObject data = null;

// Create an activation descriptor


ActivationDesc desc =
new ActivationDesc (
agid, "RemoteActivatableObject", source, data);

// Enter descriptor into registry


RemoteInterface remoteInterface =
(RemoteInterface) [Link](desc);

// Publish the interface in the naming service


[Link]("ServerTest", remoteInterface);
}
}

Compilation and execution

// compile the server


javac [Link]
// generates stubs
rmic RemoteActivatableObject
// start the registry
start rmiregistry
// start the RMI daemon,
// instantiates objects when required
rmid
// initialize the server
java RemoteActivatableObject
// start a client
java RemoteClient
Source
[Link], Using Java 2 Platform, Que, 1998.

You might also like