• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Dagger 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 dagger.functional.producers.cancellation;
18 
19 import static com.google.common.base.Preconditions.checkNotNull;
20 
21 import com.google.common.util.concurrent.ListenableFuture;
22 import dagger.BindsInstance;
23 import dagger.functional.producers.cancellation.CancellationComponent.Dependency;
24 import dagger.producers.Producer;
25 import dagger.producers.Production;
26 import dagger.producers.ProductionComponent;
27 import java.util.concurrent.Executor;
28 import javax.inject.Named;
29 
30 @ProductionComponent(modules = CancellationModule.class, dependencies = Dependency.class)
31 interface CancellationComponent {
32 
33   @Named("ep1")
entryPoint1()34   ListenableFuture<String> entryPoint1();
35 
36   @Named("ep2")
entryPoint2()37   Producer<String> entryPoint2();
38 
39   @Named("ep3")
entryPoint3()40   ListenableFuture<String> entryPoint3();
41 
subcomponentBuilder()42   CancellationSubcomponent.Builder subcomponentBuilder();
43 
44   @ProductionComponent.Builder
45   interface Builder {
module(CancellationModule module)46     Builder module(CancellationModule module);
47 
dependency(Dependency dependency)48     Builder dependency(Dependency dependency);
49 
50     @BindsInstance
executor(@roduction Executor executor)51     Builder executor(@Production Executor executor);
52 
build()53     CancellationComponent build();
54   }
55 
56   final class Dependency {
57 
58     final ProducerTester tester;
59 
Dependency(ProducerTester tester)60     Dependency(ProducerTester tester) {
61       this.tester = checkNotNull(tester);
62     }
63 
64     @SuppressWarnings("unused") // Dagger uses it
getDependencyFuture()65     ListenableFuture<String> getDependencyFuture() {
66       return tester.start("dependencyFuture");
67     }
68   }
69 }
70