本文整理汇总了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;
}