use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.
the class ClientHeartbeatMonitor method monitor.
private void monitor(ClientEndpoint clientEndpoint) {
Connection connection = clientEndpoint.getConnection();
long lastTimePacketReceived = connection.lastReadTimeMillis();
long timeoutInMillis = SECONDS.toMillis(heartbeatTimeoutSeconds);
long currentTimeMillis = Clock.currentTimeMillis();
if (lastTimePacketReceived + timeoutInMillis < currentTimeMillis) {
String message = "Client heartbeat is timed out, closing connection to " + connection + ". Now: " + timeToString(currentTimeMillis) + ". LastTimePacketReceived: " + timeToString(lastTimePacketReceived);
connection.close(message, null);
}
}
use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.
the class MembersUpdateOp method getConnectionEndpointOrThisAddress.
final Address getConnectionEndpointOrThisAddress() {
ClusterServiceImpl clusterService = getService();
NodeEngineImpl nodeEngine = clusterService.getNodeEngine();
Node node = nodeEngine.getNode();
Connection conn = getConnection();
return conn != null ? conn.getRemoteAddress() : node.getThisAddress();
}
use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.
the class AuthenticationBaseMessageTask method prepareUnauthenticatedClientMessage.
private ClientMessage prepareUnauthenticatedClientMessage() {
boolean clientFailoverSupported = nodeEngine.getNode().getNodeExtension().isClientFailoverSupported();
Connection connection = endpoint.getConnection();
logger.warning("Received auth from " + connection + " with clientUuid " + clientUuid + " and clientName " + clientName + ", authentication failed");
byte status = CREDENTIALS_FAILED.getId();
return encodeAuth(status, null, null, serializationService.getVersion(), clientEngine.getPartitionService().getPartitionCount(), clientEngine.getClusterService().getClusterId(), clientFailoverSupported);
}
use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.
the class AuthenticationBaseMessageTask method authenticate.
private AuthenticationStatus authenticate(SecurityContext securityContext) {
String nodeClusterName = nodeEngine.getConfig().getClusterName();
if (!nodeClusterName.equals(clusterName)) {
return CREDENTIALS_FAILED;
}
Connection connection = endpoint.getConnection();
Boolean passed = Boolean.FALSE;
try {
LoginContext lc = securityContext.createClientLoginContext(clusterName, credentials, connection);
lc.login();
endpoint.setLoginContext(lc);
passed = Boolean.TRUE;
return AUTHENTICATED;
} catch (LoginException e) {
logger.warning(e);
return CREDENTIALS_FAILED;
} finally {
nodeEngine.getNode().getNodeExtension().getAuditlogService().eventBuilder(AuditlogTypeIds.AUTHENTICATION_CLIENT).message("Client connection authentication.").addParameter("connection", connection).addParameter("credentials", credentials).addParameter("passed", passed).log();
}
}
use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.
the class ClientClusterServiceImpl method detectMembershipEvents.
private List<MembershipEvent> detectMembershipEvents(Collection<Member> prevMembers, Set<Member> currentMembers) {
List<Member> newMembers = new LinkedList<>();
Set<Member> deadMembers = new HashSet<>(prevMembers);
for (Member member : currentMembers) {
if (!deadMembers.remove(member)) {
newMembers.add(member);
}
}
List<MembershipEvent> events = new LinkedList<>();
for (Member member : deadMembers) {
events.add(new MembershipEvent(client.getCluster(), member, MembershipEvent.MEMBER_REMOVED, currentMembers));
Connection connection = connectionManager.getConnection(member.getUuid());
if (connection != null) {
connection.close(null, new TargetDisconnectedException("The client has closed the connection to this member," + " after receiving a member left event from the cluster. " + connection));
}
}
for (Member member : newMembers) {
events.add(new MembershipEvent(client.getCluster(), member, MembershipEvent.MEMBER_ADDED, currentMembers));
}
if (events.size() != 0) {
MemberListSnapshot snapshot = memberListSnapshot.get();
if (snapshot.members.values().size() != 0) {
logger.info(membersString(snapshot));
}
}
return events;
}
Aggregations