微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

org.osgi.framework.startlevel.FrameworkStartLevel的实例源码

项目:everest    文件TestOsgiActions.java   
@Test
public void testOsgiInitialBundleStartLevel() throws ResourceNotFoundException,IllegalActionOnResourceException {

    Resource osgi = get("/osgi");
    // get initial bundle start level
    Integer bundleStartlevel = osgi.getMetadata().get("startlevel.bundle",Integer.class);
    System.out.println(bundleStartlevel);
    FrameworkStartLevel fwStartlevel = osgiHelper.getBundle(0).adapt(FrameworkStartLevel.class);
    assertthat(bundleStartlevel).isEqualTo(fwStartlevel.getinitialBundleStartLevel());

    Resource bundles = get("/osgi/bundles");
    for (Resource bundle : bundles.getResources()) {
        BundleResource bundleResource = bundle.adaptTo(BundleResource.class);
        //System.out.println(bundleResource.getBundleId() + " : " + bundleResource.getStartLevel());
    }

    // set initial bundle start level
    HashMap<String,Object> params = new HashMap<String,Object>();
    params.put("startlevel.bundle",2);
    update(osgi.getPath(),params);
    osgi = get("/osgi");
    assertthat(osgi.getMetadata().get("startlevel.bundle")).isEqualTo(2);


}
项目:everest    文件OsgiRootResource.java   
@Override
public Resource update(Request request) throws IllegalActionOnResourceException {
    FrameworkStartLevel frameworkStartLevel = m_frameworkBundle.adapt(FrameworkStartLevel.class);
    Integer bundleStartLevel = request.get(STARTLEVEL_BUNDLE_ParaMETER,Integer.class);
    if (bundleStartLevel != null) {
        frameworkStartLevel.setinitialBundleStartLevel(bundleStartLevel);
    }
    Integer startLevel = request.get(STARTLEVEL_ParaMETER,Integer.class);
    if (startLevel != null) {
        frameworkStartLevel.setStartLevel(startLevel);
    }
    Boolean restart = request.get(FRAMEWORK_RESTART_ParaMETER,Boolean.class);
    if (restart != null && restart) {
        try {
            //restarting framework
            m_frameworkBundle.update();
        } catch (BundleException e) {
            throw new IllegalActionOnResourceException(request,e.getMessage());
        }
    }
    return this;
}
项目:everest    文件TestOsgiRootResource.java   
@Before
public void setUp() {
    m_everest = new Everest();

    // Create a fake bundle context.
    Bundle zero = mock(Bundle.class,RETURNS_MOCKS);
    BundleContext context = mock(BundleContext.class,RETURNS_MOCKS);

    when(zero.getBundleContext()).thenReturn(context);
    when(context.getBundle(0)).thenReturn(zero);
    when(context.getProperty(anyString())).thenReturn("Some Property");
    when(zero.adapt(FrameworkWiring.class)).thenReturn(mock(FrameworkWiring.class));
    when(zero.adapt(FrameworkStartLevel.class)).thenReturn(mock(FrameworkStartLevel.class));

    m_osgi = new OsgiRootResource(context);
    m_everest.bindRootResource(m_osgi);
}
项目:osgi-richconsole    文件UpgradeProcess.java   
public UpgradeProcess(final UpgradeServiceImpl bundleDeployerService,final BundleContext systemBundleContext) {
    this.bundleDeployerService = bundleDeployerService;
    this.systemBundleContext = systemBundleContext;

    // Refresh classes must be initialized first because they will be not available if the richconsole re-deploys
    // itself
    final AtomicBoolean refreshFinished = new AtomicBoolean(false);

    Lock refreshFinishLock = new reentrantlock();
    Condition refreshFinishCondition = refreshFinishLock.newCondition();
    refreshListener = new FrameworkRefreshListener(refreshFinished,refreshFinishLock,refreshFinishCondition);

    Bundle systemBundle = systemBundleContext.getBundle();
    frameworkWiring = systemBundle.adapt(FrameworkWiring.class);

    frameworkStartLevel = systemBundle.adapt(FrameworkStartLevel.class);
    originalFrameworkStartLevelValue = frameworkStartLevel.getStartLevel();
    currentFrameworkStartLevelValue = originalFrameworkStartLevelValue;
}
项目:neoscada    文件Activator.java   
@Override
public void start ( final BundleContext bundleContext ) throws Exception
{
    this.context = bundleContext;

    final ServiceReference<FrameworkStartLevel> frameworkStartLevel = this.context.getServiceReference ( FrameworkStartLevel.class );
    if ( frameworkStartLevel != null )
    {
        final FrameworkStartLevel service = this.context.getService ( frameworkStartLevel );
        if ( service != null )
        {
            try
            {
                this.defaultStartLevel = service.getinitialBundleStartLevel ();
            }
            finally
            {
                this.context.ungetService ( frameworkStartLevel );
            }
        }
    }

    loadStartLevels ();

    for ( final Map.Entry<String,Integer> entry : this.bundleStartList.entrySet () )
    {
        setStartLevel ( entry.getKey (),entry.getValue () );
    }
}
项目:nexus-public    文件NexusContextListener.java   
/**
 * Install all features listed under "nexus-features".
 */
