View Javadoc

1   package org.apache.maven.monitor.event;
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.Arrays;
23  import java.util.List;
24  
25  /**
26   * @author jdcasey
27   */
28  public abstract class AbstractSelectiveEventMonitor
29      implements EventMonitor
30  {
31      
32      private List boundStartEvents;
33      private List boundErrorEvents;
34      private List boundEndEvents;
35  
36      protected AbstractSelectiveEventMonitor(String[] startEvents, String[] endEvents, String[] errorEvents)
37      {
38          this.boundStartEvents = Arrays.asList( startEvents );
39          
40          this.boundEndEvents = Arrays.asList( endEvents );
41          
42          this.boundErrorEvents = Arrays.asList( errorEvents );
43      }
44  
45      public final void startEvent( String eventName, String target, long timestamp )
46      {
47          if( boundStartEvents.contains( eventName ) )
48          {
49              doStartEvent( eventName, target, timestamp );
50          }
51      }
52      
53      protected void doStartEvent( String eventName, String target, long timestamp )
54      {
55      }
56  
57      public final void endEvent( String eventName, String target, long timestamp )
58      {
59          if( boundEndEvents.contains( eventName ) )
60          {
61              doEndEvent( eventName, target, timestamp );
62          }
63      }
64  
65      protected void doEndEvent( String eventName, String target, long timestamp )
66      {
67      }
68  
69      public final void errorEvent( String eventName, String target, long timestamp, Throwable cause )
70      {
71          if( boundErrorEvents.contains( eventName ) )
72          {
73              doErrorEvent( eventName, target, timestamp, cause );
74          }
75      }
76  
77      protected void doErrorEvent( String eventName, String target, long timestamp, Throwable cause )
78      {
79      }
80  
81  }