Home | History | Annotate | Download | only in internal
      1 /*
      2  * Copyright 2017, OpenCensus Authors
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *     http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package io.opencensus.internal;
     18 
     19 import io.opencensus.common.Clock;
     20 import io.opencensus.common.Timestamp;
     21 import javax.annotation.concurrent.Immutable;
     22 
     23 /** A {@link Clock} that always returns 0. */
     24 @Immutable
     25 public final class ZeroTimeClock extends Clock {
     26   private static final ZeroTimeClock INSTANCE = new ZeroTimeClock();
     27   private static final Timestamp ZERO_TIMESTAMP = Timestamp.create(0, 0);
     28 
     29   private ZeroTimeClock() {}
     30 
     31   /**
     32    * Returns a {@code ZeroTimeClock}.
     33    *
     34    * @return a {@code ZeroTimeClock}.
     35    */
     36   public static ZeroTimeClock getInstance() {
     37     return INSTANCE;
     38   }
     39 
     40   @Override
     41   public Timestamp now() {
     42     return ZERO_TIMESTAMP;
     43   }
     44 
     45   @Override
     46   public long nowNanos() {
     47     return 0;
     48   }
     49 }
     50