Java Code Examples for org.apache.flink.queryablestate.FutureUtils#getFailedFuture()
The following examples show how to use
org.apache.flink.queryablestate.FutureUtils#getFailedFuture() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Client.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * Returns a future holding the serialized request result. * * <p>If the channel has been established, forward the call to the * established channel, otherwise queue it for when the channel is * handed in. * * @param request the request to be sent. * @return Future holding the serialized result */ CompletableFuture<RESP> sendRequest(REQ request) { synchronized (connectLock) { if (failureCause != null) { return FutureUtils.getFailedFuture(failureCause); } else if (connectionShutdownFuture.get() != null) { return FutureUtils.getFailedFuture(new ClosedChannelException()); } else { if (established != null) { return established.sendRequest(request); } else { // Queue this and handle when connected final PendingRequest pending = new PendingRequest(request); queuedRequests.add(pending); return pending; } } } }
Example 2
Source File: Client.java From flink with Apache License 2.0 | 6 votes |
/** * Returns a future holding the serialized request result. * * <p>If the channel has been established, forward the call to the * established channel, otherwise queue it for when the channel is * handed in. * * @param request the request to be sent. * @return Future holding the serialized result */ CompletableFuture<RESP> sendRequest(REQ request) { synchronized (connectLock) { if (failureCause != null) { return FutureUtils.getFailedFuture(failureCause); } else if (connectionShutdownFuture.get() != null) { return FutureUtils.getFailedFuture(new ClosedChannelException()); } else { if (established != null) { return established.sendRequest(request); } else { // Queue this and handle when connected final PendingRequest pending = new PendingRequest(request); queuedRequests.add(pending); return pending; } } } }
Example 3
Source File: Client.java From flink with Apache License 2.0 | 6 votes |
/** * Returns a future holding the serialized request result. * * <p>If the channel has been established, forward the call to the * established channel, otherwise queue it for when the channel is * handed in. * * @param request the request to be sent. * @return Future holding the serialized result */ CompletableFuture<RESP> sendRequest(REQ request) { synchronized (connectLock) { if (failureCause != null) { return FutureUtils.getFailedFuture(failureCause); } else if (connectionShutdownFuture.get() != null) { return FutureUtils.getFailedFuture(new ClosedChannelException()); } else { if (established != null) { return established.sendRequest(request); } else { // Queue this and handle when connected final PendingRequest pending = new PendingRequest(request); queuedRequests.add(pending); return pending; } } } }
Example 4
Source File: Client.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
public CompletableFuture<RESP> sendRequest(final InetSocketAddress serverAddress, final REQ request) { if (clientShutdownFuture.get() != null) { return FutureUtils.getFailedFuture(new IllegalStateException(clientName + " is already shut down.")); } EstablishedConnection connection = establishedConnections.get(serverAddress); if (connection != null) { return connection.sendRequest(request); } else { PendingConnection pendingConnection = pendingConnections.get(serverAddress); if (pendingConnection != null) { // There was a race, use the existing pending connection. return pendingConnection.sendRequest(request); } else { // We try to connect to the server. PendingConnection pending = new PendingConnection(serverAddress, messageSerializer); PendingConnection previous = pendingConnections.putIfAbsent(serverAddress, pending); if (previous == null) { // OK, we are responsible to connect. bootstrap.connect(serverAddress.getAddress(), serverAddress.getPort()).addListener(pending); return pending.sendRequest(request); } else { // There was a race, use the existing pending connection. return previous.sendRequest(request); } } } }
Example 5
Source File: QueryableStateClient.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Returns a future holding the request result. * @param jobId JobID of the job the queryable state belongs to. * @param queryableStateName Name under which the state is queryable. * @param key The key that the state we request is associated with. * @param namespace The namespace of the state. * @param keyTypeInfo The {@link TypeInformation} of the keys. * @param namespaceTypeInfo The {@link TypeInformation} of the namespace. * @param stateDescriptor The {@link StateDescriptor} of the state we want to query. * @return Future holding the immutable {@link State} object containing the result. */ private <K, N, S extends State, V> CompletableFuture<S> getKvState( final JobID jobId, final String queryableStateName, final K key, final N namespace, final TypeInformation<K> keyTypeInfo, final TypeInformation<N> namespaceTypeInfo, final StateDescriptor<S, V> stateDescriptor) { Preconditions.checkNotNull(jobId); Preconditions.checkNotNull(queryableStateName); Preconditions.checkNotNull(key); Preconditions.checkNotNull(namespace); Preconditions.checkNotNull(keyTypeInfo); Preconditions.checkNotNull(namespaceTypeInfo); Preconditions.checkNotNull(stateDescriptor); TypeSerializer<K> keySerializer = keyTypeInfo.createSerializer(executionConfig); TypeSerializer<N> namespaceSerializer = namespaceTypeInfo.createSerializer(executionConfig); stateDescriptor.initializeSerializerUnlessSet(executionConfig); final byte[] serializedKeyAndNamespace; try { serializedKeyAndNamespace = KvStateSerializer .serializeKeyAndNamespace(key, keySerializer, namespace, namespaceSerializer); } catch (IOException e) { return FutureUtils.getFailedFuture(e); } return getKvState(jobId, queryableStateName, key.hashCode(), serializedKeyAndNamespace) .thenApply(stateResponse -> createState(stateResponse, stateDescriptor)); }
Example 6
Source File: QueryableStateClient.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * 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); } }
Example 7
Source File: Client.java From flink with Apache License 2.0 | 5 votes |
public CompletableFuture<RESP> sendRequest(final InetSocketAddress serverAddress, final REQ request) { if (clientShutdownFuture.get() != null) { return FutureUtils.getFailedFuture(new IllegalStateException(clientName + " is already shut down.")); } EstablishedConnection connection = establishedConnections.get(serverAddress); if (connection != null) { return connection.sendRequest(request); } else { PendingConnection pendingConnection = pendingConnections.get(serverAddress); if (pendingConnection != null) { // There was a race, use the existing pending connection. return pendingConnection.sendRequest(request); } else { // We try to connect to the server. PendingConnection pending = new PendingConnection(serverAddress, messageSerializer); PendingConnection previous = pendingConnections.putIfAbsent(serverAddress, pending); if (previous == null) { // OK, we are responsible to connect. bootstrap.connect(serverAddress.getAddress(), serverAddress.getPort()).addListener(pending); return pending.sendRequest(request); } else { // There was a race, use the existing pending connection. return previous.sendRequest(request); } } } }
Example 8
Source File: QueryableStateClient.java From flink with Apache License 2.0 | 5 votes |
/** * Returns a future holding the request result. * @param jobId JobID of the job the queryable state belongs to. * @param queryableStateName Name under which the state is queryable. * @param key The key that the state we request is associated with. * @param namespace The namespace of the state. * @param keyTypeInfo The {@link TypeInformation} of the keys. * @param namespaceTypeInfo The {@link TypeInformation} of the namespace. * @param stateDescriptor The {@link StateDescriptor} of the state we want to query. * @return Future holding the immutable {@link State} object containing the result. */ private <K, N, S extends State, V> CompletableFuture<S> getKvState( final JobID jobId, final String queryableStateName, final K key, final N namespace, final TypeInformation<K> keyTypeInfo, final TypeInformation<N> namespaceTypeInfo, final StateDescriptor<S, V> stateDescriptor) { Preconditions.checkNotNull(jobId); Preconditions.checkNotNull(queryableStateName); Preconditions.checkNotNull(key); Preconditions.checkNotNull(namespace); Preconditions.checkNotNull(keyTypeInfo); Preconditions.checkNotNull(namespaceTypeInfo); Preconditions.checkNotNull(stateDescriptor); TypeSerializer<K> keySerializer = keyTypeInfo.createSerializer(executionConfig); TypeSerializer<N> namespaceSerializer = namespaceTypeInfo.createSerializer(executionConfig); stateDescriptor.initializeSerializerUnlessSet(executionConfig); final byte[] serializedKeyAndNamespace; try { serializedKeyAndNamespace = KvStateSerializer .serializeKeyAndNamespace(key, keySerializer, namespace, namespaceSerializer); } catch (IOException e) { return FutureUtils.getFailedFuture(e); } return getKvState(jobId, queryableStateName, key.hashCode(), serializedKeyAndNamespace) .thenApply(stateResponse -> createState(stateResponse, stateDescriptor)); }
Example 9
Source File: QueryableStateClient.java From flink with Apache License 2.0 | 5 votes |
/** * 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); } }
Example 10
Source File: LocalStandaloneFlinkResource.java From flink with Apache License 2.0 | 5 votes |
@Override public CompletableFuture<Void> closeAsync() { try { distribution.stopFlinkCluster(); return CompletableFuture.completedFuture(null); } catch (IOException e) { return FutureUtils.getFailedFuture(e); } }
Example 11
Source File: Client.java From flink with Apache License 2.0 | 5 votes |
public CompletableFuture<RESP> sendRequest(final InetSocketAddress serverAddress, final REQ request) { if (clientShutdownFuture.get() != null) { return FutureUtils.getFailedFuture(new IllegalStateException(clientName + " is already shut down.")); } EstablishedConnection connection = establishedConnections.get(serverAddress); if (connection != null) { return connection.sendRequest(request); } else { PendingConnection pendingConnection = pendingConnections.get(serverAddress); if (pendingConnection != null) { // There was a race, use the existing pending connection. return pendingConnection.sendRequest(request); } else { // We try to connect to the server. PendingConnection pending = new PendingConnection(serverAddress, messageSerializer); PendingConnection previous = pendingConnections.putIfAbsent(serverAddress, pending); if (previous == null) { // OK, we are responsible to connect. bootstrap.connect(serverAddress.getAddress(), serverAddress.getPort()).addListener(pending); return pending.sendRequest(request); } else { // There was a race, use the existing pending connection. return previous.sendRequest(request); } } } }
Example 12
Source File: QueryableStateClient.java From flink with Apache License 2.0 | 5 votes |
/** * Returns a future holding the request result. * @param jobId JobID of the job the queryable state belongs to. * @param queryableStateName Name under which the state is queryable. * @param key The key that the state we request is associated with. * @param namespace The namespace of the state. * @param keyTypeInfo The {@link TypeInformation} of the keys. * @param namespaceTypeInfo The {@link TypeInformation} of the namespace. * @param stateDescriptor The {@link StateDescriptor} of the state we want to query. * @return Future holding the immutable {@link State} object containing the result. */ private <K, N, S extends State, V> CompletableFuture<S> getKvState( final JobID jobId, final String queryableStateName, final K key, final N namespace, final TypeInformation<K> keyTypeInfo, final TypeInformation<N> namespaceTypeInfo, final StateDescriptor<S, V> stateDescriptor) { Preconditions.checkNotNull(jobId); Preconditions.checkNotNull(queryableStateName); Preconditions.checkNotNull(key); Preconditions.checkNotNull(namespace); Preconditions.checkNotNull(keyTypeInfo); Preconditions.checkNotNull(namespaceTypeInfo); Preconditions.checkNotNull(stateDescriptor); TypeSerializer<K> keySerializer = keyTypeInfo.createSerializer(executionConfig); TypeSerializer<N> namespaceSerializer = namespaceTypeInfo.createSerializer(executionConfig); stateDescriptor.initializeSerializerUnlessSet(executionConfig); final byte[] serializedKeyAndNamespace; try { serializedKeyAndNamespace = KvStateSerializer .serializeKeyAndNamespace(key, keySerializer, namespace, namespaceSerializer); } catch (IOException e) { return FutureUtils.getFailedFuture(e); } return getKvState(jobId, queryableStateName, key.hashCode(), serializedKeyAndNamespace) .thenApply(stateResponse -> createState(stateResponse, stateDescriptor)); }
Example 13
Source File: QueryableStateClient.java From flink with Apache License 2.0 | 5 votes |
/** * 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); } }