blob: bffa18dcba49a97c8c50ceca46e04df99656546e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/*******************************************************************************
* Copyright (c) 2011, 2012 Wind River Systems, Inc. and others. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
package org.eclipse.tcf.te.tcf.core.internal;
import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.tcf.protocol.Protocol;
import org.eclipse.tcf.te.tcf.core.Tcf;
import org.eclipse.tcf.te.tcf.core.activator.CoreBundleActivator;
/**
* Class loaded by the TCF core framework when the framework is fired up. The static
* constructor of the class will trigger whatever is necessary in this case.
* <p>
* <b>Note:</b> This will effectively trigger {@link CoreBundleActivator#start(org.osgi.framework.BundleContext)}
* to be called.
*/
public class Startup {
// Atomic boolean to store the started state of the TCF core framework
/* default */ final static AtomicBoolean STARTED = new AtomicBoolean(false);
static {
setStarted(true);
}
/**
* Set the core framework started state to the given state.
*
* @param started <code>True</code> when the framework is started, <code>false</code> otherwise.
*/
public static final void setStarted(boolean started) {
STARTED.set(started);
// Start/Stop should be called in the TCF protocol dispatch thread
if (Protocol.getEventQueue() != null) {
// Catch IllegalStateException: TCF event dispatcher has shut down
try {
Runnable runnable = new Runnable() {
@Override
public void run() {
if (STARTED.get()) Tcf.start(); else Tcf.stop();
}
};
if (Protocol.isDispatchThread()) runnable.run();
else Protocol.invokeAndWait(runnable);
} catch (IllegalStateException e) {
if (!STARTED.get() && "TCF event dispatcher has shut down".equals(e.getLocalizedMessage())) { //$NON-NLS-1$
// ignore the exception on shutdown
} else {
// re-throw in any other case
throw e;
}
}
}
}
/**
* Returns if or if not the core framework has been started.
*
* @return <code>True</code> when the framework is started, <code>false</code> otherwise.
*/
public static final boolean isStarted() {
return STARTED.get();
}
}
|