Exemplo n.º 1
0
 public void SetStartLevel(int newSL, AbstractBundle callerBundle)
 {
     if (newSL <= 0)
     {
         throw new ArgumentException(""); //$NON-NLS-1$
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// 关闭矿建,销毁框架实例
 /// </summary>
 public void Close()
 {
     if (adaptor == null)
     {
         return;
     }
     if (active)
     {
         Shutdown();
     }
     lock (bundles)
     {
         IList allBundles = bundles.GetBundles();
         int   size       = allBundles.Count;
         for (int i = 0; i < size; i++)
         {
             AbstractBundle bundle = (AbstractBundle)allBundles[i];
             bundle.Close();
         }
         bundles.RemoveAllBundles();
     }
     serviceRegistry = null;
     adaptor         = null;
     assemblyResolver.Stop();
     assemblyResolver = null;
 }
Exemplo n.º 3
0
        /**
         *  Suspends all bundles in the vector passed in.
         * @param bundles list of Bundle objects to be suspended
         */
        private void suspendAllBundles(BundleRepository bundles)
        {
            bool changed;

            do
            {
                changed = false;

                AbstractBundle[] shutdown = this.GetInstalledBundles(bundles, false);

                // Shutdown all running bundles
                for (int i = shutdown.Length - 1; i >= 0; i--)
                {
                    AbstractBundle bundle = shutdown[i];

                    //if (framework.SuspendBundle(bundle, false)) {
                    //    changed = true;
                    //}
                }
            } while (changed);

            try
            {
                //framework.systemBundle.context.stop();
            }
            catch (BundleException sbe)
            {
                Log.Debug(sbe);
                //framework.publishFrameworkEvent(FrameworkEvent.ERROR, framework.systemBundle, sbe);
            }

            //framework.systemBundle.state = Bundle.RESOLVED;
            //framework.publishBundleEvent(BundleEvent.STOPPED, framework.systemBundle);
        }
Exemplo n.º 4
0
 /// <summary>
 /// 加载已安装的所有插件
 /// </summary>
 /// <param name="installedBundles"></param>
 private void LoadInstalledBundles(AbstractBundle[] installedBundles)
 {
     for (int i = 0; i < installedBundles.Length; i++)
     {
         AbstractBundle bundle = installedBundles[i];
         bundle.Load();
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// 添加插件
 /// </summary>
 /// <param name="bundle"></param>
 public void Add(AbstractBundle bundle)
 {
     lock (syncLock)
     {
         if (bundle != null)
         {
             bundlesByInstallOrder.Add(bundle);
             bundlesById.Add(bundle.BundleId, bundle);
             bundlesByLocation.Add(bundle.Location, bundle);
             AddSymbolicName(bundle);
         }
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// 初始化插件框架
 /// </summary>
 /// <param name="adaptor"></param>
 internal void Initialize(IFrameworkAdaptor adaptor)
 {
     this.adaptor = adaptor;
     active       = false;
     /* 初始化适配器 */
     adaptor.Initialize();
     try
     {
         adaptor.InitializeStorage();
     }
     catch (Exception e)
     {
         throw new Exception(e.Message, e);
     }
     /* 初始化框架属性 */
     InitializeProperties(adaptor.Properties);
     /* 初始化包管理器 */
     packageAdmin = new PackageAdminImpl(this);
     /* 初始化扩展管理器 */
     extensionAdmin = new ExtensionAdmin(this);
     /* 初始化程序集解析器 */
     assemblyResolver = new AssemblyResolvingImpl(this);
     /* 初始化启动级别管理器 */
     startLevelManager = new StartLevelManager(this);
     /* 创建服务注册中心 */
     serviceRegistry = new ServiceRegistry(this);
     /* 创建系统插件 */
     this.CreateSystemBundle();
     /* 为安装的插件创建插件对象. */
     IBundleData[] bundleDatas = adaptor.InstalledBundles.ToArray();
     bundles = new BundleRepository(this);
     /* 添加系统插件到插件仓库 */
     bundles.Add(systemBundle);
     if (bundleDatas != null)
     {
         for (int i = 0; i < bundleDatas.Length; i++)
         {
             try
             {
                 AbstractBundle bundle = AbstractBundle.CreateBundle(bundleDatas[i], this, true);
                 bundles.Add(bundle);
             }
             catch (BundleException be)
             {
                 Log.Debug(be);
                 // This is not a fatal error. Publish the framework event.
                 //publishFrameworkEvent(FrameworkEvent.ERROR, systemBundle, be);
             }
         }
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// 获取所有的插件
 /// </summary>
 /// <returns></returns>
 internal AbstractBundle[] getAllBundles()
 {
     lock (bundles)
     {
         IList allBundles = bundles.GetBundles();
         int   size       = allBundles.Count;
         if (size == 0)
         {
             return(null);
         }
         AbstractBundle[] bundlelist = new AbstractBundle[size];
         allBundles.CopyTo(bundlelist, 0);
         return(bundlelist);
     }
 }
Exemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="symbolicName"></param>
        /// <param name="bundle"></param>
        private void RemoveSymbolicName(string symbolicName, AbstractBundle bundle)
        {
            string key = symbolicName;

            if (!bundlesBySymbolicName.ContainsKey(key))
            {
                return;
            }
            AbstractBundle[] bundles = bundlesBySymbolicName[symbolicName] as AbstractBundle[];

            // found some bundles with the global name.
            // remove all references to the specified bundle.
            int numRemoved = 0;

            for (int i = 0; i < bundles.Length; i++)
            {
                if (bundle == bundles[i])
                {
                    numRemoved++;
                    bundles[i] = null;
                }
            }
            if (numRemoved > 0)
            {
                if (bundles.Length - numRemoved <= 0)
                {
                    // no bundles left in the array remove the array from the hash
                    bundlesBySymbolicName.Remove(key);
                }
                else
                {
                    // create a new array with the null entries removed.
                    AbstractBundle[] newBundles = new AbstractBundle[bundles.Length - numRemoved];
                    int indexCnt = 0;
                    for (int i = 0; i < bundles.Length; i++)
                    {
                        if (bundles[i] != null)
                        {
                            newBundles[indexCnt] = bundles[i];
                            indexCnt++;
                        }
                    }
                    bundlesBySymbolicName[key] = newBundles;
                }
            }
        }
Exemplo n.º 9
0
        /**
         * Build an array of all installed bundles to be launch.
         * The returned array is sorted by increasing startlevel/id order.
         * @param bundles - the bundles installed in the framework
         * @return A sorted array of bundles
         */
        internal AbstractBundle[] GetInstalledBundles(BundleRepository bundles, bool sortByDependency)
        {
            /* make copy of bundles vector in case it is modified during launch */
            AbstractBundle[] installedBundles;

            lock (bundles)
            {
                IList allBundles = bundles.GetBundles();
                installedBundles = new AbstractBundle[allBundles.Count];
                allBundles.CopyTo(installedBundles, 0);

                /* Sort bundle array in ascending startlevel / bundle id order
                 * so that bundles are started in ascending order.
                 */
                BundleUtil.Sort(installedBundles, 0, installedBundles.Length);
                //if (sortByDependency)
                //    SortByDependency(installedBundles);
            }
            return(installedBundles);
        }
Exemplo n.º 10
0
        /**
         * Assign a start level value to the specified Bundle.
         *
         * <p>The specified bundle will be assigned the specified start level. The
         * start level value assigned to the bundle will be persistently recorded
         * by the Framework.
         *
         * If the new start level for the bundle is lower than or equal to the active start level of
         * the Framework, the Framework will start the specified bundle as described
         * in the <tt>Bundle.start</tt> method if the bundle is persistently marked
         * to be started. The actual starting of this bundle must occur asynchronously.
         *
         * If the new start level for the bundle is higher than the active start level of
         * the Framework, the Framework will stop the specified bundle as described
         * in the <tt>Bundle.stop</tt> method except that the persistently recorded
         * state for the bundle indicates that the bundle must be restarted in the
         * future. The actual stopping of this bundle must occur asynchronously.
         *
         * @param bundle The target bundle.
         * @param newSL The new start level for the specified Bundle.
         * @throws IllegalArgumentException
         * If the specified bundle has been uninstalled or
         * if the specified start level is less than or equal to zero, or the  specified bundle is
         * the system bundle.
         * @throws SecurityException if the caller does not have the
         * <tt>AdminPermission</tt> and the Java runtime environment supports
         * permissions.
         */
        public void SetBundleStartLevel(AbstractBundle bundle, int newSL)
        {
            String exceptionText = null;

            if (bundle.BundleId == 0)
            { // system bundle has id=0
                exceptionText = "不能改变插件的启动级别";
            }
            else if (newSL <= 0)
            {
                exceptionText = "启动级别非法"; //$NON-NLS-1$
            }
            if (exceptionText != null)
            {
                throw new ArgumentException(exceptionText);
            }
            try
            {
                // if the bundle's startlevel is not already at the requested startlevel
                if (newSL != ((AbstractBundle)bundle).StartLevel)
                {
                    AbstractBundle b = bundle as AbstractBundle;
                    b.BundleData.StartLevel = (newSL);
                    try
                    {
                        // b.BundleData.Save();
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                    // handle starting or stopping the bundle asynchronously
                    //issueEvent(new StartLevelEvent(StartLevelEvent.CHANGE_BUNDLE_SL, newSL, (AbstractBundle) bundle));
                }
            }
            catch (Exception e)
            {
                Log.Debug(e);
                //framework.publishFrameworkEvent(FrameworkEvent.ERROR, bundle, e);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// 根据位置获取插件对象
        /// </summary>
        /// <param name="location"></param>
        /// <returns></returns>
        internal AbstractBundle GetBundleByLocation(string location)
        {
            lock (bundles)
            {
                // this is not optimized; do not think it will get called
                // that much.
                string finalLocation = location;

                IList allBundles = bundles.GetBundles();
                int   size       = allBundles.Count;
                for (int i = 0; i < size; i++)
                {
                    AbstractBundle bundle = (AbstractBundle)allBundles[i];
                    if (finalLocation.Equals(bundle.Location))
                    {
                        return(bundle);
                    }
                }
                return(null);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// 删除指定的插件
        /// </summary>
        /// <param name="bundle"></param>
        public void Remove(AbstractBundle bundle)
        {
            lock (syncLock)
            {
                // 移除指定Bundle标识ID的Bundle
                bundlesById.Remove(bundle.BundleId);

                // 移除指定Bundle路径的Bundle
                bundlesByLocation.Remove(bundle.Location);

                // 按安装顺序移除指定的Bundle
                bundlesByInstallOrder.Remove(bundle);

                // 通过标识名移除指定的Bundle
                String symbolicName = bundle.SymbolicName;
                if (string.IsNullOrEmpty(symbolicName))
                {
                    return;
                }
                RemoveSymbolicName(symbolicName, bundle);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// 将插件插入到以插件唯一表示名存贮的集合中
        /// </summary>
        /// <param name="bundle"></param>
        private void AddSymbolicName(AbstractBundle bundle)
        {
            string symbolName = bundle.SymbolicName;

            AbstractBundle[] bundles = GetBundles(symbolName);
            string           key     = symbolName;

            if (bundles == null)
            {
                bundles    = new AbstractBundle[1];
                bundles[0] = bundle;
                bundlesBySymbolicName.Add(key, bundles);
                return;
            }

            List <AbstractBundle> list = new List <AbstractBundle>();
            // find place to insert the bundle
            Version newVersion = bundle.Version;
            bool    added      = false;

            for (int i = 0; i < bundles.Length; i++)
            {
                AbstractBundle oldBundle  = bundles[i];
                Version        oldVersion = oldBundle.Version;
                if (!added && newVersion.CompareTo(oldVersion) >= 0)
                {
                    added = true;
                    list.Add(bundle);
                }
                list.Add(oldBundle);
            }
            if (!added)
            {
                list.Add(bundle);
            }

            bundlesBySymbolicName[key] = list.ToArray();
        }
Exemplo n.º 14
0
 /**
  * Return the assigned start level value for the specified Bundle.
  *
  * @param bundle The target bundle.
  * @return The start level value of the specified Bundle.
  * @exception java.lang.IllegalArgumentException If the specified bundle has been uninstalled.
  */
 public int GetBundleStartLevel(AbstractBundle bundle)
 {
     return(((AbstractBundle)bundle).StartLevel);
 }
Exemplo n.º 15
0
 public bool IsBundleActivationPolicyUsed(AbstractBundle bundle)
 {
     //return (((AbstractBundle) bundle).getBundleData().getStatus() & Constants.BUNDLE_ACTIVATION_POLICY) != 0;
     return(false);
 }
Exemplo n.º 16
0
 /**
  * Return the persistent state of the specified bundle.
  *
  * <p>This method returns the persistent state of a bundle.
  * The persistent state of a bundle indicates whether a bundle
  * is persistently marked to be started when it's start level is
  * reached.
  *
  * @return <tt>true</tt> if the bundle is persistently marked to be started,
  * <tt>false</tt> if the bundle is not persistently marked to be started.
  * @exception java.lang.IllegalArgumentException If the specified bundle has been uninstalled.
  */
 public bool IsBundlePersistentlyStarted(AbstractBundle bundle)
 {
     //return (((AbstractBundle) bundle).BundleDataBundleData().getStatus() & Constants.BUNDLE_STARTED) != 0;
     return(false);
 }