Exemplo n.º 1
0
  private void initSocket(InetAddress address, int port, boolean nonDefaultSocket)
      throws SocketException, IOException {
    socket = new Socket();
    if (nonDefaultSocket) {
      socket.setReuseAddress(true);
      try {
        this.socket.setTcpNoDelay(true);
      } catch (SocketException e) {
        EclTcpClientPlugin.log(
            new Status(
                IStatus.ERROR,
                EclTcpClientPlugin.PLUGIN_ID,
                "Error setting TCP_NODELAY on client socket"));
      }
    }
    socket.connect(new InetSocketAddress(address, port));

    initSessionId(socket);
  }
Exemplo n.º 2
0
  public EclTcpSession(InetAddress address, int port) throws IOException {
    NetworkUtil.initTimeouts();
    this.address = address;
    this.port = port;

    try {
      initSocket(address, port, true);
    } catch (IOException e) {
      initSocket(address, port, false);
      EclTcpClientPlugin.logInfo(
          "Could not open a session with NO_DELAY and SO_REUSEADDR, succeeded with default socket");
    }
    processingThread =
        new Thread(
            new Runnable() {
              public void run() {
                try {
                  while (!closed.get()) {
                    ExecutionNode node = null;
                    IMarkeredPipe pipe = null;
                    try {
                      node = commands.take();
                      if (CLOSE_NODE.equals(node)) {
                        return;
                      }
                      pipe =
                          CoreUtils.createEMFPipe(
                              socket.getInputStream(), socket.getOutputStream());

                      pipe.write(node.command);
                      readInput(node.input, pipe);
                      pipe.writeCloseMarker();
                      IStatus result = writeOutput(node.output, pipe);

                      node.process.setStatus(result);
                    } catch (Throwable t) {
                      try {
                        if (node != null) {
                          IStatus status =
                              (t instanceof CoreException)
                                  ? ((CoreException) t).getStatus()
                                  : CorePlugin.err(t);
                          node.process.setStatus(new EclTcpSocketStatus(status));
                        }
                      } catch (CoreException e1) {
                        CorePlugin.log(e1);
                      }
                    } finally {
                      if (pipe != null) {
                        pipe.closeNoWait();
                      }
                    }
                  }
                } finally {
                  try {
                    closeSocket();
                  } catch (Throwable e) {
                    CorePlugin.log(e);
                  }
                }
              }
            },
            "ECL TCP session execute: " + sessionID);
    processingThread.start();
  }