windchill开发之远程方法调用

windchill开发之远程方法调用

来源:原创 作者:云淡天晴 时间:2008-10-19 
       在windchill的开发过程中不可避免要用到RMI远程方法调用,什么是远程方法调用,可以查看java中的基本概念。在windchill开发过程中,

原理与以前在java中的一样,但是方法却有说区别。在windchill中被调用的方法运行在MethodServer端,如果有输出可以在MethodServer

中看到。

    在什么样的情况下用到远程方法调用呢?通常在windchill中创建对象,修改对象,删除对象的时候我们必须用RMI,在查询对象过程中有可能

会用到RMI,如果不知道什么时候用,也不要紧,代码出错会有非常明显的提示。注意在工作流中调用的时候不需要再用RMI,因为工作流本来就

是运行在服务器端。举一RMI例子。

  import java.lang.reflect.InvocationTargetException;
import java.rmi.RemoteException;
import wt.method.RemoteMethodServer;

public class Demo5  implements wt.method.RemoteAccess
{

 /**
  * 代码比较简单,这里就不做详细注释了
  * @param args
  * @throws InvocationTargetException
  * @throws RemoteException
  */
 public static void main(String[] args) throws RemoteException, InvocationTargetException
 {
  // TODO Auto-generated method stub
  RemoteMethod("这里是可以探讨java基础与windchill 9 的地方");
 }

 public static void RemoteMethod(String msg) throws RemoteException,
   InvocationTargetException
 {
  String CLASSNAME = (Demo5.class).getName();
  Class argTypes[];
  Object svrArgs[];
  argTypes = (new Class[]
  { String.class});
  svrArgs = (new Object[]
  { msg});
  RemoteMethodServer.getDefault().invoke("pirntMsg", CLASSNAME, null, argTypes, svrArgs);
 }
 
 public static void  pirntMsg(String msg)
 {
  System.out.println(msg);
 }
}

注意:代码必须实现wt.method.RemoteAccess接口

将编译后的Demo5.class放置在codebase文件夹下,在windchill shell中运行命令:windchill Demo5

结果将在MethodServer端出现,而不是在windchill shell中打印。

发布了24 篇原创文章 · 获赞 4 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/wangxiaomei2008/article/details/4990963
今日推荐