use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.
the class SqlErrorClientTest method testMissingHandler.
@Test
public void testMissingHandler() {
instance1 = newHazelcastInstance(true);
client = newClient();
try {
ClientMessage message = SqlExecute_reservedCodec.encodeRequest("SELECT * FROM table", Collections.emptyList(), 100L, 100);
SqlClientService clientService = ((SqlClientService) client.getSql());
Connection connection = clientService.getQueryConnection();
clientService.invokeOnConnection(connection, message);
fail("Must fail");
} catch (Exception e) {
assertTrue(e.getMessage().contains("Unrecognized client message received"));
}
}
use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.
the class ClientICMPManager method start.
public static void start(ClientIcmpPingConfig clientIcmpPingConfig, TaskScheduler taskScheduler, ILogger logger, Collection<Connection> unmodifiableActiveConnections) {
if (!clientIcmpPingConfig.isEnabled()) {
return;
}
if (clientIcmpPingConfig.isEchoFailFastOnStartup()) {
echoFailFast(logger);
}
int icmpTtl = clientIcmpPingConfig.getTtl();
int icmpTimeoutMillis = clientIcmpPingConfig.getTimeoutMilliseconds();
int icmpIntervalMillis = clientIcmpPingConfig.getIntervalMilliseconds();
int icmpMaxAttempts = clientIcmpPingConfig.getMaxAttempts();
if (icmpTimeoutMillis > icmpIntervalMillis) {
throw new IllegalStateException("ICMP timeout is set to a value greater than the ICMP interval, " + "this is not allowed.");
}
if (icmpIntervalMillis < MIN_ICMP_INTERVAL_MILLIS) {
throw new IllegalStateException("ICMP interval is set to a value less than the min allowed, " + MIN_ICMP_INTERVAL_MILLIS + "ms");
}
PingFailureDetector<Connection> failureDetector = new PingFailureDetector<>(icmpMaxAttempts);
taskScheduler.scheduleWithRepetition(() -> {
failureDetector.retainAttemptsForAliveEndpoints(unmodifiableActiveConnections);
for (Connection connection : unmodifiableActiveConnections) {
// we don't want an isReachable call to an address stopping us to check other addresses.
// so we run each check in its own thread
taskScheduler.execute(() -> ping(logger, failureDetector, connection, icmpTtl, icmpTimeoutMillis));
}
}, icmpIntervalMillis, icmpIntervalMillis, TimeUnit.MILLISECONDS);
}
use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.
the class TcpClientConnectionManager method doConnectToCandidateCluster.
private boolean doConnectToCandidateCluster(CandidateClusterContext context, boolean switchingToNextCluster) {
Set<Address> triedAddresses = new HashSet<>();
try {
waitStrategy.reset();
do {
Set<Address> triedAddressesPerAttempt = new HashSet<>();
List<Member> memberList = new ArrayList<>(client.getClientClusterService().getMemberList());
if (shuffleMemberList) {
Collections.shuffle(memberList);
}
// try to connect to a member in the member list first
for (Member member : memberList) {
checkClientActive();
triedAddressesPerAttempt.add(member.getAddress());
Connection connection = connect(member, o -> getOrConnectToMember((Member) o, switchingToNextCluster));
if (connection != null) {
return true;
}
}
// try to connect to a member given via config(explicit config/discovery mechanisms)
for (Address address : getPossibleMemberAddresses(context.getAddressProvider())) {
checkClientActive();
if (!triedAddressesPerAttempt.add(address)) {
// if we can not add it means that it is already tried to be connected with the member list
continue;
}
Connection connection = connect(address, o -> getOrConnectToAddress((Address) o, switchingToNextCluster));
if (connection != null) {
return true;
}
}
triedAddresses.addAll(triedAddressesPerAttempt);
// and the lifecycle check is missing, hence we need to repeat the same check at this point.
if (triedAddressesPerAttempt.isEmpty()) {
checkClientActive();
}
} while (waitStrategy.sleep());
} catch (ClientNotAllowedInClusterException | InvalidConfigurationException e) {
logger.warning("Stopped trying on the cluster: " + context.getClusterName() + " reason: " + e.getMessage());
}
logger.info("Unable to connect to any address from the cluster with name: " + context.getClusterName() + ". The following addresses were tried: " + triedAddresses);
return false;
}
use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.
the class HeartbeatManager method start.
public static void start(HazelcastClientInstanceImpl client, TaskScheduler taskScheduler, ILogger logger, long heartbeatIntervalMillis, long heartbeatTimeoutMillis, Collection<Connection> unmodifiableActiveConnections) {
taskScheduler.scheduleWithRepetition(() -> {
long now = Clock.currentTimeMillis();
for (Connection connection : unmodifiableActiveConnections) {
if (!connection.isAlive()) {
return;
}
if (now - connection.lastReadTimeMillis() > heartbeatTimeoutMillis) {
logger.warning("Heartbeat failed over the connection: " + connection);
connection.close("Heartbeat timed out", new TargetDisconnectedException("Heartbeat timed out to connection " + connection));
return;
}
if (now - connection.lastWriteTimeMillis() > heartbeatIntervalMillis) {
ClientMessage request = ClientPingCodec.encodeRequest();
ClientInvocation invocation = new ClientInvocation(client, request, null, connection);
invocation.invokeUrgent();
}
}
}, heartbeatIntervalMillis, heartbeatIntervalMillis, MILLISECONDS);
}
use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.
the class ClientEngineImpl method accept.
public void accept(ClientMessage clientMessage) {
Connection connection = clientMessage.getConnection();
MessageTask messageTask = messageTaskFactory.create(clientMessage, connection);
OperationServiceImpl operationService = nodeEngine.getOperationService();
if (isUrgent(messageTask)) {
operationService.execute((UrgentMessageTask) messageTask);
} else if (messageTask instanceof AbstractPartitionMessageTask) {
operationService.execute((AbstractPartitionMessageTask) messageTask);
} else if (isQuery(messageTask)) {
queryExecutor.execute(messageTask);
} else if (messageTask instanceof TransactionalMessageTask) {
blockingExecutor.execute(messageTask);
} else if (messageTask instanceof BlockingMessageTask) {
blockingExecutor.execute(messageTask);
} else {
executor.execute(messageTask);
}
}
Aggregations