Experience the fun of distributed programming - [5]

zhaozj2021-02-16  49

Experience the distributed programming

Redstar81 at 9/9/2003 ~ 13/9/2003 81_redstar81@163.com Tomhornson.student@www.sina.com.cn

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

Method C example:

The program is broken 1:

Here is just on the client program. But the client and server side need to start the Voyager runtime environment when premising.

//

// 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) Factory.create ("Computing", "OtherServer: 9000);

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

System.out.println (returnvalue);

} catch (Exception E)

{

System.err.Println (e);

}

Voyager.shutdown ();

}

}

This Factory has established a remote object on the remote server OtherServer and is used locally using a remote object.

3) Migration of the object

In general, we need object migration in the following occasions:

[A] When the local object and server object interaction require a lot of communication. This price is much larger than the cost of the object migration. [B] offline calculation of mobile devices.

[C] Support workflow. In a collaborative workflow system, the migration of objects is a practical practice.

[D] load balance.

We think that in the distribution object computing technology of your contact, there is no technology to implement object migration. RMI? CORBA? DCOM? Yes, you can't.

The key issue of object movement is to ensure reference integrity. We envision, if an object may be in any of the following or several states below. [A] Object references local objects. [B] Object reference remote object [C] object is local reference [D] object is a remote object, which is remotely referenced. Many such local or server-side objects constitute a very complex reference network. Obviously, after an object migrate, you need to solve the problem of reference migration, which is a very complex problem. However, there is Voyager, everything is simple. Voyager forwards references through special mechanisms to automatically replicate local reference objects to ensure reference integrity.

To achieve object migration, first create a level object from an object, and then you can achieve migration through the MoveTo method. This MoveTo method is overloaded. We only introduce one of one, more detailed. Please refer to Voyager's Manual. Program List 1:

Scenario: The object is constantly moving, however we can still be referenced by Voyager's reference.

//

// Project: MobileObject: MobileObject

// filename: Iball.java

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

//

// statement:

//

Public interface iball {

Public void hit ();

}

//

// Project: MobileObject: MobileObject

// filename: ball.java

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

//

// statement:

//

Import java.io. *;

Public Class Ball Implements Iball, Serializable {

Synchronized public void hit () {

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

}

}

//

// Project: MobileObject: MobileObject

// filename: Iball.java

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

//

// statement:

//

Import com.Objectspace.voyager. *;

Import com.Objectspace.voyager.mobility. *;

Public class bat {

Public void play (iball ball, string _url) {

Try {

Ball.hit ();

Mobility.of (ball) .Moveto (_URL);

} catch (mobiLityExcect e) {

System.out.pringln (e);

}

}

Public static void main (String [] args) {

Try {

Voyager.startup ("9000");

Classmanager.enableResourceserver ();

BAT ba = new ba ();

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

Bat.Play (Ball, "// OS1: 9000");

Bat.Play (Ball, "// OS2: 9000");

Bat.Play (Ball, "// OS3: 9000);

} catCH (Exception Exception) {

System.err.Pringln (Exception);

}

Voyager.shutdown ();

}

}

The above program needs to be explained:

[A] Since Voyager is based on Java technology, the sequential technology is used, the mobile object needs to implement the serializable interface.

In fact, if you want your mobile object to handle some other things during the entire process of migration, such as moving, movement, etc., your mobile object requires Imobile in addition to the SerializABE interface, these processes will be Sequential call. This is very like Applet.

5) Remote call

Synchronous and asynchronous concepts are a very important concept in Socket programming. Synchronization is the order execution, before the last task (function) call returns, the following task (function) is not performed, that is, the execution of the task is blocked. the way. Asynchronous and reverse, do not have to wait for the completion of the previous task, the following tasks are performed. In general, in practice, we need to solve the way asynchronous C / S programming, and this is not more than three: [A] When the service request comes, start a new thread to handle the task. [B] use the wheel Inquiries to handle tasks.

[C] callback. You can say this, three methods are asynchronous processing solutions.

In the end, we will analyze an instance of using multi-threaded and RMI to simulate and high performance computing.

Similarly, in the calculation of distributed objects, our ultimate goal can be said to be a method of calling, there is also a problem of synchronization and asynchronous. Of course, the three methods mentioned above can be used, but based on Voyager, we don't need To deal with these problems, we only need to divide the task into multiple methods, and then the static method of the Future class Invoke (Object, "Method", New Object [] {param-list ...}) can perform asynchronous Execute it. Where Object is the object where the method is located, the method is the method of executing, and param-list is a list of passed to the calling method.

Of course, this Invoke is suitable for local objects and remote objects.

There is no ready-made example here. It is worth reminding: Invoke returns a RESULT type object, you can use Isavailable () to detect whether to get the result, no other work. When the result is obtained, you can get the results via readint () or REDBYTE or readObject () or the like. You can also set the wait time, set the callback function, and so on with other overloaded INVOKE methods.

Renewed: 2. DCOM

3. CORBA

4. WebServices

5. Sun RMI vs. DOTNET Remoting

6. Linda and Sun Javaspace, IBM TSPACE

7. 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

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

New Post(0)