View Javadoc
1   package org.apachi.onami.lifecycle.warmup;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.concurrent.CountDownLatch;
23  
24  import javax.inject.Inject;
25  import javax.inject.Singleton;
26  import org.apache.onami.lifecycle.warmup.WarmUp;
27  
28  public class Dag1
29  {
30      /*
31          3 Classes all with warmups
32  
33              B
34            <
35          A
36            <
37              C
38       */
39  
40      @SuppressWarnings( "UnusedParameters" )
41      @Singleton
42      public static class A
43      {
44          private final Recorder recorder;
45          private final CountDownLatch latch;
46  
47          @Inject
48          public A( Recorder recorder, B b, C c, CountDownLatch latch )
49          {
50              this.recorder = recorder;
51              this.latch = latch;
52          }
53  
54          @WarmUp
55          public void warmUp()
56              throws InterruptedException
57          {
58              try
59              {
60                  recorder.record( "A" );
61              }
62              finally
63              {
64                  latch.countDown();
65              }
66          }
67      }
68  
69      @Singleton
70      public static class B
71      {
72          private final Recorder recorder;
73          private final CountDownLatch latch;
74  
75          @Inject
76          public B( Recorder recorder, CountDownLatch latch )
77          {
78              this.recorder = recorder;
79              this.latch = latch;
80          }
81  
82          @WarmUp
83          public void warmUp()
84              throws InterruptedException
85          {
86              try
87              {
88                  recorder.record( "B" );
89              }
90              finally
91              {
92                  latch.countDown();
93              }
94          }
95      }
96  
97      @Singleton
98      public static class C
99      {
100         private final Recorder recorder;
101         private final CountDownLatch latch;
102 
103         @Inject
104         public C( Recorder recorder, CountDownLatch latch )
105         {
106             this.recorder = recorder;
107             this.latch = latch;
108         }
109 
110         @WarmUp
111         public void warmUp()
112             throws InterruptedException
113         {
114             try
115             {
116                 recorder.record( "C" );
117             }
118             finally
119             {
120                 latch.countDown();
121             }
122         }
123     }
124 }