[ 
https://issues.apache.org/jira/browse/BEAM-6502?focusedWorklogId=219600&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-219600
 ]

ASF GitHub Bot logged work on BEAM-6502:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 27/Mar/19 20:38
            Start Date: 27/Mar/19 20:38
    Worklog Time Spent: 10m 
      Work Description: swegner commented on pull request #8146: [BEAM-6502] 
Re-Remove runner time execution information from public API surface (now 
including Watch)
URL: https://github.com/apache/beam/pull/8146#discussion_r269759263
 
 

 ##########
 File path: 
sdks/java/fn-execution/src/main/java/org/apache/beam/sdk/fn/splittabledofn/RestrictionTrackers.java
 ##########
 @@ -0,0 +1,138 @@
+/*
+ * 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.beam.sdk.fn.splittabledofn;
+
+import javax.annotation.concurrent.ThreadSafe;
+import org.apache.beam.sdk.transforms.splittabledofn.Backlog;
+import org.apache.beam.sdk.transforms.splittabledofn.Backlogs;
+import org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker;
+
+/** Support utilities for interacting with {@link RestrictionTracker 
RestrictionTrackers}. */
+public class RestrictionTrackers {
+
+  /** Interface allowing a runner to observe the calls to {@link 
RestrictionTracker#tryClaim}. */
+  public interface ClaimObserver<PositionT> {
+    /** Called when {@link RestrictionTracker#tryClaim} returns true. */
+    void onClaimed(PositionT position);
+
+    /** Called when {@link RestrictionTracker#tryClaim} returns false. */
+    void onClaimFailed(PositionT position);
+  }
+
+  /**
+   * A {@link RestrictionTracker} which forwards all calls to the delegate 
{@link
+   * RestrictionTracker}.
+   */
+  @ThreadSafe
+  private static class RestrictionTrackerObserver<RestrictionT, PositionT>
+      extends RestrictionTracker<RestrictionT, PositionT> {
+    protected final RestrictionTracker<RestrictionT, PositionT> delegate;
+    private final ClaimObserver<PositionT> claimObserver;
+
+    protected RestrictionTrackerObserver(
+        RestrictionTracker<RestrictionT, PositionT> delegate,
+        ClaimObserver<PositionT> claimObserver) {
+      this.delegate = delegate;
+      this.claimObserver = claimObserver;
+    }
+
+    @Override
+    public synchronized boolean tryClaim(PositionT position) {
+      if (delegate.tryClaim(position)) {
+        claimObserver.onClaimed(position);
+        return true;
+      } else {
+        claimObserver.onClaimFailed(position);
+        return false;
+      }
+    }
+
+    @Override
+    public synchronized RestrictionT currentRestriction() {
+      return delegate.currentRestriction();
+    }
+
+    @Override
+    public synchronized RestrictionT checkpoint() {
+      return delegate.checkpoint();
+    }
+
+    @Override
+    public synchronized void checkDone() throws IllegalStateException {
+      delegate.checkDone();
+    }
+  }
+
+  /**
+   * A {@link RestrictionTracker} which forwards all calls to the delegate 
backlog reporting {@link
+   * RestrictionTracker}.
+   */
+  @ThreadSafe
+  private static class RestrictionTrackerObserverWithBacklog<RestrictionT, 
PositionT>
+      extends RestrictionTrackerObserver<RestrictionT, PositionT> implements 
Backlogs.HasBacklog {
+
+    protected RestrictionTrackerObserverWithBacklog(
+        RestrictionTracker<RestrictionT, PositionT> delegate,
+        ClaimObserver<PositionT> claimObserver) {
+      super(delegate, claimObserver);
+    }
+
+    @Override
+    public synchronized Backlog getBacklog() {
+      return ((Backlogs.HasBacklog) delegate).getBacklog();
+    }
+  }
+
+  /**
+   * A {@link RestrictionTracker} which forwards all calls to the delegate 
partitioned backlog
+   * reporting {@link RestrictionTracker}.
+   */
+  @ThreadSafe
+  private static class 
RestrictionTrackerObserverWithPartitionedBacklog<RestrictionT, PositionT>
+      extends RestrictionTrackerObserverWithBacklog<RestrictionT, PositionT>
+      implements Backlogs.HasPartitionedBacklog {
+
+    protected RestrictionTrackerObserverWithPartitionedBacklog(
+        RestrictionTracker<RestrictionT, PositionT> delegate,
+        ClaimObserver<PositionT> claimObserver) {
+      super(delegate, claimObserver);
+    }
+
+    @Override
+    public synchronized byte[] getBacklogPartition() {
+      return ((Backlogs.HasPartitionedBacklog) delegate).getBacklogPartition();
+    }
+  }
+
+  /**
+   * Returns a thread safe {@link RestrictionTracker} which reports all claim 
attempts to the
+   * specified {@link ClaimObserver}.
+   */
+  public static <RestrictionT, PositionT> RestrictionTracker<RestrictionT, 
PositionT> observe(
 
 Review comment:
   If I understand this correctly, RestrictionTracker can implement various 
interfaces with additional APIs that need synchronization. And each wrapper 
implementation needs to maintain the interface signature to mark the 
capabilities of the RestrictionTracker.
   
   These seems potentially fragile, or at least annoying to maintain. Is there 
a better pattern? What about signalling the capabilities of the tracker using 
virtual properties/methods rather than reflection?
 
----------------------------------------------------------------
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]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 219600)
    Time Spent: 1.5h  (was: 1h 20m)

> SplittableDoFn: Re-Remove runner time execution information from public API 
> surface
> -----------------------------------------------------------------------------------
>
>                 Key: BEAM-6502
>                 URL: https://issues.apache.org/jira/browse/BEAM-6502
>             Project: Beam
>          Issue Type: Improvement
>          Components: sdk-java-core
>            Reporter: Luke Cwik
>            Assignee: Luke Cwik
>            Priority: Minor
>              Labels: triaged
>          Time Spent: 1.5h
>  Remaining Estimate: 0h
>
> Move the setting of "claim observers" within RestrictionTracker to another 
> location to clean up the RestrictionTracker interface.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to