osgi - 检测正在运行的 Equinox IApplication ID
问题描述
我有带有 GUI (JavaFX) 的 RCP E4 应用程序。它还包含几个没有 GUI 的 IApplication 实例。问题是,有一些自动运行的 DS 服务,我想检测从这些 DS 服务中启动的应用程序(IApplication/产品 ID)。这可能吗?我能得到什么信息?
解决方案
IApplicationContext
包含许多方法来告诉您它所谓的“品牌应用程序” 。
getBrandingApplication
为您提供正在运行的应用程序的 ID(例如,对于 e4,总是 org.eclipse.e4.ui.workbench.swt.E4Application`)。
getBrandingId
是产品编号。
getBrandingName
是为产品指定的名称。
在 e4 应用程序中,您只需注入IApplicationContext
. IApplication
应用程序被赋予 cpntext 作为 start 方法的参数。也可以通过搜索 OSGi 服务找到:
IApplicationContext getApplicationContext(BundleContext context) {
Collection<ServiceReference<IApplicationContext>> references;
try {
references = context.getServiceReferences(IApplicationContext.class, "(eclipse.application.type=main.thread)");
} catch (InvalidSyntaxException e) {
return null;
}
if (references == null || references.isEmpty())
return null;
// assumes the application context is available as a service
ServiceReference<IApplicationContext> firstRef = references.iterator().next();
IApplicationContext result = context.getService(firstRef);
if (result != null) {
context.ungetService(firstRef);
return result;
}
return null;
}
(以上代码改编自org.eclipse.core.internal.runtimeInternalPlatform
)
推荐阅读
- python - 我在哪里将密码存储在 AWS 沙箱中,用于通过 python 脚本连接到雪花的用户
- excel - Selenium VBA中的GetAttribute用于样式
- api - PUT 或 PATCH,哪个更快,为什么?
- sql - 根据第一个字段的值使用不同字段进行 SQL 排序
- python - 键错误:'客户'
- reactjs - 使用 msal.js 时 AcquireTokenSilent 失败
- python - 是否可以在后台运行 PyAutoGUI?
- python - 是否可以将预训练的 lda 模型加载到 gensim 中?
- glob - 全局匹配在 Storybook 配置中不起作用?
- go - golang json.Unmarshal 到 struct []byte