在不同远程对象之间拆分远程 EJB 功能

发布于 2024-10-19 20:22:17 字数 1144 浏览 6 评论 0原文

我正在开发一个遗留系统,其中有一个远程 bean 变得太大且单一,我想将需要添加的新功能分开。

我最初的想法是,不要将新方法添加到现有接口中,而是使用我的所有内容创建一个新接口,并添加一个返回实现我的接口的远程对象的方法。

我现在面临的问题是,当我调用返回对象的方法时,运行时尝试序列化它而不是发送存根。

代码布局或多或少像这样:

@Stateless
public class OldBean implements OldRemoteInterface {
   //lots of the old unrelated methods here

   public MyNewStuff getMyNewStuff() {
      return new MyNewStuff();
   }
}

@Remote
public interface OldRemoteInterface {
   //lots of the old unrelated methods declared here

   MyNewStuff getMyNewStuff();
}

public class MyNewStuff implements NewRemoteInterface {
   //methods implemented here
}

@Remote
public interface NewRemoteInterface {
   //new methods declared here
}

我得到的例外是:

"IOP00810267: (MARSHAL) An instance of class MyNewStuff could not be marshalled:
the class is not an instance of java.io.Serializable"

我尝试以“旧方式”进行操作,扩展 java.rmi.Remote 接口而不是使用 ejb @Remote 注释,我得到的异常是:

"IOP00511403: (INV_OBJREF) Class MyNewStuff not exported, or else is actually 
a JRMP stub"

我知道我一定遗漏了一些应该显而易见的东西......:-/

I am working on a legacy system, where there is a remote bean that has become too big and monolithic, and I would like to keep separate the new functionality I that need to add.

My initial idea was, instead of adding my new methods to the existing interface, create a new interface with all my stuff and add a single method that returns a remote object implementing my interface.

The problem I am facing now is that when I'm invoking the method that returns my object, the runtime tries to serialize it instead of sending the stub.

The code layout is more or less like this:

@Stateless
public class OldBean implements OldRemoteInterface {
   //lots of the old unrelated methods here

   public MyNewStuff getMyNewStuff() {
      return new MyNewStuff();
   }
}

@Remote
public interface OldRemoteInterface {
   //lots of the old unrelated methods declared here

   MyNewStuff getMyNewStuff();
}

public class MyNewStuff implements NewRemoteInterface {
   //methods implemented here
}

@Remote
public interface NewRemoteInterface {
   //new methods declared here
}

And the exception I am getting is:

"IOP00810267: (MARSHAL) An instance of class MyNewStuff could not be marshalled:
the class is not an instance of java.io.Serializable"

I have tried to do it "the old way", extending the java.rmi.Remote interface instead of using the ejb @Remote annotation, and the exception I get is:

"IOP00511403: (INV_OBJREF) Class MyNewStuff not exported, or else is actually 
a JRMP stub"

I know I must be missing something that should be obvious... :-/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风吹过旳痕迹 2024-10-26 20:22:17

你在这里的方法有点令人困惑。当您创建新接口时,下一步应该是让旧 bean 实现新接口,如下所示:

public class OldBean implements OldRemoteInterface, NewRemoteInterface {

您的旧 bean 会变得更大,是的,但这是扩展旧 bean 功能的唯一方法无需创建新的 bean 或接触旧的界面。

getNewStuff() 返回的对象只是一个普通对象——它不是远程的。这就是您收到序列化错误的原因,因为 RMI 正在尝试通过网络传输您的 NewRemoteInterface 实例。使用 @Remote 注释它不会执行任何操作(直到您实际在 bean 上使用该接口、部署该 bean,然后使用 DI 或 Context 检索它)

your approach here is a bit confusing. when you created the new interface, the next step should have been to have the old bean implement the new interface, like so:

public class OldBean implements OldRemoteInterface, NewRemoteInterface {

Your old bean would get larger, yes, but this is the only way you can expand the functionality of your old bean without creating a new bean or touching the old interface.

The object being returned by getNewStuff() is just a plain object -- it is not remote. That's why you're getting serialization errors, because RMI is trying to transfer your NewRemoteInterface instance across the network. Annotating it with @Remote doesn't do anything (until you actually use the interface on a bean, deploy that bean and then retrieve it using DI or Contexts)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文