01: package org.apache.maven.monitor.event;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "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 implements
29: EventMonitor {
30:
31: private List boundStartEvents;
32: private List boundErrorEvents;
33: private List boundEndEvents;
34:
35: protected AbstractSelectiveEventMonitor(String[] startEvents,
36: String[] endEvents, String[] errorEvents) {
37: this .boundStartEvents = Arrays.asList(startEvents);
38:
39: this .boundEndEvents = Arrays.asList(endEvents);
40:
41: this .boundErrorEvents = Arrays.asList(errorEvents);
42: }
43:
44: public final void startEvent(String eventName, String target,
45: long timestamp) {
46: if (boundStartEvents.contains(eventName)) {
47: doStartEvent(eventName, target, timestamp);
48: }
49: }
50:
51: protected void doStartEvent(String eventName, String target,
52: long timestamp) {
53: }
54:
55: public final void endEvent(String eventName, String target,
56: long timestamp) {
57: if (boundEndEvents.contains(eventName)) {
58: doEndEvent(eventName, target, timestamp);
59: }
60: }
61:
62: protected void doEndEvent(String eventName, String target,
63: long timestamp) {
64: }
65:
66: public final void errorEvent(String eventName, String target,
67: long timestamp, Throwable cause) {
68: if (boundErrorEvents.contains(eventName)) {
69: doErrorEvent(eventName, target, timestamp, cause);
70: }
71: }
72:
73: protected void doErrorEvent(String eventName, String target,
74: long timestamp, Throwable cause) {
75: }
76:
77: }
|