-
- private static class BundleKey {
- Bundle bundle;
- BundleContext bundleContext;
-
- public BundleKey(Bundle bundle) {
- this.bundle = bundle;
- }
-
- BundleContext getBundleContext() {
- if(bundleContext != null) {
- return bundleContext;
- }
-
- // If the bundle isn't activated yet, it may not have a BundleContext yet so busy wait for it.
- Stopwatch timer = Stopwatch.createStarted();
- while(timer.elapsed(TimeUnit.MILLISECONDS) <= BUNDLE_CONTEXT_TIMEOUT) {
- bundleContext = bundle.getBundleContext();
- if(bundleContext != null) {
- return bundleContext;
- }
-
- Uninterruptibles.sleepUninterruptibly(10, TimeUnit.MILLISECONDS);
- }
-
- return null;
- }
-
- @Override
- public int hashCode() {
- return (int) bundle.getBundleId();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (getClass() != obj.getClass()) {
- return false;
- }
- BundleKey other = (BundleKey) obj;
- return bundle.getBundleId() == other.bundle.getBundleId();
- }
- }