Package com.ericsson.otp.erlang

Examples of com.ericsson.otp.erlang.OtpConnection


  @Test(timeout = 4000)
  public void testServiceTimeouts() throws Exception {
    OtpSelf self = new OtpSelf("tmp_connector_"
        + System.currentTimeMillis());
    OtpPeer peer = new OtpPeer("RPCServerTimeout");
    OtpConnection connection = self.connect(peer);
    // delay message sending after connecting
    Thread.sleep(1000);
    // service binding timeout set to 500 so after that time it will give up
    // and close connection
    try {
      connection.send("rex", new OtpErlangString("test"));
      fail("Exception expected");
    } catch (Exception e) {
      assertEquals(IOException.class, e.getClass());
    }

    connection = self.connect(peer);
    // sending message immediately and encountering no connection close
    connection.send("rex", new OtpErlangString("test"));

  }
View Full Code Here


  }

  private Message invokeOperation(Message msg) {
    OtpSelf self = null;
    OtpPeer other = null;
    OtpConnection connection = null;
    try {
      self = new OtpSelf(getClientNodeName());
      if (binding.hasCookie()) {
        self.setCookie(binding.getCookie());
      }
      other = new OtpPeer(binding.getNode());
      connection = self.connect(other);
      Method jmethod = ((JavaOperation) msg.getOperation())
          .getJavaMethod();
      OtpErlangList params = TypeHelpersProxy.toErlangAsList(msg
          .getBody(), jmethod.getParameterAnnotations());
      OtpErlangTuple message = MessageHelper.rpcMessage(self.pid(), self
          .createRef(), binding.getModule(), msg.getOperation()
          .getName(), params);
      connection.send(MessageHelper.RPC_MBOX, message);
      OtpErlangObject rpcResponse = null;
      if (binding.hasTimeout()) {
        rpcResponse = connection.receive(binding.getTimeout());
      } else {
        rpcResponse = connection.receive();
      }
      OtpErlangObject result = ((OtpErlangTuple) rpcResponse)
          .elementAt(1);
      if (MessageHelper.isfunctionUndefMessage(result)) {
        // TODO: externalize message?
        Exception e = new ErlangException("No '" + binding.getModule()
            + ":" + msg.getOperation().getName()
            + "' operation defined on remote '" + binding.getNode()
            + "' node.");
        reportProblem(msg, e);
        msg.setBody(null);
      } else if (msg.getOperation().getOutputType() != null) {
        jmethod.getAnnotations();
        msg.setBody(TypeHelpersProxy.toJava(result, msg.getOperation()
            .getOutputType().getPhysical(), jmethod
            .getAnnotations()));
      }
    } catch (OtpAuthException e) {
      // TODO: externalize message?
      ErlangException ee = new ErlangException(
          "Problem while authenticating client - check your cookie",
          e);
      msg.setBody(null);
      reportProblem(msg, ee);
    } catch (InterruptedException e) {
      // TODO: externalize message?
      ErlangException ee = new ErlangException(
          "Timeout while receiving RPC reply", e);
      msg.setBody(null);
      reportProblem(msg, ee);
    } catch (Exception e) {
      reportProblem(msg, e);
    } finally {
      if (connection != null) {
        connection.close();
      }
    }
    return msg;
  }
View Full Code Here

  public void run() {
    executors = Executors.newFixedThreadPool(nodeElement.getBinding().getServiceThreadPool());
    while (!stopRequested) {
      try {
        OtpConnection connection = self.accept();
        executors.execute(new ServiceExecutor(connection,
            groupedOperations, nodeElement, name));
      } catch (IOException e) {
        // TODO: externalzie message?
        logger.log(Level.WARNING,
View Full Code Here

  @Test(timeout = 4000)
  public void testServiceTimeouts() throws Exception {
    OtpSelf self = new OtpSelf("tmp_connector_"
        + System.currentTimeMillis());
    OtpPeer peer = new OtpPeer("RPCServerTimeout");
    OtpConnection connection = self.connect(peer);
    // delay message sending after connecting
    Thread.sleep(1000);
    // service binding timeout set to 500 so after that time it will give up
    // and close connection
    try {
      connection.send("rex", new OtpErlangString("test"));
      fail("Exception expected");
    } catch (Exception e) {
      assertEquals(IOException.class, e.getClass());
    }

    connection = self.connect(peer);
    // sending message immediately and encountering no connection close
    connection.send("rex", new OtpErlangString("test"));

  }
View Full Code Here

  @Test
  public void stressTest() throws Exception {
    String cookie = readCookie();
    logger.info("Cookie: " + cookie);
    OtpConnection con = createConnection();
    boolean recycleConnection = false;
    for (int i = 0; i < 100; i++) {
      executeRpc(con, recycleConnection, "rabbit", "status");
      executeRpc(con, recycleConnection, "rabbit", "stop");
      executeRpc(con, recycleConnection, "rabbit", "status");
View Full Code Here

TOP

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

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.