Java Code Examples for org.osgi.framework.BundleEvent#getBundle()

The following examples show how to use org.osgi.framework.BundleEvent#getBundle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Activator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public @Override void bundleChanged(BundleEvent event) {
        Bundle bundle = event.getBundle();
        switch (event.getType()) {
        case BundleEvent.STARTED:
//            System.err.println("started " + bundle.getSymbolicName());
            Dictionary<?,?> headers = bundle.getHeaders();
            load(queue.offer(bundle, provides(headers), requires(headers), needs(headers)));
            break;
        case BundleEvent.STOPPED:
//            System.err.println("stopped " + bundle.getSymbolicName());
            if (framework.getState() == Bundle.STOPPING) {
//                System.err.println("fwork stopping during " + bundle.getSymbolicName());
//                ActiveQueue.stop();
            } else {
                unload(queue.retract(bundle));
            }
            break;
        }
    }
 
Example 2
Source File: ManagementPermissionsAdder.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
@Override
public void bundleChanged(BundleEvent event) {
    Bundle bundle = event.getBundle();
    try {
        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);

        if (event.getType() == BundleEvent.STARTED) {
            addUIPermissionFromBundle(bundle);
        }
    } catch (Exception e) {
        log.error("Error occured when processing component xml in bundle " +
                bundle.getSymbolicName(), e);
    }
}
 
