走自己的路

路漫漫其修远兮,吾将上下而求索

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  50 随笔 :: 4 文章 :: 118 评论 :: 0 Trackbacks
 
  1. 远程对象是cache在本地的singleton引用(允许初始化多次),如果是null就重新lookup一把,强调的是出现异常后,需要将远程对象的引用置为null,这样一旦rmi server重启,rmi client会重新lookup新的远程对象,自动恢复。

      protected RemotableMessageReceiver getRemoteMessageReceiver()

                  throws MIFReceiverException {

            if (this.messageReceiver != null) {

                  return this.messageReceiver;

            }

 

            try {

                  Registry registry = LocateRegistry.getRegistry(rmiHost, rmiPort);

                  this.messageReceiver = (RemotableMessageReceiver) registry

                              .lookup(this.serviceName);

            } catch (Exception ex) {

                  throw new MIFReceiverException(

                              "look up remote message receiver failed!", this, ex);

            }

 

            return this.messageReceiver;

      }

 

      public void invokeProcessFlow(String processId) throws MIFReceiverException {

            try {

                  RemotableMessageReceiver messageReceiver = getRemoteMessageReceiver();

                  messageReceiver.invokeProcessFlow(processId);

            } catch (RemoteException e) {

                  this.messageReceiver = null;

                  throw new MIFReceiverException("invoke process: " + processId

                              + " fails, encounter error: " + e.getMessage(), this, e);

            }

      }

 

 

  1. 如果RMI registry是命令行启动的,可以重用,但如果standalone的rmiregistry被关闭了,所有application都需要重启,代价也很大。
  2. 一旦RMI registry是由某个application jvm启的,在不同application team之间最好就不要重用。重用别的jvmrmi registry会出现这样一个情况,jvm A重启了,jvmB就不能再lookupbind的远程对象,当然jvmBjvmA重启之前已经lookup出来的远程对象还是可以正常使用的,jvmB重启也可以恢复正常,但这样jvmB就会依赖于jvmA,因为它们存在rmi registry的依赖关系。所以通过JVMrmi registry,觉得还是要强行create新的registry,不重用已有的,如果端口被占用就抛异常,让application用户换端口,这样比较安全,一旦重用还是会担心出现第二个问题。


posted on 2009-05-05 15:29 叱咤红人 阅读(1455) 评论(2)  编辑  收藏 所属分类: JDBC JNDI JMS RMI EJB and Other J2EE Tech

评论

# re: RMI使用的注意点 2009-05-05 23:57 web tasarımı
RemotableMessageReceiver messageReceiver = getRemoteMessageReceiver();

messageReceiver.invokeProcessFlow(processId);

} catch (RemoteException e) {

this.messageReceiver = null;

throw new MIFReceiverException("invoke process: " + processId

+ " fails, encounter error: " + e.getMessage(), this, e);

}

}  回复  更多评论
  

# re: RMI使用的注意点 2009-05-05 23:58 yuz estetigi
} catch (Exception ex) {

throw new MIFReceiverException(

"look up remote message receiver failed!",  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: