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;
}
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();
}
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;
}
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);
}
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;
}
Aggregations