Example 3
Source File: AutomationResourceBundlesEventQueue.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Depending on the action committed against the bundle supplier of automation resources, this method performs the
 * appropriate action - calls for it's host bundles:
 * <ul>
 * {@link AbstractResourceBundleProvider#processAutomationProviderUninstalled(Bundle)} method
 * </ul>
 * or
 * <ul>
 * {@link AbstractResourceBundleProvider#processAutomationProvider(Bundle)} method
 * </ul>
 *
 * @param event for a bundle tracked by the {@code BundleTracker}. It has been for adding, modifying or removing the
 *            bundle.
 */
protected void processBundleChanged(BundleEvent event) {
    Bundle bundle = event.getBundle();
    if (HostFragmentMappingUtil.isFragmentBundle(bundle)) {
        for (Bundle host : HostFragmentMappingUtil.returnHostBundles(bundle)) {
            provider.processAutomationProvider(host);
        }
    } else {
        switch (event.getType()) {
            case BundleEvent.UNINSTALLED:
                provider.processAutomationProviderUninstalled(bundle);
                break;
            default:
                provider.processAutomationProvider(bundle);
        }
    }
}
 
Example 4
Source File: AutomationResourceBundlesEventQueue.java    From openhab-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Depending on the action committed against the bundle supplier of automation resources, this method performs the
 * appropriate action - calls for it's host bundles:
 * <ul>
 * {@link AbstractResourceBundleProvider#processAutomationProviderUninstalled(Bundle)} method
 * </ul>
 * or
 * <ul>
 * {@link AbstractResourceBundleProvider#processAutomationProvider(Bundle)} method
 * </ul>
 *
 * @param event for a bundle tracked by the {@code BundleTracker}. It has been for adding, modifying or removing the
 *            bundle.
 */
protected void processBundleChanged(BundleEvent event) {
    Bundle bundle = event.getBundle();
    if (HostFragmentMappingUtil.isFragmentBundle(bundle)) {
        for (Bundle host : HostFragmentMappingUtil.returnHostBundles(bundle)) {
            provider.processAutomationProvider(host);
        }
    } else {
        switch (event.getType()) {
            case BundleEvent.UNINSTALLED:
                provider.processAutomationProviderUninstalled(bundle);
                break;
            default:
                provider.processAutomationProvider(bundle);
        }
    }
}
 
Example 5
Source File: ManagementPermissionsAdder.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
@Override
public void bundleChanged(BundleEvent event) {
    Bundle bundle = event.getBundle();
    try {
        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);

        if (event.getType() == BundleEvent.STARTED) {
            addUIPermissionFromBundle(bundle);
        }
    } catch (Exception e) {
        log.error("Error occured when processing component xml in bundle " +
                bundle.getSymbolicName(), e);
    }
}
 
Example 6
Source File: Spin.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void bundleChanged(BundleEvent ev) {
  Long    id = new Long(ev.getBundle().getBundleId());
  synchronized(bundles) {
    BX bx = bundles.get(id);

    switch(ev.getType()) {
    case BundleEvent.INSTALLED:
      if(bx == null) {
        bx = new BX(this, ev.getBundle());
        bundles.put(id, bx);
        bxNeedRecalc = true;
      }
      break;
    case BundleEvent.UNINSTALLED:
      if(bx != null) {
        bundles.remove(id);
        bxNeedRecalc = true;
      }
      break;
    }
  }
  repaint();
}
 
Example 7
Source File: SCR.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Process bundle components when it starts.
 */
public void bundleChanged(BundleEvent event) {
  postponeCheckin();
  try {
    final Bundle bundle = event.getBundle();

    switch (event.getType()) {
    case BundleEvent.LAZY_ACTIVATION:
      lazy.add(bundle);
      processBundle(bundle);
      break;
    case BundleEvent.STARTED:
      if (!lazy.remove(bundle)) {
        processBundle(bundle);
      }
      break;
    case BundleEvent.STOPPING:
      lazy.remove(bundle);
      removeBundle(bundle, ComponentConstants.DEACTIVATION_REASON_BUNDLE_STOPPED);
      break;
    }
  } finally {
    postponeCheckout();
  }
}
 
Example 8
Source File: UIBundleDeployer.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
public void bundleChanged(BundleEvent event) {
    Bundle bundle = event.getBundle();
    if(log.isDebugEnabled()){
        log.debug("Received new bundle event  : " + event.getType());
    }
    try {
        switch (event.getType()) {
            //TODO need to fix here.
            case BundleEvent.RESOLVED:
                if(log.isDebugEnabled()){
                    log.debug("Add ui component event received....");
                }
                processUIBundle(bundle, CarbonConstants.ADD_UI_COMPONENT);
                break;

            case BundleEvent.UNRESOLVED:
                if(log.isDebugEnabled()){
                log.debug("Remove ui component event received....");
                }
                processUIBundle(bundle, CarbonConstants.REMOVE_UI_COMPONENT);
                break;
        }
    } catch (Exception e) {
        log.error("Error occured when processing component xml in bundle " + bundle.getSymbolicName(), e);
        e.printStackTrace();
    }
}
 
Example 9
Source File: Extender.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void bundleChanged(BundleEvent event) {
  Bundle bundle = event.getBundle();
  if (event.getType() == BundleEvent.RESOLVED) {
    checkBundle(bundle);
  } else if (event.getType() == BundleEvent.STARTED) {
    checkBundleScriptEngines(bundle);
  }
}
 
Example 10
Source File: OSGIServiceLoader.java    From incubator-tamaya with Apache License 2.0 5 votes vote down vote up
@Override
public void bundleChanged(BundleEvent bundleEvent) {
    // Parse and createObject metadata when installed
    Bundle bundle = bundleEvent.getBundle();
    if (bundleEvent.getType() == BundleEvent.STARTED) {
        checkAndLoadBundle(bundle);
    } else if (bundleEvent.getType() == BundleEvent.STOPPED) {
        checkAndUnloadBundle(bundle);
    }
}
 
Example 11
Source File: JRxmlFileBundleListener.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public void bundleChanged(BundleEvent bundleEvent) {
    Bundle bundle = bundleEvent.getBundle();
    try {
        if (bundleEvent.getType() == BundleEvent.STARTED) {
            addJrXmlToRegistry(bundle);
        }
    } catch (Exception e) {
        log.error("Error occurred when putting jrXml file to registry in bundle "
                + bundle.getSymbolicName(), e);
    }
}
 
Example 12
Source File: BundleTracker.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * {@code BundleListener} method for the {@code BundleTracker} class.
 * This method must NOT be synchronized to avoid deadlock potential.
 * 
 * @param event {@code BundleEvent} object from the framework.
 */
public void bundleChanged(final BundleEvent event) {
	/*
	 * Check if we had a delayed call (which could happen when we
	 * close).
	 */
	if (closed) {
		return;
	}
	final Bundle bundle = event.getBundle();
	final int state = bundle.getState();
	if (DEBUG) {
		System.out.println("BundleTracker.Tracked.bundleChanged[" + state + "]: " + bundle); //$NON-NLS-1$ //$NON-NLS-2$
	}

	if ((state & mask) != 0) {
		track(bundle, event);
		/*
		 * If the customizer throws an unchecked exception, it is safe
		 * to let it propagate
		 */
	} else {
		untrack(bundle, event);
		/*
		 * If the customizer throws an unchecked exception, it is safe
		 * to let it propagate
		 */
	}
}
 
Example 13
Source File: BundleTracker.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@code BundleListener} method for the {@code BundleTracker} class.
 * This method must NOT be synchronized to avoid deadlock potential.
 * 
 * @param event {@code BundleEvent} object from the framework.
 */
public void bundleChanged(final BundleEvent event) {
	/*
	 * Check if we had a delayed call (which could happen when we
	 * close).
	 */
	if (closed) {
		return;
	}
	final Bundle bundle = event.getBundle();
	final int state = bundle.getState();
	if (DEBUG) {
		System.out.println("BundleTracker.Tracked.bundleChanged[" + state + "]: " + bundle); //$NON-NLS-1$ //$NON-NLS-2$
	}

	if ((state & mask) != 0) {
		track(bundle, event);
		/*
		 * If the customizer throws an unchecked exception, it is safe
		 * to let it propagate
		 */
	} else {
		untrack(bundle, event);
		/*
		 * If the customizer throws an unchecked exception, it is safe
		 * to let it propagate
		 */
	}
}
 
Example 14
Source File: EventAdminImpl.java    From concierge with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * receive a <code>BundleEvent</code>.
 * 
 * @param bEvent
 *            the bundle event.
 * @see org.osgi.framework.BundleListener#bundleChanged(org.osgi.framework.BundleEvent)
 */
public void bundleChanged(final BundleEvent bEvent) {
	Dictionary props = new Hashtable();
	props.put(EventConstants.TIMESTAMP,
			new Long(System.currentTimeMillis()));
	Bundle bundle = bEvent.getBundle();
	props.put(EventConstants.EVENT, bEvent);
	props.put("bundle.id", new Long(bundle.getBundleId()));
	props.put("bundle", bundle);
	int t = log2(bEvent.getType());
	String type = t < 7 ? BUNDLE_EVENT[t] : "UNDEFINED";
	Event event = new Event("org/osgi/framework/BundleEvent/" + type, props);
	postEvent(event);
}
 
Example 15
Source File: Extender.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void bundleChanged(BundleEvent event) {
    Bundle bundle = event.getBundle();
    if (event.getType() == BundleEvent.RESOLVED) {
        checkBundle(bundle);
    } else if (event.getType() == BundleEvent.STARTED) {
        checkBundleScriptEngines(bundle);
    }
}
 
Example 16
Source File: BundleStartTimeCalculator.java    From sling-whiteboard with Apache License 2.0 5 votes vote down vote up
@Override
public void bundleChanged(BundleEvent event) {
    Bundle bundle = event.getBundle();
    
    // this bundle is already starting by the time this is invoked. We also can't get proper timing
    // from the framework bundle
    
    if ( bundle.getBundleId() == Constants.SYSTEM_BUNDLE_ID 
            || bundle.getBundleId() == ourBundleId ) {
        return;
    }
    
    synchronized (bundleToStartTime) {

        switch (event.getType()) {
            case BundleEvent.STARTING:
                bundleToStartTime.put(bundle.getBundleId(), new StartTime(bundle.getSymbolicName(), clock.millis()));
                break;

            case BundleEvent.STARTED:
                StartTime startTime = bundleToStartTime.get(bundle.getBundleId());
                if ( startTime == null ) {
                    Log.debug(getClass(), "No previous data for started bundle {}/{}", new Object[] { bundle.getBundleId(), bundle.getSymbolicName() });
                    return;
                }
                startTime.started(clock.millis());
                break;
            
            default: // nothing to do here
                break;
        }
    }
}
 
Example 17
Source File: TableDisplayer.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void bundleChanged(BundleEvent ev)
{
  final Bundle cBundle = null != ev ? ev.getBundle() : null;
  final long cBid = null != cBundle ? cBundle.getBundleId() : -1;
  super.bundleChanged(ev);
  final Bundle[] newBl = getBundleArray();

  // Fire table change events for the changes
  for (int row = 0; row < newBl.length; row++) {
    if (row < bundleList.length) {
      if (bundleList[row].getBundleId() != newBl[row].getBundleId()) {
        // Fire row change for rows that now presents another bundle.
        model.fireTableRowsUpdated(row, row);
      }
      if (cBid == newBl[row].getBundleId()) {
        // Fire row change since the bundle on this row was changed.
        model.fireTableRowsUpdated(row, row);
      }
    } else {
      // The remainder are new rows.
      model.fireTableRowsInserted(row, newBl.length);
      break;
    }
  }
  if (newBl.length < bundleList.length) {
    // Some rows was removed
    model.fireTableRowsDeleted(newBl.length, bundleList.length - 1);
  }

  bundleList = newBl;

  // Update column widths to handle columns with dynamic max-width.
  for (final JComponent jComp : components) {
    final JBundleTable table = (JBundleTable) jComp;
    table.setColumnWidth();
  }

  // Update table selections to match new rows of selected bundles
  valueChanged(-1);
}
 
Example 18
Source File: Desktop.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void bundleChanged(final BundleEvent ev)
{
  if (!alive) {
    return;
  }

  // This callback method is marked as "NotThreadSafe" in the
  // javadoc, that implies that the thread calling it may hold
  // internal framework locks, thus since we need to call into the
  // framework all work must be done on a separate thread to avoid
  // dead-locks.
  final Bundle bundle = null != ev ? ev.getBundle() : null;
  final String threadName =
    "Desktop.bundleChanged("
        + (null == ev
          ? ""
          : (Util.bundleEventName(ev.getType()) + ", " + (null == bundle
            ? "*"
            : String.valueOf(bundle.getBundleId())))) + ")";

  final Thread bct = new Thread(threadName) {
    @Override
    public void run()
    {
      if (pm != null) {
        pm.refresh();
      }
      bundleCache = Activator.getBundles();

      SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run()
        {
          if (ev != null && BundleEvent.INSTALLED == ev.getType()) {
            // Select bundle when installed
            setSelected(bundle);
            showBundle(bundle);
          } else if (null != bundle && isSelected(bundle)) {
            if (BundleEvent.UNINSTALLED == ev.getType()) {
              bundleSelModel.setSelected(bundle.getBundleId(), false);
            } else {
              // Trigger a selection change notification to tell
              // displayers to update their contents
              if (bundleSelModel instanceof DefaultBundleSelectionModel) {
                final DefaultBundleSelectionModel dbsm =
                  (DefaultBundleSelectionModel) bundleSelModel;
                dbsm.fireChange(bundle.getBundleId());
              }
            }
          }
          updateStatusBar();
          updateMenus();
          toolBar.revalidate();
          toolBar.repaint();
        }
      });
    }
  };
  bct.start();
}
 
