Oscar启动分析

1、Oscar首先查找与oscar.jar在同一目录下的System.properties文件,装载所有的系统属性。
 可以通过设置oscar.system.properties属性来改变system.properties文件的路径。
 
 2、查找CACHE_PROFILE_PROP的值确定profile名称属性;
 查找CACHE_PROFILE_DIR_PROP的值确定profile目录属性。
 
 3、Oscar其他属性的设定【option】
 
 4、实例化Oscar
  1)创建一份传入的配置属性的拷贝
   m_configPropMap = new HashMap();
         for (Enumeration e = props.propertyNames(); e.hasMoreElements(); )
         {
             String name = (String) e.nextElement();
             m_configPropMap.put(name, props.getProperty(name));
         }
        
         2)实例化缓存bundle的cache实例【分析】,如果CACHE_CLASS_PROP系统属性未指定,则实例化DefaultBundleCache。
         这一过程中出现异常时,如果Oscar独立启动,则停止JVM。
                
  3)初始化Oscar实例
  /***********************************************
  ** ImportSearchPolicy searchPolicy = new OSGiImportSearchPolicy(this);
     ** m_mgr = new ModuleManager(searchPolicy, new OSGiURLPolicy(this));
  ** 
     ** m_mgr.addModuleListener((OSGiSelectionPolicy) searchPolicy.getSelectionPolicy());
  **
     ** searchPolicy.addValidationListener(new ValidationListener()
     */
  构造ImportSearchPolicy实例【分析】。ImportSearchPolicy实现了ModuleLoader的查找策略以支持模块间相互Import和Export类及资源。
  构造OSGiURLPolicy实例【分析】
  使用指定的Search策略和URL策略构造ModuleManager【分析】
  在ModuleManager上注册OSGi selection policy实例为module监听,以便于在modules卸载时清洗package export cache。
  在ImportSearchPolicy实例上注册validation监听,以便于当modules被validated(如resolved)后更新bundle的state。
  
  构造支持SynchronousBundleListener的DispatchQueue的实例【分析】
  构造Installed Bundle Map实例
  ** m_dispatchQueue = new OscarDispatchQueue();
     ** m_installedBundleMap = new HashMap();
  
  构造framework properties实例(CaseInsensitiveMap)
  ** m_frameworkPropMap = new CaseInsensitiveMap();
 
  初始化Osgi Properties(initializeOsgiProperties【分析】)
  初始化Bundle Properties(initializeOsgiProperties)【分析】
  ** initializeOsgiProperties();
     ** initializeOsgiProperties();
    
  /**********************************
   ** BundleInfo info = new BundleInfo(
      **            new SystemBundleArchive(), null);
   **    systembundle = new SystemBundle(this, info, activatorList);
   **    systembundle.getInfo().addModule(
   **       m_mgr.addModule(
   **           "0", systembundle.getAttributes(),
   **            systembundle.getResourceSources(),
   **            systembundle.getLibrarySources()));
   **    m_installedBundleMap.put(
   **    systembundle.getInfo().getLocation(), systembundle);
   **   
   **    searchPolicy.validate(systembundle.getInfo().getCurrentModule());
      */          
  创建System Bundle实例:
   为System Bundle构造简单的bundle info实例【TODO:分析bundleinfo的构造】
   实例化system bundle【TODO:分析systembundle的构造】
   将system bundle放入installed bundle map中
   调用ImportSearchPolicy实例来validate System Bundle使其状态置为RESOLVED。【分析】
   启动System Bundle【分析】
   
  重新装载并缓存bundles
   BundleArchive[] archives = m_cache.getArchives();
   如果因为crash或file lock而未将标记为UNINSTALLED的bundle完全卸载,则在此处理
   /** if (archives[i].getPersistentState() == Bundle.UNINSTALLED)
          ** {
          **    m_cache.remove(archives[i]);
          ** }
          */
      否则install BundleArchives中的所有bundle【分析installBundle方法】
        /**  else
         **  {
         **      // Install the cached bundle.
         **      bundle = (BundleImpl) installBundle(
         **          archives[i].getId(), archives[i].getLocation(), null);
         ** }
   */       
      获取框架的默认start level
        
      从auto-install 和 auto-start properties设定中加载bundles;
      processAutoProperties();【分析】
 
      设定framework的active start level,如果必要可能会重新启动bundles。
      setStartLevel(startLevel);【分析】
     
      Oscar进入启动状态
      m_oscarStatus = RUNNING_STATUS;
 
      设定system bundle 的 state 为 ACTIVE.
      systembundle.getInfo().setState(Bundle.ACTIVE);
 
      为 system bundle 触发 started event.
      fireBundleEvent(BundleEvent.STARTED, systembundle);
 
      发送一个framework event 指明 Oscar 已经 started.
      fireFrameworkEvent(FrameworkEvent.STARTED, getBundle(0), null);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值