Package com.ericsson.otp.erlang

Examples of com.ericsson.otp.erlang.OtpNode


@SuppressWarnings("all")
public class LocalNodeCreator {
  public static OtpNode createOtpNode(final String cookie, final boolean longName) {
    try {
      OtpNode _xblockexpression = null;
      {
        final String hostName = HostnameUtils.getErlangHostName(longName);
        OtpNode _xifexpression = null;
        boolean _isNullOrEmpty = Strings.isNullOrEmpty(cookie);
        if (_isNullOrEmpty) {
          String _create = NodeNameCreator.create(hostName);
          _xifexpression = new OtpNode(_create);
        } else {
          String _create_1 = NodeNameCreator.create(hostName);
          _xifexpression = new OtpNode(_create_1, cookie);
        }
        _xblockexpression = _xifexpression;
      }
      return _xblockexpression;
    } catch (Throwable _e) {
View Full Code Here


      throw Exceptions.sneakyThrow(_e);
    }
  }
 
  public static OtpNode startLocalNode(final OtpNodeProxy nodeProxy, final String cookie, final boolean hasLongName) {
    OtpNode _createOtpNode = LocalNodeCreator.createOtpNode(cookie, hasLongName);
    return LocalNodeCreator.startLocalNode(nodeProxy, _createOtpNode);
  }
View Full Code Here

    if (self == null)
    {
      // Based on
      // http://erlang.org/pipermail/erlang-questions/2010-March/050226.html
      try {
        self = new OtpNode(ourNode, cookie);
      } catch (IOException e) {
        e.printStackTrace();
        // if we are here, node remains null.
      }
    }
View Full Code Here

          if (ErlangRunner.validName(f.getName()))
            ErlangRunner.compileErl(f, null, true);

        // Based on
        // http://erlang.org/pipermail/erlang-questions/2010-March/050226.html
        OtpNode self = new OtpNode(ourNode, uniqueID); // identify self
        thisMbox = self.createMbox("thisMbox");

        // Now build environment variables to ensure that dialyzer will
        // find a directory to put its plt file in.
        // This is actually a dialyzer bug which manifests itself on
        // Windows -
        // there is no need for dialyzer_options:build(Opts) to call
        // dialyzer_plt:get_default_plt()
        // before build_options(Opts, DefaultOpts1).
        List<String> envpList = new LinkedList<String>();
       
        Map<String,String> newValues = new TreeMap<String,String>();
        newValues.put("HOME",new File(GlobalConfiguration.getConfiguration().getProperty(G_PROPERTIES.PATH_ERLANGBEAM)).getAbsolutePath());
        newValues.put("ERL_MAX_PORTS","1024");// to limit the size of each Erlang instance to a few meg from a few hundred meg

        for (Entry<String, String> entry : System.getenv().entrySet())
          if (!newValues.containsKey(entry.getKey()))
            envpList.add(entry.getKey() + "=" + entry.getValue());
       
        for(Entry<String, String> entry : newValues.entrySet())
          envpList.add(entry.getKey() + "=" + entry.getValue());

