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 synchronization.
30 private boolean mbVerbose
= false;
31 private 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 maRegularQueue
= new LinkedList
<Runnable
>();
70 maDisposingQueue
= new LinkedList
<Runnable
>();
71 new Thread(this, "AWB.EventQueue").start();
75 /// This thread's main method: deliver all events
78 // in an infinite loop, check for events to deliver, then
79 // wait on lock (which will be notified when new events arrive)
82 Runnable aEvent
= null;
85 synchronized (maMonitor
)
87 if (maDisposingQueue
.size() > 0)
89 aEvent
= maDisposingQueue
.removeFirst();
91 System
.out
.println ("delivering disposing event " + aEvent
);
93 else if (maRegularQueue
.size() > 0)
95 aEvent
= maRegularQueue
.removeFirst();
97 System
.out
.println ("delivering regular event " + aEvent
);
111 "caught exception during event delivery: " + e
);
116 while( aEvent
!= null );
120 synchronized (maMonitor
)
128 System
.err
.println("Can't wait!");
134 private static EventQueue maInstance
= null;
135 private final Object maMonitor
= new Object();
136 private final LinkedList
<Runnable
> maRegularQueue
;
137 private final LinkedList
<Runnable
> maDisposingQueue
;