Java Code Examples for org.osgi.framework.FrameworkEvent#getType()

The following examples show how to use org.osgi.framework.FrameworkEvent#getType() . 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: NetbinoxHooks.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void log(FrameworkEvent fe) {
    Level l = Level.FINE;
    if ((fe.getType() & FrameworkEvent.ERROR) != 0) {
        l = Level.SEVERE;
    } else if ((fe.getType() & FrameworkEvent.WARNING) != 0) {
        l = Level.WARNING;
    } else if ((fe.getType() & FrameworkEvent.INFO) != 0) {
        l = Level.INFO;
    }
    LogRecord lr = new LogRecord(l, "framework event {0} type {1}");
    lr.setParameters(new Object[]{fe.getBundle().getSymbolicName(), fe.getType()});
    lr.setThrown(fe.getThrowable());
    lr.setLoggerName(NetbinoxFactory.LOG.getName());
    NetbinoxFactory.LOG.log(lr);
}
 
Example 2
Source File: CarbonServer.java    From carbon-kernel with Apache License 2.0 6 votes vote down vote up
/**
 * Wait until this Framework has completely stopped.
 *
 * @param framework OSGi framework
 * @throws java.lang.Exception
 */
private void waitForServerStop(Framework framework) throws Exception {
    if (!isFrameworkActive()) {
        return;
    }

    while (true) {
        FrameworkEvent event = framework.waitForStop(0);

        // We should not stop the framework if the user has updated the system bundle via the OSGi console or
        //  programmatically. In this case, framework will shutdown and start itself.
        if (event.getType() != FrameworkEvent.STOPPED_UPDATE) {
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "OSGi framework is stopped for update.");
            }
            break;
        }
    }
}
 
Example 3
Source File: NetigsoStartLevelTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void frameworkEvent(FrameworkEvent fe) {
    if (fe.getType() == FrameworkEvent.STARTLEVEL_CHANGED) {
        levelChanged = true;
        notifyAll();
    }
}
 
Example 4
Source File: FrameworkLifecycleHandler.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
public void frameworkEvent(FrameworkEvent event) {
    switch (event.getType()) {
        case 0:/* STARTING */
            starting();
            break;
        case FrameworkEvent.STARTED:
            started();
            break;
        case FrameworkEvent.STARTLEVEL_CHANGED:
        case FrameworkEvent.PACKAGES_REFRESHED:
        case FrameworkEvent.ERROR:
    }

}
 
Example 5
Source File: Activator.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void frameworkEvent(FrameworkEvent e)
{
  try {
    if (e.getType() == FrameworkEvent.STARTED) {
      activate();
    }
  } catch (final Exception e1) {
  }
}
 
Example 6
Source File: LogFrameworkListener.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * The framework event callback method inserts all framework events into
 * the log. Events of type <code>error</code> are logged at the error
 * level other event types are logged on the info level.
 * <p/>
 * FrameworkListener callback.
 * 
 * @param fe
 *            the framework event that has occurred.
 */
public void frameworkEvent(FrameworkEvent fe) {
    int level = LogService.LOG_INFO;
    String msg = null;
    // We always include the Exception even though
    // the specification says differently
    Throwable thr = fe.getThrowable();
    switch (fe.getType()) {
    case FrameworkEvent.ERROR:
        msg = "FrameworkEvent ERROR";
        level = LogService.LOG_ERROR;
        break;
    case FrameworkEvent.STARTED:
        msg = "FrameworkEvent STARTED";
        level = LogService.LOG_INFO;
        break;
    case FrameworkEvent.STARTLEVEL_CHANGED:
        msg = "FrameworkEvent STARTLEVEL_CHANGED";
        level = LogService.LOG_INFO;
        break;
    case FrameworkEvent.PACKAGES_REFRESHED:
        msg = "FrameworkEvent PACKAGES_REFRESHED";
        level = LogService.LOG_INFO;
        break;
    case FrameworkEvent.WARNING:
        msg   = "FrameworkEvent WARNING";
        level = LogService.LOG_INFO; // sic! According to spec.
        break;
    case FrameworkEvent.INFO:
        msg   = "FrameworkEvent INFO";
        level = LogService.LOG_INFO;
        break;
    default:
        msg = "FrameworkEvent <" + fe.getType() + ">";
        level = LogService.LOG_WARNING;
        break;     
    }
    lrsf.log(new LogEntryImpl(fe.getBundle(), level, msg, thr));
}
 
Example 7
Source File: Desktop.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void frameworkEvent(FrameworkEvent ev)
{
  if (!alive) {
    return;
  }
  switch (ev.getType()) {
  case FrameworkEvent.STARTLEVEL_CHANGED:
    updateStartLevel();
    break;
  }
}
 
