1 /*
2  * Copyright 2018, 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.implcore.trace.export;
18 
19 import io.opencensus.implcore.trace.RecordEventsSpanImpl;
20 import io.opencensus.trace.export.RunningSpanStore;
21 import io.opencensus.trace.export.SpanData;
22 import java.util.Collection;
23 import java.util.Collections;
24 
25 /** Abstract implementation of the {@link RunningSpanStore}. */
26 public abstract class RunningSpanStoreImpl extends RunningSpanStore {
27 
28   private static final RunningSpanStoreImpl NOOP_RUNNING_SPAN_STORE_IMPL =
29       new NoopRunningSpanStoreImpl();
30 
31   /** Returns the no-op implementation of the {@link RunningSpanStoreImpl}. */
getNoopRunningSpanStoreImpl()32   static RunningSpanStoreImpl getNoopRunningSpanStoreImpl() {
33     return NOOP_RUNNING_SPAN_STORE_IMPL;
34   }
35 
36   /**
37    * Adds the {@code Span} into the running spans list when the {@code Span} starts.
38    *
39    * @param span the {@code Span} that started.
40    */
onStart(RecordEventsSpanImpl span)41   public abstract void onStart(RecordEventsSpanImpl span);
42 
43   /**
44    * Removes the {@code Span} from the running spans list when the {@code Span} ends.
45    *
46    * @param span the {@code Span} that ended.
47    */
onEnd(RecordEventsSpanImpl span)48   public abstract void onEnd(RecordEventsSpanImpl span);
49 
50   private static final class NoopRunningSpanStoreImpl extends RunningSpanStoreImpl {
51 
52     private static final Summary EMPTY_SUMMARY =
53         RunningSpanStore.Summary.create(Collections.<String, PerSpanNameSummary>emptyMap());
54 
55     @Override
onStart(RecordEventsSpanImpl span)56     public void onStart(RecordEventsSpanImpl span) {}
57 
58     @Override
onEnd(RecordEventsSpanImpl span)59     public void onEnd(RecordEventsSpanImpl span) {}
60 
61     @Override
getSummary()62     public Summary getSummary() {
63       return EMPTY_SUMMARY;
64     }
65 
66     @Override
getRunningSpans(Filter filter)67     public Collection<SpanData> getRunningSpans(Filter filter) {
68       return Collections.<SpanData>emptyList();
69     }
70   }
71 }
72