Search in sources :

Example 36 with Connection

use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.

the class ProxyManager method getTargetOrOwnerConnection.

private Connection getTargetOrOwnerConnection(final Address target) throws IOException {
    if (target == null) {
        throw new IOException("Not able to setup owner connection!");
    }
    final ClientConnectionManager connectionManager = client.getConnectionManager();
    Connection connection = connectionManager.getConnection(target);
    if (connection == null) {
        final Address ownerConnectionAddress = client.getClientClusterService().getOwnerConnectionAddress();
        if (ownerConnectionAddress == null) {
            throw new IOException("Not able to setup owner connection!");
        }
        connection = connectionManager.getConnection(ownerConnectionAddress);
        if (connection == null) {
            throw new IOException("Client is not connected to member " + target);
        }
    }
    return connection;
}
Also used : Address(com.hazelcast.nio.Address) Connection(com.hazelcast.nio.Connection) IOException(java.io.IOException) ClientConnectionManager(com.hazelcast.client.connection.ClientConnectionManager)

Example 37 with Connection

use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.

the class ProxyManager method initialize.

private void initialize(ClientProxy clientProxy) throws Exception {
    final Address initializationTarget = findNextAddressToSendCreateRequest();
    final Connection connection = getTargetOrOwnerConnection(initializationTarget);
    final ClientMessage clientMessage = ClientCreateProxyCodec.encodeRequest(clientProxy.getDistributedObjectName(), clientProxy.getServiceName(), initializationTarget);
    final ClientContext context = new ClientContext(client, this);
    new ClientInvocation(client, clientMessage, connection).invoke().get();
    clientProxy.setContext(context);
    clientProxy.onInitialize();
}
Also used : Address(com.hazelcast.nio.Address) Connection(com.hazelcast.nio.Connection) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage)

Example 38 with Connection

use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.

the class ClientMembershipListener method detectMembershipEvents.

private List<MembershipEvent> detectMembershipEvents(Map<String, Member> prevMembers) {
    List<MembershipEvent> events = new LinkedList<MembershipEvent>();
    Set<Member> eventMembers = unmodifiableSet(members);
    List<Member> newMembers = new LinkedList<Member>();
    for (Member member : members) {
        Member former = prevMembers.remove(member.getUuid());
        if (former == null) {
            newMembers.add(member);
        }
    }
    // removal events should be added before added events
    for (Member member : prevMembers.values()) {
        events.add(new MembershipEvent(client.getCluster(), member, MembershipEvent.MEMBER_REMOVED, eventMembers));
        Address address = member.getAddress();
        if (clusterService.getMember(address) == null) {
            Connection connection = connectionManager.getConnection(address);
            if (connection != null) {
                connection.close(null, newTargetDisconnectedExceptionCausedByMemberLeftEvent(connection));
            }
        }
    }
    for (Member member : newMembers) {
        events.add(new MembershipEvent(client.getCluster(), member, MembershipEvent.MEMBER_ADDED, eventMembers));
    }
    return events;
}
Also used : Address(com.hazelcast.nio.Address) InitialMembershipEvent(com.hazelcast.core.InitialMembershipEvent) MembershipEvent(com.hazelcast.core.MembershipEvent) Connection(com.hazelcast.nio.Connection) AbstractMember(com.hazelcast.instance.AbstractMember) Member(com.hazelcast.core.Member) LinkedList(java.util.LinkedList)

Example 39 with Connection

use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.

the class ClientNonSmartInvocationServiceImpl method sendToOwner.

private void sendToOwner(ClientInvocation invocation) throws IOException {
    ClientClusterService clusterService = client.getClientClusterService();
    Address ownerConnectionAddress = clusterService.getOwnerConnectionAddress();
    if (ownerConnectionAddress == null) {
        throw new IOException("Packet is not send to owner address");
    }
    Connection conn = connectionManager.getConnection(ownerConnectionAddress);
    if (conn == null) {
        throw new IOException("Packet is not sent to owner address: " + ownerConnectionAddress);
    }
    send(invocation, (ClientConnection) conn);
}
Also used : Address(com.hazelcast.nio.Address) ClientConnection(com.hazelcast.client.connection.nio.ClientConnection) Connection(com.hazelcast.nio.Connection) IOException(java.io.IOException) ClientClusterService(com.hazelcast.client.spi.ClientClusterService)

Example 40 with Connection

use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.

the class ClientSmartInvocationServiceImpl method getOrConnect.

private Connection getOrConnect(Address target) throws IOException {
    ensureOwnerConnectionAvailable();
    Connection connection = connectionManager.getOrConnect(target, false);
    if (connection == null) {
        throw new IOException("No available connection to address " + target);
    }
    return connection;
}
Also used : ClientConnection(com.hazelcast.client.connection.nio.ClientConnection) Connection(com.hazelcast.nio.Connection) IOException(java.io.IOException)

Aggregations

Connection (com.hazelcast.nio.Connection)59 Address (com.hazelcast.nio.Address)15 ClientConnection (com.hazelcast.client.connection.nio.ClientConnection)10 Test (org.junit.Test)9 QuickTest (com.hazelcast.test.annotation.QuickTest)7 IOException (java.io.IOException)7 ClientConnectionManager (com.hazelcast.client.connection.ClientConnectionManager)6 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)6 AssertTask (com.hazelcast.test.AssertTask)6 HazelcastClientInstanceImpl (com.hazelcast.client.impl.HazelcastClientInstanceImpl)5 Packet (com.hazelcast.nio.Packet)5 ClientClusterService (com.hazelcast.client.spi.ClientClusterService)4 ClientInvocation (com.hazelcast.client.spi.impl.ClientInvocation)4 Member (com.hazelcast.core.Member)4 Node (com.hazelcast.instance.Node)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 ParallelTest (com.hazelcast.test.annotation.ParallelTest)3 EventHandler (com.hazelcast.client.spi.EventHandler)2 ClientInvocationFuture (com.hazelcast.client.spi.impl.ClientInvocationFuture)2