[ 
https://issues.apache.org/jira/browse/HADOOP-19525?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17942164#comment-17942164
 ] 

ASF GitHub Bot commented on HADOOP-19525:
-----------------------------------------

YanivKunda commented on code in PR #7570:
URL: https://github.com/apache/hadoop/pull/7570#discussion_r2035164162


##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/AbstractClock.java:
##########
@@ -0,0 +1,56 @@
+/**
+ * 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.hadoop.util;
+
+import java.time.Clock;
+import java.time.Instant;
+import java.time.ZoneId;
+
+import static java.time.ZoneOffset.UTC;
+
+/**
+ * An abstract base class for Clocks with the following default behavior:
+ * <ul>
+ * <li>Zone-agnostic: always returns UTC, ignoring any other zones</li>
+ * <li>millis-centric: shifts responsibility of subclasses to defining {@link 
#millis()},
+ * creating an Instant based on it (instead of vice versa as in {@link 
java.time.Clock})</li>
+ * </ul>
+ * Subclasses that want to change this behavior can either override relevant 
methods or
+ * subclass {@link java.time.Clock} directly.
+ */
+public abstract class AbstractClock extends Clock {

Review Comment:
   @pan3793 thanks for the review!
   This just serves as base class for `Clock`s that don't need to deal with 
`ZoneId`s and mostly handle times natively via milliseconds (converting to 
`Instant`s and not vice-versa).
   The alternative would be to just delete it and have the two subclasses 
implement this common behavior.
   
   I can also mark it with `@LimitedPrivate` and limit it to either -
   1) The only module currently using it (YARN, in ControlledClock)
   2) All modules currently using `java.time.Clock` (after this change - YARN, 
tools, MapReduce)
   
   I think I prefer the first approach (delete the class) since it doesn't save 
too much boilerplate anyway.
   wdyt?





> Use java.time.Clock instead of org.apache.hadoop.util.Clock
> -----------------------------------------------------------
>
>                 Key: HADOOP-19525
>                 URL: https://issues.apache.org/jira/browse/HADOOP-19525
>             Project: Hadoop Common
>          Issue Type: Sub-task
>          Components: hadoop-common, mapreduce, yarn
>            Reporter: Yaniv Kunda
>            Assignee: Yaniv Kunda
>            Priority: Major
>              Labels: pull-request-available
>
> Hadoop's {{Clock}} interface was recently moved from 
> {{org.apache.hadoop.yarn.util}} (in hadoop-yarn) to 
> {{org.apache.hadoop.util}} (in hadoop-common) as part of YARN-11765.
> I propose to seize the opportunity of this being targeted done for 3.5.0 to 
> modernize it usage:
> # Deprecate {{org.apache.hadoop.util.Clock}}
> # Replace all of its usages with {{java.time.Clock}}
> # Replace existing usages of its simple implementations, e.g. 
> {{SystemClock}}/{{UTCClock}} with standard {{java.time.Clock}} subclasses, 
> e.g. {{Clock.systemUTC()}}
> # Re-implement other implementations, e.g. 
> {{MonotonicClock}}/{{ControllerClock}}, as {{java.time.Clock}} subclasses.
> The standard {{java.time.Clock}} has a richer API supports modern 
> {{java.time}} classes such as {{Instant}} and {{ZoneId}}, and migration would 
> be straightforward:
> Just changing {{org.apache.hadoop.util.Clock.getTime()}} to 
> {{java.time.Clock.millis()}}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org

Reply via email to