CORBA + IDL + Java:需要编写servant的帮助

发布于 2024-10-05 16:22:11 字数 778 浏览 1 评论 0原文

我有一个定义的 idl 文件,如下所示:

module Banking {
    typedef string Transactions[5];
    typedef long AccountId;

    interface Account {
        exception InsufficientFunds {};

        readonly attribute double balance;
        long lodge(in double amount);
        long withdraw(in double amount) raises (InsufficientFunds);
        readonly attribute Transactions transactions;   
    };

    interface Bank {
        long accountCount();
        double totalMoney();
        Account account(in AccountId accNr);
    };
};

我用 idlj 编译该文件。我定义了一个 BankServant,客户端使用它与服务器进行通信,并且我有一个工作程序,几乎实现了所有方法。我唯一的问题是我不知道如何实现 account(in AccountId accNr) 方法,该方法又会返回正确的 Account 对象。由于我不了解 CORBA 并且我只是在帮助朋友,我想请求某种解决方案/示例/教程,这可能会帮助我破解一个简单但有效的类布局来处理这种情况。

先感谢您。

I have a defined idl file, which looks like this:

module Banking {
    typedef string Transactions[5];
    typedef long AccountId;

    interface Account {
        exception InsufficientFunds {};

        readonly attribute double balance;
        long lodge(in double amount);
        long withdraw(in double amount) raises (InsufficientFunds);
        readonly attribute Transactions transactions;   
    };

    interface Bank {
        long accountCount();
        double totalMoney();
        Account account(in AccountId accNr);
    };
};

which I compile with idlj. I have defined a BankServant, used by the client to communicate with the server and I have a working program with almost all methods implemented. My only problem is that I don't know how can I implement account(in AccountId accNr) method, which in turn will return the proper Account object. As I don't know CORBA and I am just helping a friend, I would like to ask for some kind of solutions / examples / tutorialis which may help me to hack a simple yet working class layout for dealing with that kind of situations.

Thank you in advance.

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

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

发布评论

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

评论(1

掩于岁月 2024-10-12 16:22:11

这实际上取决于您为 POA(可移植对象适配器)使用的策略。假设您在服务器中使用 RootPOA,则必须:

  1. 为 Account 对象创建一个实现对象。正如我在银行仆人的名称中看到的那样,这通常称为 AccountImplAccountServant

    AccountServant as = new AccountServant(accNr);

  2. 您必须在 POA 中注册该对象。这又与您为 POA 选择的政策有关。使用默认的根 POA:

    org.omg.CORBA.Object o = rootPOA.servant_to_reference( as );

  3. 使用 IDL 编译器将其缩小到正确的 Account 类型生成的AccountHelper:

    Account acc = AccountHelper.narrow(o);

  4. 返回

    return acc;

此代码假定您已为 AccountServant java 对象编写了构造函数接受帐号作为其第一个参数。您还必须向 BankServant 提供对要在其中注册新创建的 Account 对象的 POA 的引用。

有很多教程。例如,请参阅这个,因为 POA 的选项集非常多这需要一本书来解释它们:)。

It really depends on the policies you're using for the POA (the Portable Object Adapter). Assuming you're using the RootPOA in the server, you have to:

  1. Create an implementation object for the Account object. This is usually called AccountImpl or AccountServant as I see in the name of the bank servant.

    AccountServant as = new AccountServant(accNr);

  2. You have to register the object in the POA. This, again, has to do with the policies you've selected for your POA. using the default Root POA:

    org.omg.CORBA.Object o = rootPOA.servant_to_reference( as );

  3. Narrow it to the correct Account type using the IDL compiler generated AccountHelper:

    Account acc = AccountHelper.narrow(o);

  4. Return it

    return acc;

This code assumes you've written a constructor for the AccountServant java object that accepts the account number as its first argument. You have to provide the BankServant also with a reference to the POA in which you want to register the newly created Account objects.

There are lots of tutorials. See this one for example, as the set of options for the POA are so many that require a book to explain them all :).

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