1 12 package org.eclipse.core.internal.runtime; 13 14 import java.util.ArrayList ; 15 import java.util.Iterator ; 16 import org.eclipse.core.runtime.*; 17 18 23 public final class RuntimeLog { 25 26 private static ArrayList logListeners = new ArrayList (5); 27 28 34 private static ArrayList queuedMessages = new ArrayList (5); 35 36 39 public static void addLogListener(ILogListener listener) { 40 synchronized (logListeners) { 41 boolean firstListener = (logListeners.size() == 0); 42 logListeners.remove(listener); 45 logListeners.add(listener); 46 if (firstListener) { 47 for (Iterator i = queuedMessages.iterator(); i.hasNext();) { 48 try { 49 IStatus recordedMessage = (IStatus) i.next(); 50 listener.logging(recordedMessage, IRuntimeConstants.PI_RUNTIME); 51 } catch (Exception e) { 52 handleException(e); 53 } catch (LinkageError e) { 54 handleException(e); 55 } 56 } 57 queuedMessages.clear(); 58 } 59 } 60 } 61 62 65 public static void removeLogListener(ILogListener listener) { 66 synchronized (logListeners) { 67 logListeners.remove(listener); 68 } 69 } 70 71 74 public static boolean contains(ILogListener listener) { 75 synchronized (logListeners) { 76 return logListeners.contains(listener); 77 } 78 } 79 80 83 public static void log(final IStatus status) { 84 ILogListener[] listeners; 86 synchronized (logListeners) { 87 listeners = (ILogListener[]) logListeners.toArray(new ILogListener[logListeners.size()]); 88 if (listeners.length == 0) { 89 queuedMessages.add(status); 90 return; 91 } 92 } 93 for (int i = 0; i < listeners.length; i++) { 94 try { 95 listeners[i].logging(status, IRuntimeConstants.PI_RUNTIME); 96 } catch (Exception e) { 97 handleException(e); 98 } catch (LinkageError e) { 99 handleException(e); 100 } 101 } 102 } 103 104 private static void handleException(Throwable e) { 105 if (!(e instanceof OperationCanceledException)) { 106 e.printStackTrace(); 108 } 109 } 110 111 115 public static boolean isEmpty() { 116 synchronized (logListeners) { 117 return (logListeners.size() == 0); 118 } 119 } 120 121 } 122 | Popular Tags |