Example 19
Source File: MultiListener.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * A listener for events sent by bundles
 * @param bundleEvent The event sent by the bundle
 * @author Johnny Baveras
 */


public void bundleChanged(BundleEvent bundleEvent) {
  String topic = null;
  boolean knownMessageType = true;

  switch (bundleEvent.getType()) {
  case BundleEvent.INSTALLED:
    topic = INSTALLED_TOPIC;
    break;
  case BundleEvent.STARTED:
    topic = STARTED_TOPIC;
    break;
  case BundleEvent.STOPPED:
    topic = STOPPED_TOPIC;
    break;
  case BundleEvent.UPDATED:
    topic = UPDATED_TOPIC;
    break;
  case BundleEvent.UNINSTALLED:
    topic = UNINSTALLED_TOPIC;
    break;
  case BundleEvent.RESOLVED:
    topic = RESOLVED_TOPIC;
    break;
  case BundleEvent.UNRESOLVED:
    topic = UNRESOLVED_TOPIC;
    break;
  default:
    /* Setting the boolean to false if an unknown event arrives */
    knownMessageType = false;
    break;
  }


  /* Stores the properties of the event in the dictionary, if the event is known */
  if (knownMessageType) {
    if(!Activator.handlerTracker.anyHandlersMatching(topic)) {
      return;
    }
    Map<String,Object> props = new HashMap<String,Object>();
    Bundle bundle = bundleEvent.getBundle();
    putProp(props, EventConstants.EVENT, bundleEvent);
    putProp(props, "bundle.id", new Long(bundle.getBundleId()));
    putProp(props, EventConstants.BUNDLE_SYMBOLICNAME, bundle.getSymbolicName());
    putProp(props, "bundle", bundle);
    /* Tries posting the event once the properties are set */
    try {
      Activator.eventAdmin.postEvent(new Event(topic, props));
    } catch (Exception e) {
      Activator.log.error("EXCEPTION in bundleChanged()", e);
    }
  } else {
    /* Logs an error if the event, which arrived, were of an unknown type */
    Activator.log.error("Recieved unknown bundle event message (type="
              +bundleEvent.getType() +"), discarding");
  }
  // }
}