Example 8
Source File: Listeners.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 *
 */
private void frameworkEvent(final ListenerEntry le, FrameworkEvent evt) {
  try {
    ((FrameworkListener)le.listener).frameworkEvent(evt);
  } catch (final Exception pe) {
    // Don't report Error events again, since probably would go into an infinite loop.
    if (evt.getType() != FrameworkEvent.ERROR) {
      fwCtx.frameworkError(le != null ? le.bc : null, pe);
    }
  }
}
 
Example 9
Source File: DirDeployerImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void frameworkEvent(FrameworkEvent event)
{
  if (FrameworkEvent.PACKAGES_REFRESHED == event.getType()) {
    log("refresh bundles completed");
    refreshRunning = false;
    // We need to run another refresh bundles here to handle updates during
    // the previous refresh.
    refreshUpdatedBundles();
  }
}
 
Example 10
Source File: DirDeployerImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void frameworkEvent(FrameworkEvent event)
{
  if (FrameworkEvent.PACKAGES_REFRESHED == event.getType()) {
    log("refresh bundles completed");
    refreshRunning = false;
    // We need to run another refresh bundles here to handle updates during
    // the previous refresh.
    refreshUpdatedBundles();
  }
}
 
Example 11
Source File: KfApk.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Method that can be used to wait for a started framework to be
 * shut down.
 * 
 * @param fw the framework to wait on.
 */
public static void waitForStop(Framework fw) {
  while (true) { // Ignore interrupted exception.
    try {
      FrameworkEvent stopEvent = fw.waitForStop(0L);
      switch (stopEvent.getType()) {
      case FrameworkEvent.STOPPED:
        // FW terminated, Main is done!
        Log.i(KfApk.class.getName(), "Framework terminated");
        return;
      case FrameworkEvent.STOPPED_UPDATE:
        // Automatic FW restart, wait again.
        break;
      case FrameworkEvent.STOPPED_BOOTCLASSPATH_MODIFIED:
        // A manual FW restart with new boot class path is needed.
        return; // TODO
      case FrameworkEvent.ERROR:
        // Stop failed or other error, give up.
        Log.i(KfApk.class.getName(), "Fatal framework error, terminating.",
              stopEvent.getThrowable());
        return;
      case FrameworkEvent.WAIT_TIMEDOUT:
        // Should not happen with timeout==0, give up.
        Log.i(KfApk.class.getName(), "Framework waitForStop(0) timed out!",
              stopEvent.getThrowable());
        break;
      }
    } catch (final InterruptedException ie) { }
  }
}
 
Example 12
Source File: NetbinoxHooks.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
  public void frameworkEvent(FrameworkEvent ev) {
if (ev.getType() == FrameworkEvent.ERROR) {
          log(ev);
}
  }
 
Example 13
Source File: Util.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Calls package admin refresh packages and waits for the operation
 * to complete.
 *
 * @param bc context owning both resources and to install bundle from
 * @param bundles the inital list of bundles to refresh.
 * @return null on sucess, string with error message on failure.
 */
public static String refreshPackages(BundleContext bc,
                                     Bundle[] bundles)
{
  System.out.println("PackageAdmin.refreshPackages("
                     +Arrays.asList(bundles) +")");
  ServiceReference paSR
    = bc.getServiceReference(PackageAdmin.class.getName());
  if (null==paSR)
    return "No package admin service reference.";

  PackageAdmin pa = (PackageAdmin) bc.getService(paSR);
  if (null==pa)
    return "No package admin service.";

  final Object lock = new Object();

  FrameworkListener fListen = new FrameworkListener(){
      public void frameworkEvent(FrameworkEvent event)
      {
        System.out.println("Got framework event of type "+event.getType());
        if (event.getType()==FrameworkEvent.PACKAGES_REFRESHED) {
          synchronized(lock) {
            lock.notifyAll();
          }
        }
      }
    };
  bc.addFrameworkListener(fListen);

  try {
    pa.refreshPackages(bundles);
  } catch (Exception e) {
    e.printStackTrace();
    return "Failed to refresh packages, got exception " +e;
  }

  synchronized (lock) {
    try {
      lock.wait(30000L);
    } catch (InterruptedException ie) {
      System.err.println("Waiting or packages refreshed was interrupted.");
    }
  }
  System.out.println("PackageAdmin.refreshPackages("
                     +Arrays.asList(bundles) +") done.");

  bc.removeFrameworkListener(fListen);

  return null;
}