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中打印。