Package com.hazelcast.nio

Examples of com.hazelcast.nio.Connection


        super(ioService, serverSocketChannel);
    }

    @Override
    public Connection getOrConnect(Address address, boolean silent) {
        Connection connection = getConnection(address);
        if (connection != null) {
            return connection;
        }
        if (blockedAddresses.contains(address)) {
            connection = new DroppingConnection(address);
View Full Code Here


        blockedAddresses.add(address);
    }

    public void unblock(Address address) {
        blockedAddresses.remove(address);
        Connection connection = getConnection(address);
        if (connection instanceof DroppingConnection) {
            destroyConnection(connection);
        }
    }
View Full Code Here

    public void registerEndpoint(ClientEndpoint endpoint) {
        if (endpoint == null) {
            throw new NullPointerException("endpoint can't be null");
        }

        final Connection conn = endpoint.getConnection();
        if (endpoints.putIfAbsent(conn, endpoint) != null) {
            logger.severe("An endpoint already exists for connection:" + conn);
        }
    }
View Full Code Here

            endpoint.destroy();
        } catch (LoginException e) {
            logger.warning(e);
        }

        final Connection connection = endpoint.getConnection();
        if (closeImmediately) {
            try {
                connection.close();
            } catch (Throwable e) {
                logger.warning("While closing client connection: " + connection, e);
            }
        } else {
            nodeEngine.getExecutionService().schedule(new Runnable() {
                public void run() {
                    if (connection.isAlive()) {
                        try {
                            connection.close();
                        } catch (Throwable e) {
                            logger.warning("While closing client connection: " + e.toString());
                        }
                    }
                }
View Full Code Here

        }

        @Override
        public void sendResponse(Object obj) {
            long callId = remotePropagatable.getCallId();
            Connection conn = remotePropagatable.getConnection();
            if (!sent.compareAndSet(false, true) && !(obj instanceof Throwable)) {
                throw new ResponseAlreadySentException("NormalResponse already sent for call: " + callId
                        + " to " + conn.getEndPoint() + ", current-response: " + obj);
            }

            NormalResponse response;
            if (!(obj instanceof NormalResponse)) {
                response = new NormalResponse(obj, remotePropagatable.getCallId(), 0, remotePropagatable.isUrgent());
            } else {
                response = (NormalResponse) obj;
            }

            OperationService operationService = nodeEngine.getOperationService();
            if (!operationService.send(response, remotePropagatable.getCallerAddress())) {
                throw new HazelcastException("Cannot send response: " + obj + " to " + conn.getEndPoint());
            }
        }
View Full Code Here

        sendResponse(endpoint, clientResponse, isEvent);
    }

    private void sendResponse(ClientEndpointImpl endpoint, ClientResponse response, boolean isEvent) {
        Data resultData = serializationService.toData(response);
        Connection conn = endpoint.getConnection();
        final Packet packet = new Packet(resultData, serializationService.getPortableContext());
        if (isEvent) {
            packet.setHeader(Packet.HEADER_EVENT);
        }
        conn.write(packet);
    }
View Full Code Here

    public SecurityContext getSecurityContext() {
        return node.securityContext;
    }

    public void bind(final ClientEndpoint endpoint) {
        final Connection conn = endpoint.getConnection();
        if (conn instanceof TcpIpConnection) {
            Address address = new Address(conn.getRemoteSocketAddress());
            ((TcpIpConnection) conn).setEndPoint(address);
        }
        sendClientEvent(endpoint);
    }
View Full Code Here

                endpoint.destroy();
            } catch (LoginException e) {
                logger.finest(e.getMessage());
            }
            try {
                final Connection conn = endpoint.getConnection();
                if (conn.isAlive()) {
                    conn.close();
                }
            } catch (Exception e) {
                logger.finest(e);
            }
        }
View Full Code Here

            this.packet = packet;
        }

        @Override
        public void run() {
            Connection conn = packet.getConn();
            ClientEndpointImpl endpoint = (ClientEndpointImpl) endpointManager.getEndpoint(conn);
            ClientRequest request = null;
            try {
                request = loadRequest();
                if (request == null) {
                    handlePacketWithNullRequest();
                } else if (request instanceof AuthenticationRequest) {
                    if (conn.isAlive()) {
                        endpoint = new ClientEndpointImpl(ClientEngineImpl.this, conn);
                        processRequest(endpoint, request);
                    } else {
                        handleEndpointNotCreatedConnectionNotAlive();
                    }
View Full Code Here

    private void monitor(String memberUuid, ClientEndpointImpl clientEndpoint) {
        if (clientEndpoint.isFirstConnection()) {
            return;
        }

        final Connection connection = clientEndpoint.getConnection();
        final long lastTimePackageReceived = connection.lastReadTime();
        final long timeoutInMillis = TimeUnit.SECONDS.toMillis(heartbeatTimeoutSeconds);
        final long currentTimeInMillis = Clock.currentTimeMillis();
        if (lastTimePackageReceived + timeoutInMillis < currentTimeInMillis) {
            if (memberUuid.equals(clientEndpoint.getPrincipal().getOwnerUuid())) {
                logger.log(Level.WARNING, "Client heartbeat is timed out , closing connection to " + connection);
                connection.close();
            }
        }
    }
View Full Code Here

TOP

Related Classes of com.hazelcast.nio.Connection

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.