本文整理汇总了Java中org.osgi.service.packageadmin.PackageAdmin.refreshPackages方法的典型用法代码示例。如果您正苦于以下问题:Java PackageAdmin.refreshPackages方法的具体用法?Java PackageAdmin.refreshPackages怎么用?Java PackageAdmin.refreshPackages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.osgi.service.packageadmin.PackageAdmin
的用法示例。
在下文中一共展示了PackageAdmin.refreshPackages方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: refreshBundle
import org.osgi.service.packageadmin.PackageAdmin; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public void refreshBundle(Bundle changedBundle, BundleContext context) {
try {
ServiceReference ref = context.getServiceReference(PackageAdmin.class.getName());
PackageAdmin pa = (ref == null) ? null : (PackageAdmin) context.getService(ref);
System.out.println("Refreshing bundle " + changedBundle);
pa.refreshPackages(new Bundle[] { changedBundle });
} catch (Throwable e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
}
示例2: refreshDependentBundles
import org.osgi.service.packageadmin.PackageAdmin; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public void refreshDependentBundles(Bundle changedBundle, BundleContext context) {
try {
long myId = changedBundle.getBundleId();
Dictionary<String, String> headers = changedBundle.getHeaders();
String exported = headers.get("Export-Package") + ",";
Bundle[] bundles = context.getBundles();
Set<Bundle> toRefresh = new HashSet<Bundle>();
for (int i = 0; i < bundles.length; i++) {
Bundle bundle = bundles[i];
if (bundle.getBundleId() != myId) {
if (!bundle.getSymbolicName().startsWith("org.apache")) {
Dictionary<String, String> headers2 = bundle.getHeaders();
String imported = headers2.get("Import-Package");
String[] packages = imported.split(",");
for (int j = 0; j < packages.length; j++) {
String importedPackage = packages[j].trim();
importedPackage = importedPackage.split(";")[0];// no version - for now
if (exported.contains(importedPackage)) {
toRefresh.add(bundle);
}
}
}
}
}
ServiceReference ref = context.getServiceReference(PackageAdmin.class.getName());
PackageAdmin pa = (ref == null) ? null : (PackageAdmin) context.getService(ref);
System.out.println(pa);
Bundle[] refreshList = toRefresh.toArray(new Bundle[0]);
for (Bundle bundleToRefresh : refreshList) {
System.out.println("Refreshing dependend bundle " + bundleToRefresh);
}
pa.refreshPackages(refreshList);
} catch (Throwable e) {
System.err.println(e.getMessage());
e.printStackTrace();
}
}