淘宝Atlas框架初探atlas-core(一)

等待许久的淘宝Atlas框架终于开源了

Github地址:https://github.com/alibaba/atlas

atlas-core: This is client-side core library, it's job is to install each bundle, load the classes and resources on-demand when runtime.
atlas-update: This is client-side update library, which provide dexmerge capacity for update or upgrade.
atlas-gradle-plugin: This is Android Studio Gradle Plugin for engineers developing in project period, because we change some android default package mechanisms, include android aapt atlas-aapt.
比较重要的是atlas-core、atlas-update、atlas-gradle-plugin三个工程,将分三篇文章分析

本篇着重分析atlas-core这个工程,atlas-core主要的职责是安装bundle加载bundle运行所需的类和资源两个功能。


从目录上看,这个core工程包含了淘宝模块化bundle机制的框架,包含了自定义的framework、bundle基本组件、所有bundle运行有关的App组件,下面我们一点一点分析。

1.Bundle体系

先看看最主要的bundle是什么。

/**
 * An installed bundle in the Framework.
 *
 * <p>A bundle can be in one of six states:
 * <ul>
 * <li>{@link #UNINSTALLED}
 * <li>{@link #INSTALLED}
 * <li>{@link #RESOLVED}
 * <li>{@link #STARTING}
 * <li>{@link #STOPPING}
 * <li>{@link #ACTIVE}
 * </ul>
 */
public abstract interface Bundle
{
    /**
	 * This bundle is uninstalled and may not be used.
	 *
	 */
    public static final int UNINSTALLED = 0x00000001;

    /**
	 * This bundle is installed but not yet resolved.
	 *
	 */
    public static final int INSTALLED = 0x00000002;

    /**
	 * This bundle is resolved and is able to be started.
	 *
	 */
    public static final int RESOLVED = 0x00000004;

    /**
	 * This bundle is in the process of starting.
	 *
	 */
    public static final int STARTING = 0x00000008;

    /**
	 * This bundle is in the process of stopping.
	 *
	 */
    public static final int STOPPING = 0x00000010;

    /**
	 * This bundle is now running.
	 *
	 */
    public static final int ACTIVE    = 0x00000020;

    /**
	 * Returns this bundle's current state.
	 *
	 */
    public abstract int getState();

    /**
	 * Starts this bundle.
	 *
	 */
    public abstract void start() throws BundleException;

    /**
	 * Stops this bundle.
	 *
	 */
    public abstract void stop() throws BundleException;


    /**
	 * Updates this bundle from an <tt>File</tt>.
	 *
	 */
    public abstract void update(File file,String version,long dexPathVersion) throws BundleException;

    /**
	 * Uninstalls this bundle.
	 *
	 */
    public abstract void uninstall() throws BundleException;

    /**
	 * Returns this bundle's Manifest headers and values.
	 * This method returns all the Manifest headers and values
	 * from the main section of the bundle's Manifest file; that is, all lines prior
	 * to the first blank line.
	 *
	 * <p>Manifest header names are case-insensitive. The methods of the returned
	 * <tt>Dictionary</tt> object will operate on header names in a case-insensitive manner.
	 *
	 * <p>For example, the following Manifest headers and values are included
	 * if they are present in the Manifest file:
	 * <pre>
	 * Bundle-Name
	 * Bundle-Vendor
	 * Bundle-Version
	 * Bundle-Description
	 * Bundle-DocURL
	 * Bundle-ContactAddress
	 * </pre>
	 */
    public abstract Dictionary<String,String> getHeaders();

    /**
	 * Returns this bundle's identifier. The bundle is assigned a unique identifier by the Framework
	 * when it is installed in the OSGi environment.
	 *
	 */
    public abstract long getBundleId();

    /**
	 * Returns this bundle's location identifier.
	 *
	 */
    public abstract String getLocation();

    /**
	 * Determines if this bundle has the specified permissions.
	 */
    public abstract boolean hasPermission(Object permission);

    /**
	 * Find the specified resource in this bundle.
	 */
    public abstract URL getResource(String name);

}


Bundle接口定义了bundle运行时所有的状态以及Bundle的主要方法,下面接着看Bundle的实现类BundleImpl。

    /**
     * the bundle location.
     */
    final String                    location;

    /**
     * the storage location.
     */
    final File                      bundleDir;

    /**
     * the bundle revision.
     */
    long                      revisionNUM = 0;

    long                      dexPatchVersion = 0;

    /**
     * the bundle archive file.
     */
    Archive                         archive;

    /**
     * the bundle state.
     */
    int                             state;

    /**
     * the headers from the manifest.
     */
    Hashtable<String, String>       headers;

    /**
     * the bundle classloader.
     */
    BundleClassLoader               classloader;

    /**
     * the bundle context.
     */
    private final BundleContext context;

    /**
     * the protection domain of this bundle.
     */
   
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值