StefanRRichter commented on a change in pull request #7899: [FLINK-11731] 
[State Backends] Make DefaultOperatorStateBackend follow the builder pattern
URL: https://github.com/apache/flink/pull/7899#discussion_r262438032
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/state/DefaultOperatorStateBackendBuilder.java
 ##########
 @@ -0,0 +1,103 @@
+/*
+ * 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.runtime.state;
+
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.api.common.ExecutionConfig;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.util.IOUtils;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Builder class for {@link DefaultOperatorStateBackend} which handles all 
necessary initializations and clean ups.
+ */
+public class DefaultOperatorStateBackendBuilder implements
+       StateBackendBuilder<DefaultOperatorStateBackend, 
BackendBuildingException> {
+       /** The user code classloader. */
+       @VisibleForTesting
+       protected final ClassLoader userClassloader;
+       /** The execution configuration. */
+       @VisibleForTesting
+       protected final ExecutionConfig executionConfig;
+       /** Flag to de/activate asynchronous snapshots. */
+       @VisibleForTesting
+       protected final boolean asynchronousSnapshots;
+       /** State handles for restore. */
+       @VisibleForTesting
+       protected final Collection<OperatorStateHandle> restoreStateHandles;
+       @VisibleForTesting
+       protected final CloseableRegistry cancelStreamRegistry;
+
+
+       public DefaultOperatorStateBackendBuilder(
+               ClassLoader userClassloader,
+               ExecutionConfig executionConfig,
+               boolean asynchronousSnapshots,
+               Collection<OperatorStateHandle> stateHandles,
+               CloseableRegistry cancelStreamRegistry) {
+               this.userClassloader = userClassloader;
+               this.executionConfig = executionConfig;
+               this.asynchronousSnapshots = asynchronousSnapshots;
+               this.restoreStateHandles = stateHandles;
+               this.cancelStreamRegistry = cancelStreamRegistry;
+       }
+
+       @Override
+       public DefaultOperatorStateBackend build() throws 
BackendBuildingException {
+               JavaSerializer<Serializable> serializer = new 
JavaSerializer<>();
 
 Review comment:
   One more comment about this `JavaSerializer`. This is one exception where I 
would initialize the field inside the constructor of 
`DefaultOperatorStateBackend` and not pass it in. The reasons are, that this 
member has a similar intent as a `static final` field, only the class does not 
support concurrency so we must create a new instance per object. This field is 
always assigned the same type of object and it is also only used in the context 
of a deprecated method. No new code or tests would ever be interested to pass 
in something different here.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to