/** * Returns a future holding the serialized request result. * * @param jobId JobID of the job the queryable state * belongs to * @param queryableStateName Name under which the state is queryable * @param keyHashCode Integer hash code of the key (result of * a call to {@link Object#hashCode()} * @param serializedKeyAndNamespace Serialized key and namespace to query * KvState instance with * @return Future holding the serialized result */ private CompletableFuture<KvStateResponse> getKvState( final JobID jobId, final String queryableStateName, final int keyHashCode, final byte[] serializedKeyAndNamespace) { LOG.debug("Sending State Request to {}.", remoteAddress); try { KvStateRequest request = new KvStateRequest(jobId, queryableStateName, keyHashCode, serializedKeyAndNamespace); return client.sendRequest(remoteAddress, request); } catch (Exception e) { LOG.error("Unable to send KVStateRequest: ", e); return FutureUtils.getFailedFuture(e); } } }
@Override public CompletableFuture<Void> shutdown() { return kvStateClient.shutdown(); } }
client = new Client<>("Test Client", 1, serializer, stats); CompletableFuture<KvStateResponse> future = client.sendRequest(serverAddress, request); if (client != null) { try { client.shutdown().get(10L, TimeUnit.SECONDS); } catch (Exception e) { e.printStackTrace(); Assert.assertTrue(client.isEventGroupShutdown());
private static Client<KvStateInternalRequest, KvStateResponse> createInternalClient(int threads) { final MessageSerializer<KvStateInternalRequest, KvStateResponse> messageSerializer = new MessageSerializer<>( new KvStateInternalRequest.KvStateInternalRequestDeserializer(), new KvStateResponse.KvStateResponseDeserializer()); return new Client<>( "Queryable State Proxy Client", threads, messageSerializer, new DisabledKvStateRequestStats()); }
client = new Client<>("Test Client", 1, serializer, stats); results.add(finalClient.sendRequest(serverAddress, request)); client.shutdown().get(10L, TimeUnit.SECONDS); } catch (Exception e) { e.printStackTrace(); Assert.assertTrue(client.isEventGroupShutdown());
/** * Create the Queryable State Client. * @param remoteAddress the {@link InetAddress address} of the {@code Client Proxy} to connect to. * @param remotePort the port of the proxy to connect to. */ public QueryableStateClient(final InetAddress remoteAddress, final int remotePort) { Preconditions.checkArgument(remotePort >= 0 && remotePort <= 65536, "Remote Port " + remotePort + " is out of valid port range (0-65536)."); this.remoteAddress = new InetSocketAddress(remoteAddress, remotePort); final MessageSerializer<KvStateRequest, KvStateResponse> messageSerializer = new MessageSerializer<>( new KvStateRequest.KvStateRequestDeserializer(), new KvStateResponse.KvStateResponseDeserializer()); this.client = new Client<>( "Queryable State Client", 1, messageSerializer, new DisabledKvStateRequestStats()); }
client = new Client<>("Test Client", 1, serializer, stats); KvStateInternalRequest request = new KvStateInternalRequest(new KvStateID(), new byte[0]); futures.add(client.sendRequest(serverAddress, request)); futures.add(client.sendRequest(serverAddress, request)); if (client != null) { try { client.shutdown().get(10L, TimeUnit.SECONDS); } catch (Exception e) { e.printStackTrace(); Assert.assertTrue(client.isEventGroupShutdown());
/** * Shuts down the client and returns a {@link CompletableFuture} that * will be completed when the shutdown process is completed. * * <p>If an exception is thrown for any reason, then the returned future * will be completed exceptionally with that exception. * * @return A {@link CompletableFuture} for further handling of the * shutdown result. */ public CompletableFuture<?> shutdownAndHandle() { return client.shutdown(); }
/** * Create the Queryable State Client. * @param remoteAddress the {@link InetAddress address} of the {@code Client Proxy} to connect to. * @param remotePort the port of the proxy to connect to. */ public QueryableStateClient(final InetAddress remoteAddress, final int remotePort) { Preconditions.checkArgument(remotePort >= 0 && remotePort <= 65536, "Remote Port " + remotePort + " is out of valid port range (0-65536)."); this.remoteAddress = new InetSocketAddress(remoteAddress, remotePort); final MessageSerializer<KvStateRequest, KvStateResponse> messageSerializer = new MessageSerializer<>( new KvStateRequest.KvStateRequestDeserializer(), new KvStateResponse.KvStateResponseDeserializer()); this.client = new Client<>( "Queryable State Client", 1, messageSerializer, new DisabledKvStateRequestStats()); }
private CompletableFuture<KvStateResponse> getState( final KvStateRequest request, final boolean forceUpdate) { return getKvStateLookupInfo(request.getJobId(), request.getStateName(), forceUpdate) .thenComposeAsync((Function<KvStateLocation, CompletableFuture<KvStateResponse>>) location -> { final int keyGroupIndex = KeyGroupRangeAssignment.computeKeyGroupForKeyHash( request.getKeyHashCode(), location.getNumKeyGroups()); final InetSocketAddress serverAddress = location.getKvStateServerAddress(keyGroupIndex); if (serverAddress == null) { return FutureUtils.completedExceptionally(new UnknownKvStateKeyGroupLocationException(getServerName())); } else { // Query server final KvStateID kvStateId = location.getKvStateID(keyGroupIndex); final KvStateInternalRequest internalRequest = new KvStateInternalRequest( kvStateId, request.getSerializedKeyAndNamespace()); return kvStateClient.sendRequest(serverAddress, internalRequest); } }, queryExecutor); }
client = new Client<>("Test Client", 1, serializer, stats); Future<KvStateResponse> future = client.sendRequest(serverAddress, request); if (client != null) { try { client.shutdown().get(10L, TimeUnit.SECONDS); } catch (Exception e) { e.printStackTrace(); Assert.assertTrue(client.isEventGroupShutdown());
/** * Shuts down the client and waits until shutdown is completed. * * <p>If an exception is thrown, a warning is logged containing * the exception message. */ public void shutdownAndWait() { try { client.shutdown().get(); LOG.info("The Queryable State Client was shutdown successfully."); } catch (Exception e) { LOG.warn("The Queryable State Client shutdown failed: ", e); } }
/** * Create the Queryable State Client. * @param remoteAddress the {@link InetAddress address} of the {@code Client Proxy} to connect to. * @param remotePort the port of the proxy to connect to. */ public QueryableStateClient(final InetAddress remoteAddress, final int remotePort) { Preconditions.checkArgument(remotePort >= 0 && remotePort <= 65536, "Remote Port " + remotePort + " is out of valid port range (0-65536)."); this.remoteAddress = new InetSocketAddress(remoteAddress, remotePort); final MessageSerializer<KvStateRequest, KvStateResponse> messageSerializer = new MessageSerializer<>( new KvStateRequest.KvStateRequestDeserializer(), new KvStateResponse.KvStateResponseDeserializer()); this.client = new Client<>( "Queryable State Client", 1, messageSerializer, new DisabledKvStateRequestStats()); }
/** * Returns a future holding the serialized request result. * * @param jobId JobID of the job the queryable state * belongs to * @param queryableStateName Name under which the state is queryable * @param keyHashCode Integer hash code of the key (result of * a call to {@link Object#hashCode()} * @param serializedKeyAndNamespace Serialized key and namespace to query * KvState instance with * @return Future holding the serialized result */ private CompletableFuture<KvStateResponse> getKvState( final JobID jobId, final String queryableStateName, final int keyHashCode, final byte[] serializedKeyAndNamespace) { LOG.debug("Sending State Request to {}.", remoteAddress); try { KvStateRequest request = new KvStateRequest(jobId, queryableStateName, keyHashCode, serializedKeyAndNamespace); return client.sendRequest(remoteAddress, request); } catch (Exception e) { LOG.error("Unable to send KVStateRequest: ", e); return FutureUtils.getFailedFuture(e); } } }
client = new Client<>("Test Client", 1, serializer, stats); for (long i = 0L; i < numQueries; i++) { KvStateInternalRequest request = new KvStateInternalRequest(new KvStateID(), new byte[0]); futures.add(client.sendRequest(serverAddress, request)); client.shutdown().get(10L, TimeUnit.SECONDS); } catch (Exception e) { exc = e; client.isEventGroupShutdown() );
/** * Shuts down the client and returns a {@link CompletableFuture} that * will be completed when the shutdown process is completed. * * <p>If an exception is thrown for any reason, then the returned future * will be completed exceptionally with that exception. * * @return A {@link CompletableFuture} for further handling of the * shutdown result. */ public CompletableFuture<?> shutdownAndHandle() { return client.shutdown(); }
/** * Returns a future holding the serialized request result. * * @param jobId JobID of the job the queryable state * belongs to * @param queryableStateName Name under which the state is queryable * @param keyHashCode Integer hash code of the key (result of * a call to {@link Object#hashCode()} * @param serializedKeyAndNamespace Serialized key and namespace to query * KvState instance with * @return Future holding the serialized result */ private CompletableFuture<KvStateResponse> getKvState( final JobID jobId, final String queryableStateName, final int keyHashCode, final byte[] serializedKeyAndNamespace) { LOG.debug("Sending State Request to {}.", remoteAddress); try { KvStateRequest request = new KvStateRequest(jobId, queryableStateName, keyHashCode, serializedKeyAndNamespace); return client.sendRequest(remoteAddress, request); } catch (Exception e) { LOG.error("Unable to send KVStateRequest: ", e); return FutureUtils.getFailedFuture(e); } } }
/** * Shuts down the client and returns a {@link CompletableFuture} that * will be completed when the shutdown process is completed. * * <p>If an exception is thrown for any reason, then the returned future * will be completed exceptionally with that exception. * * @return A {@link CompletableFuture} for further handling of the * shutdown result. */ public CompletableFuture<?> shutdownAndHandle() { return client.shutdown(); }
/** * Shuts down the client and waits until shutdown is completed. * * <p>If an exception is thrown, a warning is logged containing * the exception message. */ public void shutdownAndWait() { try { client.shutdown().get(); LOG.info("The Queryable State Client was shutdown successfully."); } catch (Exception e) { LOG.warn("The Queryable State Client shutdown failed: ", e); } }
/** * Shuts down the client and waits until shutdown is completed. * * <p>If an exception is thrown, a warning is logged containing * the exception message. */ public void shutdownAndWait() { try { client.shutdown().get(); LOG.info("The Queryable State Client was shutdown successfully."); } catch (Exception e) { LOG.warn("The Queryable State Client shutdown failed: ", e); } }