@Override protected Object call() throws Exception { final ProxyService proxyService = clientEngine.getProxyService(); final String registrationId = proxyService.addProxyListener(this); endpoint.addDestroyAction(registrationId, new Callable() { @Override public Boolean call() { return proxyService.removeProxyListener(registrationId); } }); return registrationId; }
@Override protected Object call() throws Exception { partitionKey = serializationService.toData(parameters.name); TopicService service = getService(TopicService.SERVICE_NAME); String registrationId = service.addMessageListener(parameters.name, this, parameters.localOnly); endpoint.addListenerDestroyAction(TopicService.SERVICE_NAME, parameters.name, registrationId); return registrationId; }
@Override protected Object call() throws Exception { endpoint.clearAllListeners(); return null; }
@Override public Map<String, String> getClientStatistics() { Collection<ClientEndpoint> clientEndpoints = endpointManager.getEndpoints(); Map<String, String> statsMap = new HashMap<String, String>(clientEndpoints.size()); for (ClientEndpoint e : clientEndpoints) { String statistics = e.getClientStatistics(); if (null != statistics) { statsMap.put(e.getUuid(), statistics); } } return statsMap; }
@Override public boolean registerEndpoint(ClientEndpoint endpoint) { checkNotNull(endpoint, "endpoint can't be null"); final Connection conn = endpoint.getConnection(); if (endpoints.putIfAbsent(conn, endpoint) != null) { return false; } else { totalRegistrations.inc(); ClientEvent event = new ClientEvent(endpoint.getUuid(), ClientEventType.CONNECTED, endpoint.getSocketAddress(), endpoint.getClientType(), endpoint.getName(), endpoint.getAttributes()); sendClientEvent(event); return true; } }
@Override public boolean registerEndpoint(ClientEndpoint endpoint) { checkNotNull(endpoint, "endpoint can't be null"); final Connection conn = endpoint.getConnection(); if (endpoints.putIfAbsent(conn, endpoint) != null) { return false; } else { totalRegistrations.inc(); ClientEvent event = new ClientEvent(endpoint.getUuid(), ClientEventType.CONNECTED, endpoint.getSocketAddress(), endpoint.getClientType()); sendClientEvent(event); return true; } }
private void monitor(ClientEndpoint clientEndpoint) { // C++ client does not send heartbeat over its owner connection for versions before 3.10 // We are skipping checking heartbeat for cpp owner connection on those versions. if (clientEndpoint.isOwnerConnection() && ClientType.CPP.equals(clientEndpoint.getClientType()) && clientEndpoint.getClientVersion() < BuildInfo.calculateVersion("3.10")) { return; } 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); } } }
public void onPartitionStateChange() { for (Map.Entry<ClientEndpoint, Long> entry : partitionListeningEndpoints.entrySet()) { ClientMessage clientMessage = getPartitionsMessage(); Long correlationId = entry.getValue(); clientMessage.setCorrelationId(correlationId); ClientEndpoint clientEndpoint = entry.getKey(); Connection connection = clientEndpoint.getConnection(); connection.write(clientMessage); } }
private AuthenticationStatus authenticate(SecurityContext securityContext) { Connection connection = endpoint.getConnection(); credentials.setEndpoint(connection.getInetAddress().getHostAddress()); try { LoginContext lc = securityContext.createClientLoginContext(credentials); lc.login(); endpoint.setLoginContext(lc); return AUTHENTICATED; } catch (LoginException e) { logger.warning(e); return CREDENTIALS_FAILED; } }
private ClientMessage prepareAuthenticatedClientMessage() { Connection connection = endpoint.getConnection(); ILogger logger = clientEngine.getLogger(getClass()); endpoint.authenticated(principal, credentials, isOwnerConnection(), clientVersion, clientMessage.getCorrelationId()); setConnectionType(); logger.info("Received auth from " + connection + ", successfully authenticated" + ", principal: " + principal + ", owner connection: " + isOwnerConnection() + ", client version: " + clientVersion); if (endpointManager.registerEndpoint(endpoint)) { clientEngine.bind(endpoint); } final Address thisAddress = clientEngine.getThisAddress(); byte status = AuthenticationStatus.AUTHENTICATED.getId(); return encodeAuth(status, thisAddress, principal.getUuid(), principal.getOwnerUuid(), serializationService.getVersion(), Collections.<Member>emptyList()); }
private CacheConfig extractCacheConfigFromMessage() { int clientVersion = endpoint.getClientVersion(); if (BuildInfo.UNKNOWN_HAZELCAST_VERSION == clientVersion) { boolean compatibilityEnabled = nodeEngine.getProperties().getBoolean(GroupProperty.COMPATIBILITY_3_6_CLIENT_ENABLED); if (compatibilityEnabled) { LegacyCacheConfig legacyCacheConfig = nodeEngine.toObject(parameters.cacheConfig, LegacyCacheConfig.class); if (null == legacyCacheConfig) { return null; } return legacyCacheConfig.getConfigAndReset(); } } return (CacheConfig) nodeEngine.toObject(parameters.cacheConfig); }
void initializeAndProcessMessage() throws Throwable { if (!node.getNodeExtension().isStartCompleted()) { throw new HazelcastInstanceNotActiveException("Hazelcast instance is not ready yet!"); } parameters = decodeClientMessage(clientMessage); Credentials credentials = endpoint.getCredentials(); interceptBefore(credentials); checkPermissions(endpoint); processMessage(); interceptAfter(credentials); }
private boolean doRun() throws Exception { ILogger logger = getLogger(); ClientEngineImpl engine = getService(); String memberUuid = getCallerUuid(); if (!engine.trySetLastAuthenticationCorrelationId(clientUuid, authCorrelationId)) { String message = "Server already processed a newer authentication from client with UUID " + clientUuid + ". Not applying requested ownership change to " + memberUuid; logger.info(message); throw new StubAuthenticationException(message); } Set<ClientEndpoint> endpoints = engine.getEndpointManager().getEndpoints(clientUuid); for (ClientEndpoint endpoint : endpoints) { ClientPrincipal principal = new ClientPrincipal(clientUuid, memberUuid); endpoint.authenticated(principal); } String previousMemberUuid = engine.addOwnershipMapping(clientUuid, memberUuid); if (logger.isFineEnabled()) { logger.fine("Client authenticated " + clientUuid + ", owner " + memberUuid); } return previousMemberUuid == null; }
private void monitor(ClientEndpoint clientEndpoint) { // C++ client does not send heartbeat over its owner connection for versions before 3.10 // We are skipping checking heartbeat for cpp owner connection on those versions. if (clientEndpoint.isOwnerConnection() && ClientType.CPP.equals(clientEndpoint.getClientType()) && clientEndpoint.getClientVersion() < BuildInfo.calculateVersion("3.10")) { return; } 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); } } }
public void onPartitionStateChange() { for (Map.Entry<ClientEndpoint, Long> entry : partitionListeningEndpoints.entrySet()) { ClientMessage clientMessage = getPartitionsMessage(); Long correlationId = entry.getValue(); clientMessage.setCorrelationId(correlationId); ClientEndpoint clientEndpoint = entry.getKey(); Connection connection = clientEndpoint.getConnection(); connection.write(clientMessage); } }
@Override public Map<String, String> getClientStatistics() { Collection<ClientEndpoint> clientEndpoints = endpointManager.getEndpoints(); Map<String, String> statsMap = new HashMap<String, String>(clientEndpoints.size()); for (ClientEndpoint e : clientEndpoints) { String statistics = e.getClientStatistics(); if (null != statistics) { statsMap.put(e.getUuid(), statistics); } } return statsMap; }
private AuthenticationStatus authenticate(SecurityContext securityContext) { Connection connection = endpoint.getConnection(); credentials.setEndpoint(connection.getInetAddress().getHostAddress()); try { LoginContext lc = securityContext.createClientLoginContext(credentials); lc.login(); endpoint.setLoginContext(lc); return AuthenticationStatus.AUTHENTICATED; } catch (LoginException e) { logger.warning(e); return AuthenticationStatus.CREDENTIALS_FAILED; } }
private ClientMessage prepareAuthenticatedClientMessage() { Connection connection = endpoint.getConnection(); endpoint.authenticated(principal, credentials, isOwnerConnection(), clientVersion, clientMessage.getCorrelationId(), clientName, attributes); setConnectionType(); logger.info("Received auth from " + connection + ", successfully authenticated" + ", principal: " + principal + ", owner connection: " + isOwnerConnection() + ", client version: " + clientVersion); if (endpointManager.registerEndpoint(endpoint)) { clientEngine.bind(endpoint); } final Address thisAddress = clientEngine.getThisAddress(); byte status = AUTHENTICATED.getId(); return encodeAuth(status, thisAddress, principal.getUuid(), principal.getOwnerUuid(), serializationService.getVersion(), Collections.<Member>emptyList()); }
private Data serializeCacheConfig(Object response) { Data responseData = null; if (BuildInfo.UNKNOWN_HAZELCAST_VERSION == endpoint.getClientVersion()) { boolean compatibilityEnabled = nodeEngine.getProperties().getBoolean(GroupProperty.COMPATIBILITY_3_6_CLIENT_ENABLED); if (compatibilityEnabled) { responseData = nodeEngine.toData(response == null ? null : new LegacyCacheConfig((CacheConfig) response)); } } if (null == responseData) { responseData = nodeEngine.toData(response); } return responseData; } }
void initializeAndProcessMessage() throws Throwable { if (!node.getNodeExtension().isStartCompleted()) { throw new HazelcastInstanceNotActiveException("Hazelcast instance is not ready yet!"); } parameters = decodeClientMessage(clientMessage); Credentials credentials = endpoint.getCredentials(); interceptBefore(credentials); checkPermissions(endpoint); processMessage(); interceptAfter(credentials); }