Mercurial > projects > dwt-addons
comparison dwtx/core/internal/jobs/JobOSGiUtils.d @ 122:9d0585bcb7aa
Add core.jobs package
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 12 Aug 2008 02:34:21 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
121:c0304616ea23 | 122:9d0585bcb7aa |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2005, 2007 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.core.internal.jobs.JobOSGiUtils; | |
14 | |
15 import dwt.dwthelper.utils; | |
16 | |
17 // import org.osgi.framework.Bundle; | |
18 // import org.osgi.framework.BundleContext; | |
19 // import org.osgi.service.packageadmin.PackageAdmin; | |
20 // import org.osgi.util.tracker.ServiceTracker; | |
21 | |
22 import dwtx.core.runtime.jobs.IJobManager; | |
23 // import dwtx.osgi.service.debug.DebugOptions; | |
24 | |
25 /** | |
26 * The class contains a set of helper methods for the runtime Jobs plugin. | |
27 * The following utility methods are supplied: | |
28 * - provides access to debug options | |
29 * - provides some bundle discovery functionality | |
30 * | |
31 * The closeServices() method should be called before the plugin is stopped. | |
32 * | |
33 * @since dwtx.core.jobs 3.2 | |
34 */ | |
35 class JobOSGiUtils { | |
36 // private ServiceTracker debugTracker = null; | |
37 // private ServiceTracker bundleTracker = null; | |
38 | |
39 private static /+final+/ JobOSGiUtils singleton; | |
40 | |
41 /** | |
42 * Accessor for the singleton instance | |
43 * @return The JobOSGiUtils instance | |
44 */ | |
45 public static synchronized JobOSGiUtils getDefault() { | |
46 if( singleton is null ){ | |
47 singleton = new JobOSGiUtils(); | |
48 } | |
49 return singleton; | |
50 } | |
51 | |
52 /** | |
53 * Private constructor to block instance creation. | |
54 */ | |
55 private this() { | |
56 // super(); | |
57 } | |
58 | |
59 void openServices() { | |
60 implMissing(__FILE__,__LINE__); | |
61 // BundleContext context = JobActivator.getContext(); | |
62 // if (context is null) { | |
63 // if (JobManager.DEBUG) | |
64 // JobMessages.message("JobsOSGiUtils called before plugin started"); //$NON-NLS-1$ | |
65 // return; | |
66 // } | |
67 // | |
68 // debugTracker = new ServiceTracker(context, DebugOptions.class.getName(), null); | |
69 // debugTracker.open(); | |
70 // | |
71 // bundleTracker = new ServiceTracker(context, PackageAdmin.class.getName(), null); | |
72 // bundleTracker.open(); | |
73 } | |
74 | |
75 void closeServices() { | |
76 implMissing(__FILE__,__LINE__); | |
77 // if (debugTracker !is null) { | |
78 // debugTracker.close(); | |
79 // debugTracker = null; | |
80 // } | |
81 // if (bundleTracker !is null) { | |
82 // bundleTracker.close(); | |
83 // bundleTracker = null; | |
84 // } | |
85 } | |
86 | |
87 public bool getBooleanDebugOption(String option, bool defaultValue) { | |
88 implMissing(__FILE__,__LINE__); | |
89 return false; | |
90 // if (debugTracker is null) { | |
91 // if (JobManager.DEBUG) | |
92 // JobMessages.message("Debug tracker is not set"); //$NON-NLS-1$ | |
93 // return defaultValue; | |
94 // } | |
95 // DebugOptions options = (DebugOptions) debugTracker.getService(); | |
96 // if (options !is null) { | |
97 // String value = options.getOption(option); | |
98 // if (value !is null) | |
99 // return value.equalsIgnoreCase("true"); //$NON-NLS-1$ | |
100 // } | |
101 // return defaultValue; | |
102 } | |
103 | |
104 /** | |
105 * Returns the bundle id of the bundle that contains the provided object, or | |
106 * <code>null</code> if the bundle could not be determined. | |
107 */ | |
108 public String getBundleId(Object object) { | |
109 implMissing(__FILE__,__LINE__); | |
110 // if (bundleTracker is null) { | |
111 // if (JobManager.DEBUG) | |
112 // JobMessages.message("Bundle tracker is not set"); //$NON-NLS-1$ | |
113 // return null; | |
114 // } | |
115 // PackageAdmin packageAdmin = (PackageAdmin) bundleTracker.getService(); | |
116 // if (object is null) | |
117 // return null; | |
118 // if (packageAdmin is null) | |
119 // return null; | |
120 // Bundle source = packageAdmin.getBundle(object.getClass()); | |
121 // if (source !is null && source.getSymbolicName() !is null) | |
122 // return source.getSymbolicName(); | |
123 return null; | |
124 } | |
125 | |
126 /** | |
127 * Calculates whether the job plugin should set worker threads to be daemon | |
128 * threads. When workers are daemon threads, the job plugin does not need | |
129 * to be explicitly shut down because the VM can exit while workers are still | |
130 * alive. | |
131 * @return <code>true</code> if all worker threads should be daemon threads, | |
132 * and <code>false</code> otherwise. | |
133 */ | |
134 bool useDaemonThreads() { | |
135 implMissing(__FILE__,__LINE__); | |
136 return false; | |
137 // BundleContext context = JobActivator.getContext(); | |
138 // if (context is null) { | |
139 // //we are running stand-alone, so consult global system property | |
140 // String value = System.getProperty(IJobManager.PROP_USE_DAEMON_THREADS); | |
141 // //default to use daemon threads if property is absent | |
142 // if (value is null) | |
143 // return true; | |
144 // return "true".equalsIgnoreCase(value); //$NON-NLS-1$ | |
145 // } | |
146 // //only use daemon threads if the property is defined | |
147 // final String value = context.getProperty(IJobManager.PROP_USE_DAEMON_THREADS); | |
148 // //if value is absent, don't use daemon threads to maintain legacy behaviour | |
149 // if (value is null) | |
150 // return false; | |
151 // return "true".equalsIgnoreCase(value); //$NON-NLS-1$ | |
152 } | |
153 } |