You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by tz...@apache.org on 2020/05/28 11:41:48 UTC

[flink-statefun] 05/10: [FLINK-17875] [core] Introduce StateSpec for remote function specs

This is an automated email from the ASF dual-hosted git repository.

tzulitai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink-statefun.git

commit 00233601a0d6933c71b65eba828562f75dd0c7d0
Author: Tzu-Li (Gordon) Tai <tz...@apache.org>
AuthorDate: Wed May 27 12:05:38 2020 +0800

    [FLINK-17875] [core] Introduce StateSpec for remote function specs
    
    The StateSpec class represents the state name and ttl duration as
    specified in YAML remote modules.
---
 .../flink/core/httpfn/HttpFunctionSpec.java        | 12 +++---
 .../statefun/flink/core/httpfn/StateSpec.java      | 44 ++++++++++++++++++++++
 2 files changed, 50 insertions(+), 6 deletions(-)

diff --git a/statefun-flink/statefun-flink-core/src/main/java/org/apache/flink/statefun/flink/core/httpfn/HttpFunctionSpec.java b/statefun-flink/statefun-flink-core/src/main/java/org/apache/flink/statefun/flink/core/httpfn/HttpFunctionSpec.java
index 0e03591..868e542 100644
--- a/statefun-flink/statefun-flink-core/src/main/java/org/apache/flink/statefun/flink/core/httpfn/HttpFunctionSpec.java
+++ b/statefun-flink/statefun-flink-core/src/main/java/org/apache/flink/statefun/flink/core/httpfn/HttpFunctionSpec.java
@@ -32,14 +32,14 @@ public final class HttpFunctionSpec implements FunctionSpec {
 
   private final FunctionType functionType;
   private final URI endpoint;
-  private final List<String> states;
+  private final List<StateSpec> states;
   private final Duration maxRequestDuration;
   private final int maxNumBatchRequests;
 
   private HttpFunctionSpec(
       FunctionType functionType,
       URI endpoint,
-      List<String> states,
+      List<StateSpec> states,
       Duration maxRequestDuration,
       int maxNumBatchRequests) {
     this.functionType = Objects.requireNonNull(functionType);
@@ -72,7 +72,7 @@ public final class HttpFunctionSpec implements FunctionSpec {
     return "http+unix".equalsIgnoreCase(scheme) || "https+unix".equalsIgnoreCase(scheme);
   }
 
-  public List<String> states() {
+  public List<StateSpec> states() {
     return states;
   }
 
@@ -89,7 +89,7 @@ public final class HttpFunctionSpec implements FunctionSpec {
     private final FunctionType functionType;
     private final URI endpoint;
 
-    private final List<String> states = new ArrayList<>();
+    private final List<StateSpec> states = new ArrayList<>();
     private Duration maxRequestDuration = DEFAULT_HTTP_TIMEOUT;
     private int maxNumBatchRequests = DEFAULT_MAX_NUM_BATCH_REQUESTS;
 
@@ -98,8 +98,8 @@ public final class HttpFunctionSpec implements FunctionSpec {
       this.endpoint = Objects.requireNonNull(endpoint);
     }
 
-    public Builder withState(String stateName) {
-      this.states.add(stateName);
+    public Builder withState(StateSpec stateSpec) {
+      this.states.add(stateSpec);
       return this;
     }
 
diff --git a/statefun-flink/statefun-flink-core/src/main/java/org/apache/flink/statefun/flink/core/httpfn/StateSpec.java b/statefun-flink/statefun-flink-core/src/main/java/org/apache/flink/statefun/flink/core/httpfn/StateSpec.java
new file mode 100644
index 0000000..7748fec
--- /dev/null
+++ b/statefun-flink/statefun-flink-core/src/main/java/org/apache/flink/statefun/flink/core/httpfn/StateSpec.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.statefun.flink.core.httpfn;
+
+import java.time.Duration;
+import java.util.Objects;
+
+public final class StateSpec {
+  private final String name;
+  private final Duration ttlDuration;
+
+  public StateSpec(String name) {
+    this(name, Duration.ZERO);
+  }
+
+  public StateSpec(String name, Duration ttlDuration) {
+    this.name = Objects.requireNonNull(name);
+    this.ttlDuration = Objects.requireNonNull(ttlDuration);
+  }
+
+  public String name() {
+    return name;
+  }
+
+  public Duration ttlDuration() {
+    return ttlDuration;
+  }
+}