use of com.hazelcast.nio.Address in project hazelcast by hazelcast.
the class ClusterListenerSupport method connect.
private boolean connect(Set<InetSocketAddress> triedAddresses) throws Exception {
final Collection<InetSocketAddress> socketAddresses = getSocketAddresses();
for (InetSocketAddress inetSocketAddress : socketAddresses) {
if (!client.getLifecycleService().isRunning()) {
if (logger.isFinestEnabled()) {
logger.finest("Giving up on retrying to connect to cluster since client is shutdown");
}
break;
}
Connection connection = null;
try {
triedAddresses.add(inetSocketAddress);
Address address = new Address(inetSocketAddress);
logger.info("Trying to connect to " + address + " as owner member");
connection = connectionManager.getOrConnect(address, true);
clientMembershipListener.listenMembershipEvents(ownerConnectionAddress);
fireConnectionEvent(LifecycleEvent.LifecycleState.CLIENT_CONNECTED);
return true;
} catch (Exception e) {
Level level = e instanceof AuthenticationException ? Level.WARNING : Level.FINEST;
logger.log(level, "Exception during initial connection to " + inetSocketAddress, e);
if (null != connection) {
connection.close("Could not connect to " + inetSocketAddress + " as owner", e);
}
}
}
return false;
}
use of com.hazelcast.nio.Address in project hazelcast by hazelcast.
the class DiscoveryAddressProvider method loadAddresses.
@Override
public Collection<InetSocketAddress> loadAddresses() {
Iterable<DiscoveryNode> discoveredNodes = checkNotNull(discoveryService.discoverNodes(), "Discovered nodes cannot be null!");
Collection<InetSocketAddress> possibleMembers = new ArrayList<InetSocketAddress>();
for (DiscoveryNode discoveryNode : discoveredNodes) {
Address discoveredAddress = discoveryNode.getPrivateAddress();
try {
possibleMembers.add(discoveredAddress.getInetSocketAddress());
} catch (UnknownHostException e) {
logger.warning("Unresolvable host exception", e);
}
}
return possibleMembers;
}
use of com.hazelcast.nio.Address in project hazelcast by hazelcast.
the class ClientNonSmartInvocationServiceImpl method getConnection.
@Override
public ClientConnection getConnection(int partitionId) throws IOException {
ClientClusterService clusterService = client.getClientClusterService();
Address ownerConnectionAddress = clusterService.getOwnerConnectionAddress();
if (ownerConnectionAddress == null) {
throw new IOException("ClientNonSmartInvocationServiceImpl: Owner connection is not available.");
}
return (ClientConnection) connectionManager.getConnection(ownerConnectionAddress);
}
use of com.hazelcast.nio.Address in project hazelcast by hazelcast.
the class ClientPartitionServiceImpl method getOwnerConnection.
private Connection getOwnerConnection() {
ClientClusterService clusterService = client.getClientClusterService();
Address ownerAddress = clusterService.getOwnerConnectionAddress();
if (ownerAddress == null) {
return null;
}
Connection connection = client.getConnectionManager().getConnection(ownerAddress);
if (connection == null) {
return null;
}
return connection;
}
use of com.hazelcast.nio.Address in project hazelcast by hazelcast.
the class ClientTransactionManagerServiceImpl method connect.
public ClientConnection connect() throws Exception {
Exception lastError = null;
int count = 0;
while (count < RETRY_COUNT) {
try {
final Address randomAddress = getRandomAddress();
return (ClientConnection) client.getConnectionManager().getOrConnect(randomAddress, false);
} catch (Exception e) {
lastError = e;
}
count++;
}
throw lastError;
}
Aggregations