领略分布式编程乐趣--[4]

博客提及领略分布式编程乐趣,还给出了作者邮箱、首次修改时间、个人文集及 WebLog 等信息,重点围绕分布式编程展开。
 


                     领略分布式编程乐趣

RedStar81 9/9/200313/9/2003
                                                                      
81_RedStar81@163.com
                                                                  TomHornson.student@www.sina.com.cn

首次修改时间:13/9/2003
            
个人文集:
http://www.csdn.net/develop/author/netauthor/RedStar81/
             WebLog: http://www.advogato.org/person/TomHornson/

 

   

2)访问远程对象

我们知道在RMI或是Remoting,使用分布式对象技术,你需要建立服务器端的远程对象,这个对象需要实现Remote接口并且继承于UnicastRemoteObject以获得分布式特性支持。而这一切在Voyager下变得简单了。Voyager在运行时生成一个类型兼容的代理,并且提供了几种方法做到这一点: a 创建一个本地对象,然后调用Proxy的静态方法Proxy.of(Object obj)来创建它的代理.  b 使用名字服务。Voyager提供名字服务功能。每个对象都可以通过将它们的名字服务登记到名字服务中,然后其它程序就可以通过Namespace.lookup(String Name)来得到这个对象的一个代理。 c 这个方法很有特色。在客户端你可以通过Factory.create(String classname,String url)在远程机器上建立对象,并且返回远程对象的代理。

下面我们就通过这几种方法实践一下Voyager环境下远程对象计算:

 

方法A示例:

程序片断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 implements 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 bat = new Bat();

    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);

}

 

}

}

上面的程序很简单,略知RMI或时Remoting,看起来一目了然,这里就不再讲解了.

 

 

程序片断二:下面是方法一复杂一点点的程序,这里客户端在调用远程对象的方法时,传递计算对象:

//

//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 implements 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 < dtEnd ; 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();  

}

}

上面需要注意的就是传递给远程对象方法的参数需要实Serializable接口.

 

 

待续:

 

2.    DCOM

3.    CORBA

4.       WebServices

5.         Sun RMI  VS. dotNET Remoting

6.         LindaSun JavaSpace ,IBM Tspace

7.         JINI

8.         Emerald VS. Dejay

9.         Pjama

10.     IBM Mobile Computing Interface : Aglets

.综合应用分析

1.       利用多线程和分布对象计算技术模拟高性能并行计算

2.       利用Vdejay计算几何分形图

 

 

  声明:

1。本人不是专门研究分布式的,完全出于兴趣写下这篇文章.希对分布式计算应用爱好者有所帮助。
2
。水平有限,欢迎指正。
3
。由于本文讲述内容较多,很多讲述不可能太细致。而且考虑到读者群的问题,理论性内容尽量的省略。
  
如果读者有兴趣,可参考列出的参考书籍和网络资源。

4。可任意的转载、不过请注明出处;不可用于商业用途。

 

【顶级EI完整复现】【DRCC】考虑N-1准则的分布鲁棒机会约束低碳经济调度(Matlab代码实现)内容概要:本文介绍了名为《【顶级EI完整复现】【DRCC】考虑N-1准则的分布鲁棒机会约束低碳经济调度(Matlab代码实现)》的技术资源,聚焦于电力系统中低碳经济调度问题,结合N-1安全准则与分布鲁棒机会约束(DRCC)方法,提升调度模型在不确定性环境下的鲁棒性和可行性。该资源提供了完整的Matlab代码实现,涵盖建模、优化求解及仿真分析全过程,适用于复杂电力系统调度场景的科研复现与算法验证。文中还列举了大量相关领域的研究主题与代码资源,涉及智能优化算法、机器学习、电力系统管理、路径规划等多个方向,展示了广泛的科研应用支持能力。; 适合人群:具备一定电力系统、优化理论和Matlab编程基础的研究生、科研人员及从事能源调度、智能电网相关工作的工程师。; 使用场景及目标:①复现高水平期刊(如EI/SCI)关于低碳经济调度的研究成果;②深入理解N-1安全约束与分布鲁棒优化在电力调度中的建模方法;③开展含新能源接入的电力系统不确定性优化研究;④为科研项目、论文撰写或工程应用提供可运行的算法原型和技术支撑。; 阅读建议:建议读者结合文档提供的网盘资源,下载完整代码与案例数据,按照目录顺序逐步学习,并重点理解DRCC建模思想与Matlab/YALMIP/CPLEX等工具的集成使用方式,同时可参考文中列出的同类研究方向拓展研究思路。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值