2

我如何拨打这样的电话:

order_cat(Pid, Name, Color, Desc) ->
    gen_server:call(Pid, {order, Name, Color, Desc}).

像这样:

handle_call({order, Name, Color, Desc}, _From, Cats) ->
    if Cats =:= [] ->
        {reply, make_cat(Name, Color, Desc), Cats};
       Cats =/= [] ->
        {reply, hd(Cats), tl(Cats)}
    end;
handle_call(terminate, _From, Cats) ->
    {stop, normal, ok, Cats}.

通过使用 java 和 Jinterface 而不是第一个代码?我知道如何使用 Jinterface 向 pid 发送消息,但是我有一个处理它的接收语句。我想改用 OTP,但我不明白如何。

4

1 回答 1

1

有两种方法可以通过 Jinterface 连接到您的 Erlang 代码:消息和 RPC。

RPC 记录在这里:http ://www.erlang.org/doc/apps/jinterface/jinterface_users_guide.html#id57655

请注意,使用消息不是“非 OTP”。如果你有一个 gen_server,你可以直接给它发消息,并在 handle_info 函数中接收消息。

于 2014-04-25T19:55:56.190 回答