Search in sources :

Example 1 with OtpErlangExit

use of com.ericsson.otp.erlang.OtpErlangExit in project erlide_eclipse by erlang.

the class OtpRpc method getRpcResult.

/**
 * Retrieve the result of a RPC.
 *
 * @param mbox
 * @param timeout
 * @param env
 * @return
 * @throws RpcException
 */
@Override
public OtpErlangObject getRpcResult(final OtpMbox mbox, final long timeout, final String env) throws RpcException {
    assert mbox != null;
    OtpErlangObject res = null;
    try {
        try {
            if (timeout == OtpRpc.INFINITY) {
                res = mbox.receive();
            } else {
                res = mbox.receive(timeout);
            }
            if (OtpRpc.CHECK_RPC) {
                ErlLogger.debug("RPC " + mbox.hashCode() + "<= " + res);
            }
        } finally {
            if (res != null) {
                mbox.close();
            }
        }
        if (res == null) {
            final String msg = env != null ? env : "??";
            throw new RpcTimeoutException(msg);
        }
        if (!(res instanceof OtpErlangTuple)) {
            throw new RpcException(res.toString());
        }
        final OtpErlangTuple t = (OtpErlangTuple) res;
        if (t.arity() != 2) {
            throw new RpcException(res.toString());
        }
        res = t.elementAt(1);
    } catch (final OtpErlangExit e) {
        throw new RpcException(e);
    } catch (final OtpErlangDecodeException e) {
        throw new RpcException(e);
    }
    return res;
}
Also used : OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) RpcException(org.erlide.runtime.rpc.RpcException) OtpErlangDecodeException(com.ericsson.otp.erlang.OtpErlangDecodeException) OtpErlangExit(com.ericsson.otp.erlang.OtpErlangExit) RpcTimeoutException(org.erlide.runtime.rpc.RpcTimeoutException) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple)

Example 2 with OtpErlangExit

use of com.ericsson.otp.erlang.OtpErlangExit in project erlide_eclipse by erlang.

the class OtpNodeProxy method receiveEventMessage.

private void receiveEventMessage(final OtpMbox eventBox) throws OtpErlangExit {
    OtpErlangObject msg = null;
    try {
        msg = eventBox.receive(OtpNodeProxy.POLL_INTERVAL);
        final ErlEvent busEvent = eventHelper.parse(msg, this);
        if (busEvent != null) {
            if (OtpNodeProxy.DEBUG) {
                ErlLogger.debug("MSG: %s", "[" + busEvent.getSender() + "::" + busEvent.getTopic() + ": " + busEvent.getEvent() + "]");
            }
            eventBus.post(busEvent);
        }
    } catch (final OtpErlangExit e) {
        ErlLogger.error(e);
        throw e;
    } catch (final OtpErlangDecodeException e) {
        ErlLogger.error(e);
    }
}
Also used : OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangDecodeException(com.ericsson.otp.erlang.OtpErlangDecodeException) OtpErlangExit(com.ericsson.otp.erlang.OtpErlangExit) ErlEvent(org.erlide.runtime.events.ErlEvent)

Aggregations

OtpErlangDecodeException (com.ericsson.otp.erlang.OtpErlangDecodeException)2 OtpErlangExit (com.ericsson.otp.erlang.OtpErlangExit)2 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)2 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)1 ErlEvent (org.erlide.runtime.events.ErlEvent)1 RpcException (org.erlide.runtime.rpc.RpcException)1 RpcTimeoutException (org.erlide.runtime.rpc.RpcTimeoutException)1