        erlangProcess = Runtime
            .getRuntime()
            .exec(new String[] {
                ErlangRunner.getErlangBin() + "erl",
                "-pa",getErlangBeamDirectory().getAbsolutePath(),
                // the easiest way to substitute our module in place
                // of the original Erlang's one, otherwise I'd
                // have to rely on tracerunner:compileAndLoad
                "-run", "tracerunner", "start", ourNode,
                runnerMode, "-sname", traceRunnerNode,
                "-noshell", "-setcookie", uniqueID },
                envpList.toArray(new String[0]));
                //getErlangBeamDirectory());
        stdDumper = new Thread(new Runnable() {

          @Override
          public void run() {
            ExperimentRunner.dumpStreams(erlangProcess,
                timeBetweenChecks, new HandleProcessIO() {

                  @Override
                  public void OnHeartBeat() {
                    // no prodding is done - we are
                    // being prodded by Erlang instead.
                  }

                  @Override
                  public void StdErr(StringBuffer b) {
                    if (displayErlangOutput)
                      System.out.print("[ERLANG] "
                          + b.toString());
                  }

                  @Override
                  public void StdOut(StringBuffer b) {
                    if (displayErlangOutput)
                      System.out.print("[ERLERR] "
                          + b.toString());
                  }
                });
          }
        });
        stdDumper.setDaemon(true);
        stdDumper.start();
        if (delay > 0)
          Thread.sleep(delay);
        // At this point, the process may have not yet started or
        // already terminated, it is easy to find out which of the
        // two has happened by doing
        int timeout = serverTimeout;
        while (!self.ping(traceRunnerNode, 500) && timeout > 0) {
          try {
            erlangProcess.exitValue();
            // process terminated, record this as a failure
            timeout = 0;
          } catch (IllegalThreadStateException e) {
            // process not yet terminated, hence we keep waiting
            --timeout;
          }
        }
        ourBox = new OtpErlangTuple(new OtpErlangObject[] {
            thisMbox.self(), self.createRef() });
        if (timeout <= 0) {
          final long endTime = System.currentTimeMillis();
          throw new IllegalArgumentException(
              "timeout waiting for a server to start after "
                  + (endTime - startTime) + "ms");
View Full Code Here

                for (File f : new File(ErlangQSMOracle.ErlangTyper).listFiles())
                    if (ErlangRunner.validName(f.getName()))
                        ErlangRunner.compileErl(f,null);

                // Based on http://erlang.org/pipermail/erlang-questions/2010-March/050226.html
                OtpNode self = new OtpNode(ourNode, uniqueID); // identify self
                thisMbox = self.createMbox("thisMbox");
               
                // Now build environment variables to ensure that dialyzer will find a directory to put its plt file in.
                // This is actually an bug of dialyzer which manifests itself on Windows -
                // there is no need for dialyzer_options:build(Opts) to call dialyzer_plt:get_default_plt()
                // before build_options(Opts, DefaultOpts1).
              List<String> envpList = new LinkedList<String>();
              for(Entry<String,String> entry:System.getenv().entrySet())
                if (!entry.getKey().equals("HOME"))
                  envpList.add(entry.getKey()+"="+entry.getValue());
              envpList.add("HOME="+new File(ErlangQSMOracle.ErlangFolder).getAbsolutePath());
              
                erlangProcess = Runtime.getRuntime().exec(new String[]{ErlangRunner.getErlangBin() + "erl",
                    "-pa",new File(ErlangQSMOracle.ErlangFolder).getAbsolutePath(),
                    "-pa",new File(ErlangQSMOracle.ErlangTyper).getAbsolutePath(),// the easiest way to substitute our module in place of the original Erlang's one, otherwise I'd have to rely on tracerunner:compileAndLoad
                    "-run","tracerunner","start",ourNode,runnerMode,"-sname",traceRunnerNode,"-noshell","-setcookie",uniqueID}, envpList.toArray(new String[0]), new File(ErlangQSMOracle.ErlangFolder));
                stdDumper = new Thread(new Runnable() {
         
          @Override
          public void run() {
                 ExperimentRunner.dumpStreams(erlangProcess, timeBetweenChecks, new HandleProcessIO() {

                      @Override
                      public void OnHeartBeat() {// no prodding is done - we are being prodded by Erlang instead.
                      }

                      @Override
                      public void StdErr(StringBuffer b) {
                          System.out.print("[ERLANG] "+b.toString());
                      }

                      @Override
                      public void StdOut(StringBuffer b) {
                          System.out.print("[ERLERR] "+b.toString());
                      }
                  });
          }
        });
                stdDumper.setDaemon(true);stdDumper.start();
                if (delay > 0) Thread.sleep(delay);
                // At this point, the process may have not yet started or already terminated, it is easy to find out which of the
                // two has happened by doing
                int timeout = serverTimeout;
                while(!self.ping(traceRunnerNode, 500) && timeout > 0)
                {
                  try
                  {
                    erlangProcess.exitValue();
                    // process terminated, record this as a failure
                    timeout = 0;
                  }
                  catch(IllegalThreadStateException e)
                  {// process not yet terminated, hence we keep waiting
                    --timeout;
                  }
                }
                ourBox = new OtpErlangTuple(new OtpErlangObject[]{thisMbox.self(),self.createRef()});
                if (timeout <= 0) throw new IllegalArgumentException("timeout waiting for a server to start");
            }
      }
      catch(IOException e)
      {
View Full Code Here

          if (ErlangRunner.validName(f.getName()))
            ErlangRunner.compileErl(f, null);

        // Based on
        // http://erlang.org/pipermail/erlang-questions/2010-March/050226.html
        OtpNode self = new OtpNode(ourNode, uniqueID); // identify self
        thisMbox = self.createMbox("thisMbox");

        // Now build environment variables to ensure that dialyzer will
        // find a directory to put its plt file in.
        // This is actually a dialyzer bug which manifests itself on
        // Windows -
        // there is no need for dialyzer_options:build(Opts) to call
        // dialyzer_plt:get_default_plt()
        // before build_options(Opts, DefaultOpts1).
        List<String> envpList = new LinkedList<String>();
       
        Map<String,String> newValues = new TreeMap<String,String>();
        newValues.put("HOME",new File(ErlangQSMOracle.ErlangFolder).getAbsolutePath());
        newValues.put("ERL_MAX_PORTS","1024");// to limit the size of each Erlang instance to a few meg from a few hundred meg

        for (Entry<String, String> entry : System.getenv().entrySet())
          if (!newValues.containsKey(entry.getKey()))
            envpList.add(entry.getKey() + "=" + entry.getValue());
       
        for(Entry<String, String> entry : newValues.entrySet())
          envpList.add(entry.getKey() + "=" + entry.getValue());

        erlangProcess = Runtime
            .getRuntime()
            .exec(new String[] {
                ErlangRunner.getErlangBin() + "erl",
                "-pa",
                new File(ErlangQSMOracle.ErlangFolder).getAbsolutePath(),
                "-pa",
                new File(ErlangQSMOracle.ErlangTyper).getAbsolutePath(),
                // the easiest way to substitute our module in place
                // of the original Erlang's one, otherwise I'd
                // have to rely on tracerunner:compileAndLoad
                "-run", "tracerunner", "start", ourNode,
                runnerMode, "-sname", traceRunnerNode,
                "-noshell", "-setcookie", uniqueID },
                envpList.toArray(new String[0]),
                new File(ErlangQSMOracle.ErlangFolder));
        stdDumper = new Thread(new Runnable() {

          @Override
          public void run() {
            ExperimentRunner.dumpStreams(erlangProcess,
                timeBetweenChecks, new HandleProcessIO() {

                  @Override
                  public void OnHeartBeat() {
                    // no prodding is done - we are
                    // being prodded by Erlang instead.
                  }

                  @Override
                  public void StdErr(StringBuffer b) {
                    if (displayErlangOutput)
                      System.out.print("[ERLANG] "
                          + b.toString());
                  }

                  @Override
                  public void StdOut(StringBuffer b) {
                    if (displayErlangOutput)
                      System.out.print("[ERLERR] "
                          + b.toString());
                  }
                });
          }
        });
        stdDumper.setDaemon(true);
        stdDumper.start();
        if (delay > 0)
          Thread.sleep(delay);
        // At this point, the process may have not yet started or
        // already terminated, it is easy to find out which of the
        // two has happened by doing
        int timeout = serverTimeout;
        while (!self.ping(traceRunnerNode, 500) && timeout > 0) {
          try {
            erlangProcess.exitValue();
            // process terminated, record this as a failure
            timeout = 0;
          } catch (IllegalThreadStateException e) {
            // process not yet terminated, hence we keep waiting
            --timeout;
          }
        }
        ourBox = new OtpErlangTuple(new OtpErlangObject[] {
            thisMbox.self(), self.createRef() });
        if (timeout <= 0) {
          final long endTime = System.currentTimeMillis();
          throw new IllegalArgumentException(
              "timeout waiting for a server to start after "
                  + (endTime - startTime) + "ms");
View Full Code Here

      cookieModuleReference = component.getCookieModuleReference();
      invalidCookieModuleReference = component
          .getInvalidCookieModuleReference();
      timeoutModuleReference = component.getTimeoutModuleReference();

      serNode = new OtpNode("MboxServer");
      serMbox = serNode.createMbox("sendArgs");
      refNode = new OtpNode("MboxClient");
      refMbox = refNode.createMbox("connector_to_SCA_mbox");
    } catch (IOException e) {
      System.out.println("Problem executing " + EPMD_COMMAND + ": "
          + e.getLocalizedMessage() + ". Tests will be IGNORED.");
    }
View Full Code Here

        + System.currentTimeMillis();
  }

  private Message sendMessage(Message msg) {
    OtpMbox tmpMbox = null;
    OtpNode node = null;
    try {
      node = new OtpNode(getClientNodeName());
      if (binding.hasCookie()) {
        node.setCookie(binding.getCookie());
      }
      tmpMbox = node.createMbox();
      // obtain args, make sure they aren't null
      // NOTE: sending message with no content (but only with senders PID)
      // is possible
      Object[] args = (Object[]) (msg.getBody() != null ? msg.getBody()
          : new Object[0]);
      Method jmethod = ((JavaOperation) msg.getOperation())
          .getJavaMethod();
      // create and send msg with self pid in the beginning
      OtpErlangObject[] argsArray = {
          tmpMbox.self(),
          TypeHelpersProxy.toErlang(args, jmethod
              .getParameterAnnotations()) };
      OtpErlangObject otpArgs = new OtpErlangTuple(argsArray);
      tmpMbox.send(msg.getOperation().getName(), binding.getNode(),
          otpArgs);
      if (msg.getOperation().getOutputType() != null) {
        OtpMsg resultMsg = null;
        if (binding.hasTimeout()) {
          resultMsg = tmpMbox.receiveMsg(binding.getTimeout());
        } else {
          resultMsg = tmpMbox.receiveMsg();
        }
        OtpErlangObject result = resultMsg.getMsg();
        msg.setBody(TypeHelpersProxy.toJava(result, msg.getOperation()
            .getOutputType().getPhysical(), jmethod
            .getAnnotations()));
      }
    } catch (InterruptedException e) {
      // TODO: externalize message?
      ErlangException ee = new ErlangException(
          "Timeout while receiving message reply", e);
      msg.setBody(null);
      reportProblem(msg, ee);
    } catch (Exception e) {
      reportProblem(msg, e);
    } finally {
      if (tmpMbox != null) {
        tmpMbox.close();
      }
      if (node != null) {
        OtpEpmd.unPublishPort(node);
        node.close();
      }
    }
    return msg;
  }
View Full Code Here

    private boolean canConnect(final String hostName) {
        if (hostName == null) {
            return false;
        }
        try {
            final OtpNode node = new OtpNode("jtest", "erlide");
            final boolean result = node.ping(nodeName + "@" + hostName, 1000);
            node.close();
            return result;
        } catch (final IOException e) {
            ErlLogger.error(e);
        }
        return false;
View Full Code Here

      cookieModuleReference = component.getCookieModuleReference();
      invalidCookieModuleReference = component
          .getInvalidCookieModuleReference();
      timeoutModuleReference = component.getTimeoutModuleReference();

      serNode = new OtpNode("MboxServer");
      serMbox = serNode.createMbox("sendArgs");
      refNode = new OtpNode("MboxClient");
      refMbox = refNode.createMbox("connector_to_SCA_mbox");
    } catch (IOException e) {
      System.out.println("Problem executing " + EPMD_COMMAND + ": "
          + e.getLocalizedMessage() + ". Tests will be IGNORED.");
    }
View Full Code Here

TOP

Related Classes of com.ericsson.otp.erlang.OtpNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.