comparison graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/observer/ObservableCompiler.java @ 2874:d90bf514d647

Renamed packages.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 08 Jun 2011 08:59:54 +0200
parents graal/com.oracle.max.graal.compiler/src/com/sun/c1x/observer/ObservableCompiler.java@0341b6424579
children
comparison
equal deleted inserted replaced
2873:810e2d253e00 2874:d90bf514d647
1 /*
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.oracle.max.graal.compiler.observer;
24
25 import java.util.*;
26
27 import com.oracle.max.graal.compiler.debug.*;
28
29 /**
30 * Base class for compilers that notify subscribed {@link CompilationObserver CompilationObservers} of
31 * {@link CompilationEvent CompilationEvents} that occur during their compilations.
32 *
33 * @author Peter Hofer
34 */
35 public class ObservableCompiler {
36
37 private List<CompilationObserver> observers;
38
39 /**
40 * @return {@code true} if one or more observers are subscribed to receive notifications from this compiler,
41 * {@code false} otherwise.
42 */
43 public boolean isObserved() {
44 return observers != null && !TTY.isSuppressed();
45 }
46
47 /**
48 * Add the specified observer to receive events from this compiler.
49 *
50 * @param observer The observer to add.
51 */
52 public void addCompilationObserver(CompilationObserver observer) {
53 assert observer != null;
54
55 if (observers == null) {
56 observers = new LinkedList<CompilationObserver>();
57 }
58 observers.add(observer);
59 }
60
61 public void fireCompilationStarted(CompilationEvent event) {
62 if (isObserved()) {
63 for (CompilationObserver observer : observers) {
64 observer.compilationStarted(event);
65 }
66 }
67 }
68
69 public void fireCompilationEvent(CompilationEvent event) {
70 if (isObserved()) {
71 for (CompilationObserver observer : observers) {
72 observer.compilationEvent(event);
73 }
74 }
75 }
76
77 public void fireCompilationFinished(CompilationEvent event) {
78 if (isObserved()) {
79 for (CompilationObserver observer : observers) {
80 observer.compilationFinished(event);
81 }
82 }
83 }
84
85 /**
86 * Remove the specified observer so that it no longer receives events from this compiler.
87 *
88 * @param observer The observer to remove.
89 */
90 public void removeCompilationObserver(CompilationObserver observer) {
91 if (observers != null) {
92 observers.remove(observer);
93 if (observers.size() == 0) {
94 observers = null;
95 }
96 }
97 }
98
99 }