Mercurial > projects > dwt2
comparison org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/RuntimeLog.d @ 105:bbe49769ec18
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 08 Nov 2009 12:42:30 +0100 |
parents | bc29606a740c |
children |
comparison
equal
deleted
inserted
replaced
104:88652073d1c2 | 105:bbe49769ec18 |
---|---|
2 * Copyright (c) 2000, 2006 IBM Corporation and others. | 2 * Copyright (c) 2000, 2006 IBM Corporation and others. |
3 * All rights reserved. This program and the accompanying materials | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | 4 * are made available under the terms of the Eclipse Public License v1.0 |
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * Julian Chen - fix for bug #92572, jclRM | 10 * Julian Chen - fix for bug #92572, jclRM |
11 * Port to the D programming language: | |
12 * Frank Benoit <benoit@tionex.de> | |
13 *******************************************************************************/ | 11 *******************************************************************************/ |
14 module org.eclipse.core.internal.runtime.RuntimeLog; | 12 // Port to the D programming language: |
13 // Frank Benoit <benoit@tionex.de> | |
14 module org.eclipse.core.internal.runtimeRuntimeLog; | |
15 | 15 |
16 import java.lang.all; | 16 import java.lang.all; |
17 | |
18 import org.eclipse.core.internal.runtimeIRuntimeConstants; // packageimport | |
19 | |
17 import java.util.ArrayList; | 20 import java.util.ArrayList; |
18 import java.util.Iterator; | 21 import java.util.Iterator; |
19 | 22 |
20 import org.eclipse.core.runtime.ILogListener; | 23 import org.eclipse.core.runtime.ILogListener; |
21 import org.eclipse.core.runtime.IStatus; | 24 import org.eclipse.core.runtime.IStatus; |
22 import org.eclipse.core.runtime.OperationCanceledException; | 25 import org.eclipse.core.runtime.OperationCanceledException; |
23 import org.eclipse.core.internal.runtime.IRuntimeConstants; | |
24 | 26 |
25 /** | 27 /** |
26 * NOT API!!! This log infrastructure was split from the InternalPlatform. | 28 * NOT API!!! This log infrastructure was split from the InternalPlatform. |
27 * | 29 * |
28 * @since org.eclipse.equinox.common 3.2 | 30 * @since org.eclipse.equinox.common 3.2 |
29 */ | 31 */ |
30 // XXX this must be removed and replaced with something more reasonable | 32 // XXX this must be removed and replaced with something more reasonable |
31 public final class RuntimeLog { | 33 public final class RuntimeLog { |
32 | 34 |
33 private static ArrayList logListeners; | 35 private static ArrayList logListeners = new ArrayList(5); |
34 | 36 |
35 /** | 37 /** |
36 * Keep the messages until the first log listener is registered. | 38 * Keep the messages until the first log listener is registered. |
37 * Once first log listeners is registred, it is going to receive | 39 * Once first log listeners is registred, it is going to receive |
38 * all status messages accumulated during the period when no log | 40 * all status messages accumulated during the period when no log |
39 * listener was available. | 41 * listener was available. |
40 */ | 42 */ |
41 private static ArrayList queuedMessages; | 43 private static ArrayList queuedMessages = new ArrayList(5); |
42 | |
43 static this(){ | |
44 logListeners = new ArrayList(5); | |
45 queuedMessages = new ArrayList(5); | |
46 } | |
47 | 44 |
48 /** | 45 /** |
49 * See org.eclipse.core.runtime.Platform#addLogListener(ILogListener) | 46 * See org.eclipse.core.runtime.Platform#addLogListener(ILogListener) |
50 */ | 47 */ |
51 public static void addLogListener(ILogListener listener) { | 48 public static void addLogListener(ILogListener listener) { |
52 synchronized (logListeners) { | 49 synchronized (logListeners) { |
53 bool firstListener = (logListeners.size() is 0); | 50 bool firstListener = (logListeners.size() is 0); |
54 // replace if already exists (Set behaviour but we use an array | 51 // replace if already exists (Set behaviour but we use an array |
55 // since we want to retain order) | 52 // since we want to retain order) |
56 logListeners.remove(cast(Object)listener); | 53 logListeners.remove(listener); |
57 logListeners.add(cast(Object)listener); | 54 logListeners.add(listener); |
58 if (firstListener) { | 55 if (firstListener) { |
59 for (Iterator i = queuedMessages.iterator(); i.hasNext();) { | 56 for (Iterator i = queuedMessages.iterator(); i.hasNext();) { |
60 try { | 57 try { |
61 IStatus recordedMessage = cast(IStatus) i.next(); | 58 IStatus recordedMessage = cast(IStatus) i.next(); |
62 listener.logging(recordedMessage, IRuntimeConstants.PI_RUNTIME); | 59 listener.logging(recordedMessage, IRuntimeConstants.PI_RUNTIME); |
63 } catch (Exception e) { | 60 } catch (Exception e) { |
64 handleException(e); | 61 handleException(e); |
65 // SWT Fixme | 62 } catch (LinkageError e) { |
66 // } catch (LinkageError e) { | 63 handleException(e); |
67 // handleException(e); | |
68 } | 64 } |
69 } | 65 } |
70 queuedMessages.clear(); | 66 queuedMessages.clear(); |
71 } | 67 } |
72 } | 68 } |
75 /** | 71 /** |
76 * See org.eclipse.core.runtime.Platform#removeLogListener(ILogListener) | 72 * See org.eclipse.core.runtime.Platform#removeLogListener(ILogListener) |
77 */ | 73 */ |
78 public static void removeLogListener(ILogListener listener) { | 74 public static void removeLogListener(ILogListener listener) { |
79 synchronized (logListeners) { | 75 synchronized (logListeners) { |
80 logListeners.remove(cast(Object)listener); | 76 logListeners.remove(listener); |
81 } | 77 } |
82 } | 78 } |
83 | 79 |
84 /** | 80 /** |
85 * Checks if the given listener is present | 81 * Checks if the given listener is present |
86 */ | 82 */ |
87 public static bool contains(ILogListener listener) { | 83 public static bool contains(ILogListener listener) { |
88 synchronized (logListeners) { | 84 synchronized (logListeners) { |
89 return logListeners.contains(cast(Object)listener); | 85 return logListeners.contains(listener); |
90 } | 86 } |
91 } | 87 } |
92 | 88 |
93 /** | 89 /** |
94 * Notifies all listeners of the platform log. | 90 * Notifies all listeners of the platform log. |
95 */ | 91 */ |
96 public static void log(IStatus status) { | 92 public static void log(final IStatus status) { |
97 // create array to avoid concurrent access | 93 // create array to avoid concurrent access |
98 ILogListener[] listeners; | 94 ILogListener[] listeners; |
99 synchronized (logListeners) { | 95 synchronized (logListeners) { |
100 listeners = arraycast!(ILogListener)( logListeners.toArray()); | 96 listeners = (ILogListener[]) logListeners.toArray(new ILogListener[logListeners.size()]); |
101 if (listeners.length is 0) { | 97 if (listeners.length is 0) { |
102 queuedMessages.add(cast(Object)status); | 98 queuedMessages.add(status); |
103 return; | 99 return; |
104 } | 100 } |
105 } | 101 } |
106 for (int i = 0; i < listeners.length; i++) { | 102 for (int i = 0; i < listeners.length; i++) { |
107 try { | 103 try { |
108 listeners[i].logging(status, IRuntimeConstants.PI_RUNTIME); | 104 listeners[i].logging(status, IRuntimeConstants.PI_RUNTIME); |
109 } catch (Exception e) { | 105 } catch (Exception e) { |
110 handleException(e); | 106 handleException(e); |
111 // SWT Fixme | 107 } catch (LinkageError e) { |
112 // } catch (LinkageError e) { | 108 handleException(e); |
113 // handleException(e); | |
114 } | 109 } |
115 } | 110 } |
116 } | 111 } |
117 | 112 |
118 private static void handleException(Exception e) { | 113 private static void handleException(Throwable e) { |
119 if (!(cast(OperationCanceledException)e )) { | 114 if (!( null !is cast(OperationCanceledException)e )) { |
120 // Got a error while logging. Don't try to log again, just put it into stderr | 115 // Got a error while logging. Don't try to log again, just put it into stderr |
121 ExceptionPrintStackTrace(e); | 116 e.printStackTrace(); |
122 } | 117 } |
123 } | 118 } |
124 | 119 |
125 /** | 120 /** |
126 * Helps determine if any listeners are registered with the logging mechanism. | 121 * Helps determine if any listeners are registered with the logging mechanism. |