Experience the fun of distributed programming - [4]

zhaozj2021-02-16  45

Experienced distributed programming redstar81 in 9/9/2003 ~ 13/9/2003 81_redstar81@163.com Tomhornson.student@www.sina.com.cn

First modification time: 13/9/2003 personal text: http://www.9cbs.net/develop/author/neetauthor/redstar81/weblog: http://www.advogato.org/person/tomhornson /

2) Access the remote object

We know that in RMI or Remoting, we use distributed object technology, you need to create remote objects of the server, which requires the Remote interface and inherits in UnicastRemoteObject to obtain distributed feature support. And all this is simple under Voyager. Voyager generates a type-compatible agent at runtime, and provides several ways to do this: [A] Create a local object, then call the proxy static method proxy.of (Object obj) to create its agent .. [B] Use the name service. Voyager provides a name service function. Each object can be registered in the name service by using their names, and then other programs can get one agent of this object via Namespace.lookup (String Name). [C] This method is very characteristic. On the client, you can build an object on the remote machine with Factory.create (String ClassName, String URL) and returns the proxy for remote objects.

Below we will practice the remote object calculation in the Voyager environment through these methods:

Method A Example:

The program is broken 1:

//

// Project: RemoteObject

// filename: Iball.java

// creator and date: redstar81 2003-8-22 22:51

//

// statement:

//

Public interface iball {

Public void hit ();

}

//

// Project: RemoteObject

// filename: ball.java

// creator and date: redstar81 2003-8-22 22:51

//

// statement:

//

Public class ball imports Iball {

Public void hit () {

System.out.Println ("Ball Has Been Hit");

}

}

//

// Project: RemoteObject

// filename: bat.java

// creator and date: redstar81 2003-8-22 22:50

//

// statement:

//

Import com.Objectspace.voyager. *;

Public class bat {

Public void play (iball iball) {

Iball.hit ();

}

Public static void main (String [] args) {

Try {

Voyager.startup ();

BAT ba = new ba ();

Iball Iball = (iball) Namespace.lookup ("8000 / ball");

Bat.Play (Iball);

} catch (exception e) {

System.err.Println (e);

}

Voyager.shutdown ();

}

//

// Project: RemoteObject

// filename: Ballmachine.java

// creator and date: redstar81 2003-8-22 22:50

//

// statement:

//

Import com.Objectspace.voyager. *;

Public class ballmachine {

Public static void main (String [] args) {

Try {

Voyager.startup ("8000");

Ball ball = new ball ();

Iball iball = (iball) proxy.of (ball);

Namespace.bind ("8000 / Ball", IBALL);

} catch (exception e) {

System.err.Println (e);

}

}

}

The above procedure is very simple, knowing RMI or time Remoting, it looks at it, it will no longer explain it here.

Dramatic segment 2: Below is a program for a complicated point, where the client calls the computing object when calling the remote object:

//

// Project: RemoteObjectComplexComputing Using Voyager Producted by ObjectSpace

// filenaem: iComputing.java

// Creator and date: redstar81 2003-8-23 0:07

//

// Statement: It is uesd to test the conditons when pass a object!

//

Public interface iComputing {

Public Double Computing (ComputingObject Co);

}

//

// Project: RemoteObjectComplexComputing Using Voyager Producted by ObjectSpace

// filenaem: computing.java

// Creator and date: redstar81 2003-8-23 0:07

//

// Statement: It is uesd to test the conditons when pass a object!

//

Public class computing imports iComputing {

Public Double Computing (ComputingObject Co) {

System.out.println ("Computing is Done On this Machine!");

Return co.workcode ();

}

}

//

// Project: RemoteObjectComplexComputing Using Voyager Producted by ObjectSpace

// filenaem: computingserver.java

// Creator and date: redstar81 2003-8-23 0:07

//

// Statement: It is uesd to test the conditons when pass a object!

//

Import java.io. *;

Public class computingObject implements serializable {

//

// Serializable: NEED!

//

PRIVATE DOUBLE SUM = 0;

Private int dtstart, Dtend;

Public ComputingObject (int Datastart, int DataEnd) {dtstart = DataStart;

DTEND = DataEnd;

}

Public Double Workcode ()

{

For (int control = dtstart; control

SUM = Math.SQRT (Control);

Return New Double (SUM);

}

}

//

// Project: RemoteObjectComplexComputing Using Voyager Producted by ObjectSpace

// filenaem: computingserver.java

// Creator and date: redstar81 2003-8-23 0:07

//

// Statement: It is uesd to test the conditons when pass a object!

//

Import com.Objectspace.voyager. *;

Public class computingserver {

Public static void main (string [] args)

{

Try {

Voyager.startup ("8000");

Computing computingObject = new computing ();

IComputing iComputing = (iComputing) Proxy.of (ComputingObject);

Namespace.bind ("8000 / computing", iComputing;

} catch (Exception E)

{

System.err.Println (e);

}

}

}

//

// Project: RemoteObjectComplexComputing Using Voyager Producted by ObjectSpace

// Filenaem: Caller.java

// Creator and date: redstar81 2003-8-23 0:07

//

// Statement: It is uesd to test the conditons when pass a object!

//

Import com.Objectspace.voyager. *;

Public class caller {

Public static void main (String [] args) {

Try {

Voyager.startup ();

Computing computingObject = new computing ();

IComputing IC = (iComputing) Namespace.lookup ("// localhost: 8000 / computing);

Double ReturnValue = (Ic.computing (New ComputingObject (1,100000))). DoubleValue ();

System.out.println (returnvalue);

} catch (Exception E)

{

System.err.Println (e);

}

Voyager.shutdown ();

}

}

What needs to be counted above is to pass parameters to the remote object method requires a SERIALIZABLE interface.

to be continued:

2. DCOM

3. CORBA

4. WebServices

5. Sun RMI vs. DOTNET Remoting

6. Linda and Sun Javaspace, IBM Tspace7. Jini

8. Emerald vs. dejay

9. Pjama

10. IBM Mobile Computing Interface: Aglets

6. Comprehensive application analysis

1. Calculate technology to simulate high performance parallel computing with multi-threaded and distributed objects

2. Calculate geometric fractal graphs using Vdejay

statement:

1. I am not specializing in the distribution, completely written down this article. I will help distributed computing applicants. 2. Welcome to the level, welcome to correct. 3. Since this paper tells more content, many tells that it is impossible to be too meticulous. And taking into account the problem of the reader group, the theoretical content is omitted as much as possible. If the reader is interested, you can refer to the list of reference books and network resources.

4. Arbitrary reproduced, but please indicate the source; not available for commercial purposes.

转载请注明原文地址:https://www.9cbs.com/read-23571.html

New Post(0)