Ejemplo n.º 1
0
  @Override
  protected OtpErlangObject handleCall(OtpErlangObject cmd, OtpErlangTuple from)
      throws OtpStopException, OtpContinueException, OtpErlangException {

    OtpErlangTuple cmdTuple = (OtpErlangTuple) cmd;
    OtpErlangAtom cmdName = (OtpErlangAtom) cmdTuple.elementAt(0);
    if (cmdName.atomValue().equals("pid")) { // {pid}
      return super.getSelf();

    } else if (cmdName.atomValue().equals("match")) {
      // {match, Query :: string(), PageSize :: integer()}
      String queryString = ((OtpErlangString) cmdTuple.elementAt(1)).stringValue();
      int pageSize = ((OtpErlangLong) cmdTuple.elementAt(2)).intValue();
      OtpErlangObject[] sortFieldNames = ((OtpErlangList) cmdTuple.elementAt(3)).elements();
      SortField[] sortFields = new SortField[sortFieldNames.length];
      for (int i = 0; i < sortFields.length; i++) {
        sortFields[i] = this.translator.createSortField((OtpErlangAtom) sortFieldNames[i]);
      }
      runMatch(queryString, pageSize, sortFields, from);
      throw new OtpContinueException();

    } else if (cmdName.atomValue().equals("continue")) {
      // {continue, Token :: binary(), PageSize :: integer()}
      Object pageToken = ((OtpErlangBinary) cmdTuple.elementAt(1)).getObject();
      int pageSize = ((OtpErlangLong) cmdTuple.elementAt(2)).intValue();
      runContinue(pageToken, pageSize, from);
      throw new OtpContinueException();

    } else {
      return new OtpErlangTuple(
          new OtpErlangObject[] {new OtpErlangAtom("error"), new OtpErlangAtom("unknown command")});
    }
  }
Ejemplo n.º 2
0
    public boolean handleEvent(final OtpErlangObject msg) {
      notifier.checkCancel();

      ErlLogger.debug(">>> %s", msg);
      if (msg instanceof OtpErlangTuple) {
        try {
          final OtpErlangTuple tuple = (OtpErlangTuple) msg;
          final OtpErlangAtom akey = (OtpErlangAtom) tuple.elementAt(0);
          final String key = akey.atomValue();
          // final OtpErlangObject value = tuple.elementAt(1);

          if ("compile".equals(key)) {
            // value = {ok, Messages, Files} | {error, Messages}
            // TODO create markers for messages
            // TODO refresh Files and mark as derived
          }
          if ("tasks".equals(key)) {
            // value = [Task]
            // TODO create tasks for Tasks
          }
          if ("clash".equals(key)) {
            // value = [Clash]
            // TODO create markers for clashes
          }
        } catch (final Exception e) {
          // ignore?
        }
      }
      return msg.equals(new OtpErlangAtom("stop"));
    }
Ejemplo n.º 3
0
  private String parse(OtpErlangObject otpObj) {
    if (otpObj instanceof OtpErlangAtom) {
      OtpErlangAtom atom = (OtpErlangAtom) otpObj;
      if (atom.atomValue().equals("null")) return null;
      else throw new IllegalArgumentException("Only atom null is supported");

    } else if (otpObj instanceof OtpErlangString) {
      OtpErlangString str = (OtpErlangString) otpObj;
      return str.stringValue();
    }
    throw new IllegalArgumentException("Unexpected type " + otpObj.getClass().getName());
  }
Ejemplo n.º 4
0
 public List<IStackFrame> getStackFrames(final IDebugTarget target, final IThread process) {
   // XXX JC copy paste
   final OtpErlangTuple tuple = getTuple();
   final OtpErlangList erlStackFrames = (OtpErlangList) tuple.elementAt(2);
   final OtpErlangTuple t2 = (OtpErlangTuple) tuple.elementAt(1);
   final OtpErlangTuple ieval = (OtpErlangTuple) t2.elementAt(0);
   OtpErlangAtom m = (OtpErlangAtom) ieval.elementAt(3);
   OtpErlangList bindings = (OtpErlangList) t2.elementAt(t2.arity() - 1);
   OtpErlangLong l = (OtpErlangLong) ieval.elementAt(1);
   final List<IStackFrame> stackFrames = new ArrayList<IStackFrame>(erlStackFrames.arity() + 1);
   for (final OtpErlangObject o : erlStackFrames) {
     final OtpErlangTuple t = (OtpErlangTuple) o;
     final OtpErlangTuple ml = (OtpErlangTuple) t.elementAt(1);
     final OtpErlangObject ml0 = ml.elementAt(0);
     int stackFrameNo;
     final OtpErlangLong n = (OtpErlangLong) t.elementAt(3);
     try {
       stackFrameNo = n.intValue();
     } catch (final OtpErlangRangeException e) {
       stackFrameNo = -1;
     }
     final String module = m.atomValue();
     int line;
     try {
       line = l.intValue();
     } catch (final OtpErlangRangeException e) {
       line = -1;
     }
     final IStackFrame sf =
         new ErlangStackFrame(
             module, (ErlangProcess) process, target, line, null, bindings, stackFrameNo);
     stackFrames.add(sf);
     bindings = (OtpErlangList) t.elementAt(2);
     m = (OtpErlangAtom) ml0;
     l = (OtpErlangLong) ml.elementAt(1);
   }
   return stackFrames;
 }