Exemple #1
0
    public TcpWorker(Socket socket, AbstractMessageReceiver receiver) throws IOException {
      super(socket, receiver, ((TcpConnector) connector).getTcpProtocol().createResponse(socket));
      this.socket = socket;

      final TcpConnector tcpConnector = ((TcpConnector) connector);
      protocol = tcpConnector.getTcpProtocol();

      try {
        tcpConnector.configureSocket(TcpConnector.SERVER, socket);

        underlyingIn = new BufferedInputStream(socket.getInputStream());
        dataIn =
            new TcpInputStream(underlyingIn) {
              public void close() throws IOException {
                // Don't actually close the stream, we just want to know if the
                // we want to stop receiving messages on this sockete.
                // The Protocol is responsible for closing this.
                dataInWorkFinished = true;
                moreMessages = false;

                synchronized (notify) {
                  notify.notifyAll();
                }
              }
            };
        dataOut = new BufferedOutputStream(socket.getOutputStream());
      } catch (IOException e) {
        logger.error("Failed to set Socket properties: " + e.getMessage(), e);
      }
    }
Exemple #2
0
  public Object makeObject(Object key) throws Exception {
    UMOImmutableEndpoint ep = (UMOImmutableEndpoint) key;
    int port = ep.getEndpointURI().getPort();
    InetAddress inetAddress = InetAddress.getByName(ep.getEndpointURI().getHost());
    Socket socket = createSocket(port, inetAddress);
    socket.setReuseAddress(true);

    TcpConnector connector = (TcpConnector) ep.getConnector();
    connector.configureSocket(TcpConnector.CLIENT, socket);

    return socket;
  }