Search code examples
erlangjinterface

Can one monitor the mailbox Pid that represents a Java mailbox via JInterface?


I have a Java process that sends my erlang gen_server messages via JInterface. The message being sent to me includes the Pid of the mailbox created on the Java side. That Pid is valid in the sense that I can send messages back to that Pid, and those messages are successfully deposited in the Javan-side mailbox.

However doing a monitor(process, Pid) produces an instant nodedown message (noproc).

Is there a way to monitor this Pid?


Solution

  • Java (and C) nodes are different from Erlang nodes. They are hidden and they do not implement everything Erlang nodes do. In particular, they do not implement monitor support.

    This is documented with Erlang Distribution Protocol:

    11.7 New Ctrlmessages for distrvsn = 4 (OTP R6)

    These are only recognized by Erlang nodes, not by hidden nodes.

    MONITOR_P

    ...

    OTP implements a monitoring fallback mechanism for performing calls on (pseudo)-gen_servers on such nodes. The comment is enlightening:

        %% Node (C/Java?) is not supporting the monitor.
        %% The other possible case -- this node is not distributed
        %% -- should have been handled earlier.
        %% Do the best possible with monitor_node/2.
        %% This code may hang indefinitely if the Process 
        %% does not exist. It is only used for featureweak remote nodes.