2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 import java
.util
.LinkedList
;
21 /** The event queue singleton dispatches events received from OpenOffice.org
22 applications in a thread separate from the AWB main thread.
24 The queue of event objects, LinkedList<Runnable> The queue object will
25 also serve as lock for the consumer/producer type syncronization.
30 public boolean mbVerbose
= false;
31 public boolean mbHandleDisposingEventsSynchronous
= true;
33 public synchronized static EventQueue
Instance ()
35 if (maInstance
== null)
36 maInstance
= new EventQueue ();
40 public void addEvent (Runnable aEvent
)
42 synchronized (maMonitor
)
45 System
.out
.println ("queing regular event " + aEvent
);
46 maRegularQueue
.addLast (aEvent
);
52 public void addDisposingEvent (Runnable aEvent
)
54 if (mbHandleDisposingEventsSynchronous
)
57 synchronized (maMonitor
)
60 System
.out
.println ("queing disposing event " + aEvent
);
61 maDisposingQueue
.addLast (aEvent
);
69 maMonitor
= new Boolean (true);
70 maRegularQueue
= new LinkedList
<Runnable
>();
71 maDisposingQueue
= new LinkedList
<Runnable
>();
72 new Thread(this, "AWB.EventQueue").start();
76 /// This thread's main method: deliver all events
79 // in an infinite loop, check for events to deliver, then
80 // wait on lock (which will be notified when new events arrive)
83 Runnable aEvent
= null;
86 synchronized (maMonitor
)
88 if (maDisposingQueue
.size() > 0)
90 aEvent
= maDisposingQueue
.removeFirst();
92 System
.out
.println ("delivering disposing event " + aEvent
);
94 else if (maRegularQueue
.size() > 0)
96 aEvent
= maRegularQueue
.removeFirst();
98 System
.out
.println ("delivering regular event " + aEvent
);
112 "caught exception during event delivery: " + e
);
117 while( aEvent
!= null );
121 synchronized (maMonitor
)
129 System
.err
.println("Can't wait!");
135 private static EventQueue maInstance
= null;
136 private Object maMonitor
;
137 private LinkedList
<Runnable
> maRegularQueue
;
138 private LinkedList
<Runnable
> maDisposingQueue
;