private void installNexusFeatures(final String featureNames) throws Exception {
  final Set<Feature> features = new LinkedHashSet<>();

  for (final String name : Splitter.on(',').trimResults().omitEmptyStrings().split(featureNames)) {
    final Feature feature = featuresService.getFeature(name);
    if (feature != null) {
      features.add(feature);
    }
    else {
      log.warn("Missing: {}",name);
    }
  }

  log.info("Installing: {}",features);

  Set<String> featureIds = new HashSet<>(features.size());
  for (final Feature f : features) {
    // feature might already be installed in the cache; if so then skip installation
    if (!featuresService.isInstalled(f)) {
      featureIds.add(f.getId());
    }
  }

  if (!featureIds.isEmpty()) {
    // avoid auto-refreshing bundles as that Could trigger unwanted restart/lifecycle events
    EnumSet<Option> options = EnumSet.of(NoAutoRefreshBundles,NoAutoRefreshManagedBundles);
    featuresService.installFeatures(featureIds,options);
  }

  log.info("Installed: {}",features);

  // feature bundles have all been installed,so raise framework start level to finish activation
  FrameworkStartLevel frameworkStartLevel = bundleContext.getBundle(0).adapt(FrameworkStartLevel.class);
  if (frameworkStartLevel.getStartLevel() < NEXUS_PLUGIN_START_LEVEL) {
    frameworkStartLevel.setStartLevel(NEXUS_PLUGIN_START_LEVEL,this);
    // activation continues asynchronously in frameworkEvent method...
  }
}
项目:everest    文件TestOsgiActions.java   
@Test
public void testOsgiStartLevel() throws ResourceNotFoundException,IllegalActionOnResourceException,InterruptedException {

    Resource osgi = get("/osgi");
    // get bundle start level
    Integer startlevel = osgi.getMetadata().get("startlevel",Integer.class);
    System.out.println("startlevel: " + startlevel);
    FrameworkStartLevel fwStartlevel = osgiHelper.getBundle(0).adapt(FrameworkStartLevel.class);
    assertthat(startlevel).isEqualTo(fwStartlevel.getStartLevel());

    updatedEvents.clear();
    // set start level
    HashMap<String,Object>();
    params.put("startlevel",3);
    update(osgi.getPath(),params);

    // wait for start level passage
    System.out.println("Waiting for start level passage");
    try {
        Thread.sleep(TimeUtils.TIME_FACTOR * 1000);
    } catch (InterruptedException e) {
        // Interrupted
    }
    osgi = get("/osgi");
    startlevel = osgi.getMetadata().get("startlevel",Integer.class);
    assertthat(startlevel).isEqualTo(3);
    testUpdatedEventFrom("/osgi");

    Resource bundles = get("/osgi/bundles");
    for (Resource bundle : bundles.getResources()) {
        BundleResource bundleResource = bundle.adaptTo(BundleResource.class);
        if (bundleResource.getStartLevel() > startlevel) {
            assertthat(bundleResource.getState()).isEqualTo(OsgiResourceUtils.bundleStatetoString(Bundle.RESOLVED));
        }
        //System.out.println(bundleResource.getBundleId() + " :"+bundleResource.getSymbolicName()+"-"+bundleResource.getState()+" : " + bundleResource.getStartLevel());
    }
}
项目:everest    文件OsgiRootResource.java   
@Override
public ResourceMetadata getMetadata() {
    ImmutableResourceMetadata.Builder MetadataBuilder = new ImmutableResourceMetadata.Builder(m_Metadata);
    // add Start Level Metadata
    FrameworkStartLevel frameworkStartLevel = m_frameworkBundle.adapt(FrameworkStartLevel.class);
    MetadataBuilder.set(STARTLEVEL_BUNDLE_ParaMETER,frameworkStartLevel.getinitialBundleStartLevel());
    MetadataBuilder.set(STARTLEVEL_ParaMETER,frameworkStartLevel.getStartLevel());
    return MetadataBuilder.build();
}
项目:everest    文件OsgiRootResource.java   
@Override
public <A> A adaptTo(Class<A> clazz) {
    if (Bundle.class.equals(clazz)) {
        return (A) m_frameworkBundle;
    } else if (FrameworkWiring.class.equals(clazz)) {
        return (A) m_frameworkBundle.adapt(FrameworkWiring.class);
    } else if (FrameworkStartLevel.class.equals(clazz)) {
        return (A) m_frameworkBundle.adapt(FrameworkStartLevel.class);
    } else {
        return null;
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。