Esempio n. 1
0
 @Override
 public OtpErlangObject call(
     final int timeout,
     final OtpErlangObject gleader,
     final String module,
     final String fun,
     final String signature,
     final Object... args0)
     throws RpcException {
   if (stopped) {
     return null;
   }
   tryConnect();
   OtpErlangObject result;
   try {
     result =
         rpcHelper.rpcCall(
             localNode,
             data.getNodeName(),
             false,
             gleader,
             module,
             fun,
             timeout,
             signature,
             args0);
   } catch (final SignatureException e) {
     throw new RpcException(e);
   }
   return result;
 }
Esempio n. 2
0
 private void tryConnect() throws RpcException {
   synchronized (connectLock) {
     switch (state) {
       case DISCONNECTED:
         reported = false;
         if (connectRetry()) {
           state = State.CONNECTED;
         } else if (connectOnce) {
           state = State.DOWN;
         } else {
           state = State.DISCONNECTED;
         }
         break;
       case CONNECTED:
         break;
       case DOWN:
         try {
           if (process != null) {
             process.terminate();
           }
         } catch (final DebugException e) {
           ErlLogger.info(e);
         }
         // TODO restart it??
         // process =
         if (!stopped) {
           final String msg = reportRuntimeDown(data.getNodeName());
           throw new RpcException(msg);
         }
     }
   }
 }
Esempio n. 3
0
 @Override
 public void send(final String name, final Object msg) {
   try {
     tryConnect();
     rpcHelper.send(localNode, data.getNodeName(), name, msg);
   } catch (final SignatureException e) {
   } catch (final RpcException e) {
   }
 }
Esempio n. 4
0
 public void startLocalNode() {
   boolean nodeCreated = false;
   synchronized (localNodeLock) {
     int i = 0;
     do {
       try {
         i++;
         localNode = ErlRuntime.createOtpNode(data.getCookie(), data.hasLongName());
         localNode.registerStatusHandler(statusWatcher);
         nodeCreated = true;
       } catch (final IOException e) {
         ErlLogger.error("ErlRuntime could not be created (%s), retrying %d", e.getMessage(), i);
         try {
           localNodeLock.wait(300);
         } catch (final InterruptedException e1) {
         }
       }
     } while (!nodeCreated && i < 10);
   }
 }
Esempio n. 5
0
  public ErlRuntime(
      final String name,
      final String cookie,
      final IProvider<IProcess> processProvider,
      final boolean reportWhenDown,
      final boolean longName,
      final boolean connectOnce) {
    state = State.DISCONNECTED;
    this.processProvider = processProvider;
    process = processProvider.get();
    this.connectOnce = connectOnce;
    stopped = false;
    data = new RuntimeData();
    data.setLongName(longName);
    data.setCookie(cookie);
    data.setNodeName(name);
    data.setReportErrors(reportWhenDown);

    statusWatcher =
        new OtpNodeStatus() {
          @Override
          public void remoteStatus(final String node, final boolean up, final Object info) {
            if (node.equals(data.getNodeName())) {
              if (up) {
                ErlLogger.debug("Node %s is up", data.getNodeName());
                connectRetry();
              } else {
                ErlLogger.debug("Node %s is down: %s", data.getNodeName(), info);
                state = State.DOWN;
              }
            }
          }
        };
    startLocalNode();
    // if (epmdWatcher.isRunningNode(name)) {
    // connect();
    // }
  }
Esempio n. 6
0
 @Override
 public void cast(
     final OtpErlangObject gleader,
     final String module,
     final String fun,
     final String signature,
     final Object... args0)
     throws RpcException {
   tryConnect();
   try {
     rpcHelper.rpcCast(
         localNode, data.getNodeName(), false, gleader, module, fun, signature, args0);
   } catch (final SignatureException e) {
     throw new RpcException(e);
   }
 }
Esempio n. 7
0
 @Override
 public void async_call_result(
     final IRpcResultCallback cb,
     final String m,
     final String f,
     final String signature,
     final Object... args)
     throws RpcException {
   final OtpErlangAtom gleader = new OtpErlangAtom("user");
   try {
     rpcHelper.rpcCastWithProgress(
         cb, localNode, data.getNodeName(), false, gleader, m, f, signature, args);
   } catch (final SignatureException e) {
     throw new RpcException(e);
   }
 }
Esempio n. 8
0
 @Override
 public void async_call_cb(
     final IRpcCallback cb,
     final int timeout,
     final OtpErlangObject gleader,
     final String module,
     final String fun,
     final String signature,
     final Object... args)
     throws RpcException {
   tryConnect();
   try {
     rpcHelper.makeAsyncCbCall(
         localNode, data.getNodeName(), cb, timeout, gleader, module, fun, signature, args);
   } catch (final SignatureException e) {
     throw new RpcException(e);
   }
 }
Esempio n. 9
0
  private String reportRuntimeDown(final String peer) {
    final String fmt = "Backend '%s' is down";
    final String msg = String.format(fmt, peer);
    if (data.getReportErrors() && !reported) {
      final String user = System.getProperty("user.name");

      String msg1;
      if (connectOnce) {
        msg1 =
            "It is likely that your network is misconfigured or uses 'strange' host names.\n"
                + "Please check the "
                + "Window->preferences->erlang->network page for hints about that."
                + "\n\n"
                + "Also, check if you can create and connect two erlang nodes on your machine\n"
                + "using \"erl -name foo1\" and \"erl -name foo2\".";
      } else {
        msg1 =
            "If you didn't shut it down on purpose, it is an "
                + "unrecoverable error, please restart Eclipse. ";
      }

      final String bigMsg =
          msg
              + "\n\n"
              + msg1
              + "\n\n"
              + "If an error report named '"
              + user
              + "_<timestamp>.txt' has been created in your home directory,\n "
              + "please consider reporting the problem. \n"
              + (SystemConfiguration.hasFeatureEnabled("erlide.ericsson.user")
                  ? ""
                  : "http://www.assembla.com/spaces/erlide/support/tickets");
      MessageReporter.showError(bigMsg, ReporterPosition.CORNER);
      reported = true;
    }
    return msg;
  }
Esempio n. 10
0
 @Override
 public RuntimeInfo getRuntimeInfo() {
   return data.getRuntimeInfo();
 }
Esempio n. 11
0
 @Override
 public String getNodeName() {
   return data.getNodeName();
 }