1 11 package org.eclipse.core.internal.jobs; 12 13 import org.eclipse.core.runtime.jobs.IJobManager; 14 import org.eclipse.osgi.service.debug.DebugOptions; 15 import org.osgi.framework.Bundle; 16 import org.osgi.framework.BundleContext; 17 import org.osgi.service.packageadmin.PackageAdmin; 18 import org.osgi.util.tracker.ServiceTracker; 19 20 30 class JobOSGiUtils { 31 private ServiceTracker debugTracker = null; 32 private ServiceTracker bundleTracker = null; 33 34 private static final JobOSGiUtils singleton = new JobOSGiUtils(); 35 36 40 public static JobOSGiUtils getDefault() { 41 return singleton; 42 } 43 44 47 private JobOSGiUtils() { 48 super(); 49 } 50 51 void openServices() { 52 BundleContext context = JobActivator.getContext(); 53 if (context == null) { 54 if (JobManager.DEBUG) 55 JobMessages.message("JobsOSGiUtils called before plugin started"); return; 57 } 58 59 debugTracker = new ServiceTracker(context, DebugOptions.class.getName(), null); 60 debugTracker.open(); 61 62 bundleTracker = new ServiceTracker(context, PackageAdmin.class.getName(), null); 63 bundleTracker.open(); 64 } 65 66 void closeServices() { 67 if (debugTracker != null) { 68 debugTracker.close(); 69 debugTracker = null; 70 } 71 if (bundleTracker != null) { 72 bundleTracker.close(); 73 bundleTracker = null; 74 } 75 } 76 77 public boolean getBooleanDebugOption(String option, boolean defaultValue) { 78 if (debugTracker == null) { 79 if (JobManager.DEBUG) 80 JobMessages.message("Debug tracker is not set"); return defaultValue; 82 } 83 DebugOptions options = (DebugOptions) debugTracker.getService(); 84 if (options != null) { 85 String value = options.getOption(option); 86 if (value != null) 87 return value.equalsIgnoreCase("true"); } 89 return defaultValue; 90 } 91 92 96 public String getBundleId(Object object) { 97 if (bundleTracker == null) { 98 if (JobManager.DEBUG) 99 JobMessages.message("Bundle tracker is not set"); return null; 101 } 102 PackageAdmin packageAdmin = (PackageAdmin) bundleTracker.getService(); 103 if (object == null) 104 return null; 105 if (packageAdmin == null) 106 return null; 107 Bundle source = packageAdmin.getBundle(object.getClass()); 108 if (source != null && source.getSymbolicName() != null) 109 return source.getSymbolicName(); 110 return null; 111 } 112 113 121 boolean useDaemonThreads() { 122 BundleContext context = JobActivator.getContext(); 123 if (context == null) { 124 String value = System.getProperty(IJobManager.PROP_USE_DAEMON_THREADS); 126 if (value == null) 128 return true; 129 return "true".equalsIgnoreCase(value); } 131 final String value = context.getProperty(IJobManager.PROP_USE_DAEMON_THREADS); 133 if (value == null) 135 return false; 136 return "true".equalsIgnoreCase(value); } 138 } 139 | Popular Tags |