本文整理匯總了Java中org.osgi.framework.FrameworkUtil類的典型用法代碼示例。如果您正苦於以下問題:Java FrameworkUtil類的具體用法?Java FrameworkUtil怎麽用?Java FrameworkUtil使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FrameworkUtil類屬於org.osgi.framework包,在下文中一共展示了FrameworkUtil類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: runContainerResolverJob
import org.osgi.framework.FrameworkUtil; //導入依賴的package包/類
public static void runContainerResolverJob(IJavaProject javaProject) {
IEclipseContext context = EclipseContextFactory.getServiceContext(
FrameworkUtil.getBundle(BuildPath.class).getBundleContext());
final IEclipseContext childContext =
context.createChild(LibraryClasspathContainerResolverJob.class.getName());
childContext.set(IJavaProject.class, javaProject);
Job job =
ContextInjectionFactory.make(LibraryClasspathContainerResolverJob.class, childContext);
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
childContext.dispose();
}
});
job.schedule();
}
示例2: getDrls
import org.osgi.framework.FrameworkUtil; //導入依賴的package包/類
@Override
public List<DrlConfiguration> getDrls() {
List<DrlConfiguration> list = new LinkedList<DrlConfiguration>();
Enumeration<URL> baseRules = FrameworkUtil.getBundle(getClass()).findEntries("/src/main/resources/base-rules", "*.drl", true);
Enumeration<URL> genRules = FrameworkUtil.getBundle(getClass()).findEntries("/src/main/resources/gen-rules", "*.drl", true);
if(baseRules == null) {
throw new RuntimeException("Error, base-rules folder shouldn't be empty.");
}
if(genRules == null) {
throw new RuntimeException("Error, gen-rules folder shouldn't be empty. Have you forget to generate the rules?");
}
List<URL> loadedDrls = Collections.list(baseRules);
loadedDrls.addAll(Collections.list(genRules));
for (URL url : loadedDrls) {
addInputStreamToList(url, list);
}
return list;
}
示例3: getDtables
import org.osgi.framework.FrameworkUtil; //導入依賴的package包/類
@Override
public List<DtableConfiguration> getDtables() {
List<DtableConfiguration> dtableList = new LinkedList<DtableConfiguration>();
List<URL> urls = Collections
.list(FrameworkUtil.getBundle(getClass()).findEntries("/src/main/resources/dtables/", "*.xlsx", true));
for (URL url : urls) {
try {
dtableList.add(new DtableConfiguration(url.openStream(), url.getFile()));
} catch (IOException e) {
e.printStackTrace();
}
}
return dtableList;
}
示例4: installBundle
import org.osgi.framework.FrameworkUtil; //導入依賴的package包/類
/**
* Installs the specified jar bundle and adds the Bundle instance to the local bundle vector {@link #getBundleVector()}.
* @param bundleJarFilePath the bundle jar file path
*/
public void installBundle(String bundleJarFilePath) {
Bundle bundle = null;
try {
BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
bundle = bundleContext.installBundle(bundleJarFilePath);
if (this.debug) System.out.println("=> + " + bundle.getSymbolicName() + " installed.");
} catch (BundleException bEx) {
bEx.printStackTrace();
}
// --- Remind this bundle ---------------
if (bundle!=null) this.getBundleVector().addElement(bundle);
}
示例5: createFilter
import org.osgi.framework.FrameworkUtil; //導入依賴的package包/類
protected static Filter createFilter ( final String operand, final Filter... filters ) throws InvalidSyntaxException
{
final StringBuilder sb = new StringBuilder ();
sb.append ( "(" );
sb.append ( operand );
for ( final Filter filter : filters )
{
sb.append ( filter.toString () );
}
sb.append ( ")" );
return FrameworkUtil.createFilter ( sb.toString () );
}
示例6: MailEventHandler
import org.osgi.framework.FrameworkUtil; //導入依賴的package包/類
public MailEventHandler ( final String id, final MailSender sender, final PipeService pipeService, final int retries ) throws Exception
{
this.bundle = FrameworkUtil.getBundle ( MailHandlerFactory.class );
this.sender = sender;
this.retries = retries;
final String pipeName = "mail." + id;
try
{
this.producer = pipeService.createProducer ( pipeName );
this.workerHandle = pipeService.createWorker ( pipeName, this.mailWorker );
}
catch ( final Exception e )
{
if ( this.sender != null )
{
this.sender.dispose ();
this.sender = null;
}
}
}
示例7: openQueueMonitor
import org.osgi.framework.FrameworkUtil; //導入依賴的package包/類
public static void openQueueMonitor(Class<? extends StatusBean> beanClass,
final String queueName,
final String topicName,
final String submissionQueueName,
String partName) throws PartInitException, UnsupportedEncodingException {
String bundle = FrameworkUtil.getBundle(beanClass).getSymbolicName();
String bean = beanClass.getName();
String sqn = queueName;
String stn = topicName;
String submit = submissionQueueName;
String queueViewId = QueueViews.createSecondaryId(CommandConstants.getScanningBrokerUri(), bundle,bean, sqn, stn, submit);
if (partName!=null) queueViewId = queueViewId+"partName="+partName;
try {
PageUtil.getPage().showView(QueueViews.getQueueViewID(), queueViewId, IWorkbenchPage.VIEW_ACTIVATE);
} catch (PartInitException e) {
ErrorDialog.openError(Display.getDefault().getActiveShell(), "Cannot open view", "Cannot open view "+queueViewId,
new Status(Status.ERROR, "org.eclipse.scanning.event.ui", e.getMessage()));
throw e;
}
}
示例8: before
import org.osgi.framework.FrameworkUtil; //導入依賴的package包/類
@Before
public void before() throws Exception {
assertAllBundlesResolved();
// Track ArtifactInstaller service ONLY from bundle org.osc.installer
Bundle installerBundle = findBundle("osc-installer");
Filter artifactInstallerTrackerFilter = FrameworkUtil.createFilter(String.format("(&(objectClass=%s)(service.bundleid=%d))", ArtifactInstaller.class.getName(), installerBundle.getBundleId()));
this.artifactInstallerTracker = new ServiceTracker<>(this.bundleContext, artifactInstallerTrackerFilter, null);
this.artifactInstallerTracker.open();
// Wait up to 5 seconds for ArtifactInstaller to appear
ArtifactInstaller artifactInstaller = this.artifactInstallerTracker.waitForService(5000);
if (artifactInstaller == null) {
fail("ArtifactInstaller service not available within 5 seconds");
}
this.fwkInstallerTracker = new ServiceTracker<>(this.bundleContext, FrameworkInstaller.class, null);
this.fwkInstallerTracker.open();
}
示例9: dispose
import org.osgi.framework.FrameworkUtil; //導入依賴的package包/類
@Override
public void dispose() {
super.dispose();
BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
ServiceReference<IDebugService> serviceReference = (ServiceReference<IDebugService>) bundleContext.getServiceReference(IDebugService.class.getName());
if(serviceReference != null){
IDebugService debugService = (IDebugService)bundleContext.getService(serviceReference);
debugService.deleteDebugFiles();
}
Properties properties = ConfigFileReader.INSTANCE.getCommonConfigurations();
try {
killPortProcess(properties);
} catch (IOException e) {
logger.debug("Socket is not closed.");
}
}
示例10: getService
import org.osgi.framework.FrameworkUtil; //導入依賴的package包/類
/**
* Returns the reference to the implementation of the specified service.
*
* @param serviceClass service class
* @param <T> type of service
* @return service implementation
*/
public static <T> T getService(Class<T> serviceClass) {
BundleContext bc = FrameworkUtil.getBundle(serviceClass).getBundleContext();
if (bc != null) {
ServiceReference<T> reference = bc.getServiceReference(serviceClass);
if (reference != null) {
T impl = bc.getService(reference);
if (impl != null) {
return impl;
}
}
}
throw new ServiceNotFoundException("Service " + serviceClass.getName() + " not found");
}
示例11: getGlobalInstances
import org.osgi.framework.FrameworkUtil; //導入依賴的package包/類
/**
* Retrieves Global instances of Specific Service in the Bundle. This is
* adapted from org.opendaylight.controller.sal.utils.ServiceHelper
*
* @param clazz - Class associated with the Class loader.
* @param bundle - Bundle
* @return an array of objects that implement the services specified by the clazz
*/
public static Object[] getGlobalInstances(Class<?> clazz, Object bundle) {
Object instances[] = null;
try {
BundleContext bCtx = FrameworkUtil.getBundle(bundle.getClass())
.getBundleContext();
ServiceReference[] services = bCtx.getServiceReferences(clazz
.getName(), null);
if (services != null) {
instances = new Object[services.length];
for (int i = 0; i < services.length; i++) {
instances[i] = bCtx.getService(services[i]);
}
}
} catch (Exception e) {
LOG.error("Instance reference is NULL");
}
return instances;
}
示例12: emit
import org.osgi.framework.FrameworkUtil; //導入依賴的package包/類
@Override
protected void emit(
ServiceReference<NestedCollectionRouter> serviceReference,
Emitter<String> emitter) {
Bundle bundle = FrameworkUtil.getBundle(
NestedCollectionRouterManagerImpl.class);
BundleContext bundleContext = bundle.getBundleContext();
CustomServiceReferenceMapper<NestedCollectionRouter>
customServiceReferenceMapper = new CustomServiceReferenceMapper<>(
bundleContext, NestedCollectionRouter.class);
NestedCollectionRouter nestedCollectionRouter =
bundleContext.getService(serviceReference);
Class<?> genericClass = getGenericClassFromPropertyOrElse(
serviceReference, PARENT_MODEL_CLASS,
() -> getTypeParamOrFail(
nestedCollectionRouter, NestedCollectionRouter.class, 1));
customServiceReferenceMapper.map(
serviceReference,
key -> emitter.emit(key + "-" + genericClass.getName()));
}
示例13: getService
import org.osgi.framework.FrameworkUtil; //導入依賴的package包/類
/**
* Looks up an OSGi service. If the service is not yet available, this method will wait for 60 seconds for the service to become available. If the service
* does not appear in this period, a ServiceException is thrown.
*
* @param serviceClass
* The service interface of the service to look up
* @param timeoutInMillis
* The amount of time in milliseconds to wait for the service to become available
* @return an implementation of the given service interface
* @throws a
* ServiceException, if the service couldn't be found in the OSGi service registry
*/
public static <T> T getService(Class<T> serviceClass, long timeoutInMillis) {
BundleContext ctx = FrameworkUtil.getBundle(ServiceUtil.class).getBundleContext();
ServiceTracker<T, T> tracker = new ServiceTracker<>(ctx, serviceClass, null);
tracker.open();
T service = null;
try {
service = tracker.waitForService(timeoutInMillis);
} catch (InterruptedException e) {
throw new ServiceException("Interrupted while waiting for the service " + serviceClass.getName(), e);
}
tracker.close();
if (service != null) {
return service;
} else {
throw new ServiceException("Service " + serviceClass.getName() + " not available");
}
}
示例14: execute
import org.osgi.framework.FrameworkUtil; //導入依賴的package包/類
@Override public Object execute() throws Exception {
BundleContext context = FrameworkUtil.getBundle(GithubEmittersCommand.class).getBundleContext();
Collection<ServiceReference<GithubPullRequestEmitter>> references = context
.getServiceReferences(GithubPullRequestEmitter.class, "(github-repository=*)");
// Build the table
ShellTable table = new ShellTable();
table.column("Repository").alignLeft();
table.column("Type").alignLeft();
table.emptyTableText("No GitHub revision emitters available");
for (ServiceReference<GithubPullRequestEmitter> reference : references) {
GithubPullRequestEmitter service = context.getService(reference);
String repository = (String) reference.getProperty("github-repository");
String type = service instanceof PullRequestMonitor ? "pull requests" : "unknown";
table.addRow().addContent(repository, type);
context.ungetService(reference);
}
// Print it
table.print(System.out);
return null;
}
示例15: getRegions
import org.osgi.framework.FrameworkUtil; //導入依賴的package包/類
public static List<Region> getRegions() {
BundleContext bundleContext = FrameworkUtil.getBundle(
UseJNDI.class).getBundleContext();
ServiceTracker<RegionLocalService, RegionLocalService> tracker =
new ServiceTracker<>(bundleContext, RegionLocalService.class, null);
tracker.open();
RegionLocalService regionLocalService = tracker.getService();
try {
List<Region> regions = regionLocalService.getRegions(
0, getRegionsCount());
return regions;
}
catch (Exception e) {
e.printStackTrace();
}
tracker.close();
return null;
}