Package one.nio.net

Examples of one.nio.net.Socket


    }

    @Override
    public void run() {
        while (server.isRunning()) {
            Socket socket = null;
            try {
                socket = serverSocket.accept();
                socket.setBlocking(false);
                Session session = server.createSession(socket);
                getSmallestSelector().register(session);
                acceptedSessions++;
            } catch (Exception e) {
                if (server.isRunning()) {
                    log.error("Cannot accept incoming connection", e);
                }
                if (socket != null) {
                    socket.close();
                }
            }
        }
    }
View Full Code Here


    }

    private byte[] invokeRaw(Object request) throws Exception {
        byte[] buffer = serialize(request);

        Socket socket = borrowObject();
        try {
            try {
                sendRequest(socket, buffer);
            } catch (SocketException e) {
                // Stale connection? Retry on a fresh socket
                destroyObject(socket);
                socket = createObject();
                sendRequest(socket, buffer);
            }

            int responseSize = RpcPacket.getSize(buffer, socket);
            if (responseSize > 4) buffer = new byte[responseSize];
            socket.readFully(buffer, 0, responseSize);

            returnObject(socket);
            return buffer;
        } catch (Exception e) {
            invalidateObject(socket);
View Full Code Here

        this.connectionHeader = conn.getBooleanParam("keepalive", true) ? "Connection: Keep-Alive" : "Connection: close";
    }

    @Override
    public Socket createObject() throws PoolException {
        Socket s = super.createObject();
        if (!useSsl) return s;

        try {
            return s.ssl(false);
        } catch (IOException e) {
            s.close();
            throw new PoolException(name() + " failed to create SSL socket", e);
        }
    }
View Full Code Here

    public Response invoke(Request request) throws Exception {
        int method = request.getMethod();
        byte[] rawRequest = request.toBytes();
        ResponseReader responseReader;

        Socket socket = borrowObject();
        boolean keepAlive = false;
        try {
            try {
                socket.writeFully(rawRequest, 0, rawRequest.length);
                responseReader = new ResponseReader(socket, BUFFER_SIZE);
            } catch (SocketException e) {
                // Stale connection? Retry on a fresh socket
                destroyObject(socket);
                socket = createObject();
                socket.writeFully(rawRequest, 0, rawRequest.length);
                responseReader = new ResponseReader(socket, BUFFER_SIZE);
            }

            Response response = responseReader.readResponse(method);
            keepAlive = "Keep-Alive".equalsIgnoreCase(response.getHeader("Connection: "));
View Full Code Here

        this.connectTimeout = connectTimeout;
    }

    @Override
    public Socket createObject() throws PoolException {
        Socket socket = null;
        try {
            socket = Socket.create();
            socket.setKeepAlive(true);
            socket.setNoDelay(true);
            socket.setTimeout(connectTimeout);
            socket.connect(host, port);
            socket.setTimeout(readTimeout);
            return socket;
        } catch (Exception e) {
            if (socket != null) socket.close();
            throw new PoolException(name() + " createObject failed", e);
        }
    }
View Full Code Here

TOP

Related Classes of one.nio.net.Socket

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.