gembin

OSGi, Eclipse Equinox, ECF, Virgo, Gemini, Apache Felix, Karaf, Aires, Camel, Eclipse RCP

HBase, Hadoop, ZooKeeper, Cassandra

Flex4, AS3, Swiz framework, GraniteDS, BlazeDS etc.

There is nothing that software can't fix. Unfortunately, there is also nothing that software can't completely fuck up. That gap is called talent.

About Me

 

equinox实现Class Loader机制

equinox 环 境下每一个bundle都是由独立的classLoader实现类的装载的。在OSGi Framework中,Bundle是模块化管理的单元,所有的应用和资源都必须以Bundle作为载体。每个Bundle都有自己的Class Loader,不同Bundle之间(在同一个VM中)可以通过Import和Export机制共享或者隐藏Package。Class Loader建立一种Loading Class的代理模型,来实现资源的共享或隐藏。




下面是equinox实现的类的装载代码:


 



    Class findClass(String name, boolean checkParent) throws ClassNotFoundException {



        String pkgName 
= getPackageName(name);

        
// follow the OSGi delegation model

        if (checkParent && parent != null) {

            
if (name.startsWith(JAVA_PACKAGE))

              
// 1) if startsWith "java." delegate to parent and terminate search

              
// we want to throw ClassNotFoundExceptions if a java.* class cannot be loaded from the parent.

                return parent.loadClass(name);

            
else if (isBootDelegationPackage(pkgName))

                
// 2) if part of the bootdelegation list then delegate to parent and continue of failure

                try {

                    
return parent.loadClass(name);

                } 
catch (ClassNotFoundException cnfe) {

                    
// we want to continue

                }

        }



        Class result 
= null;

        
// 3) search the imported packages

        PackageSource source = findImportedSource(pkgName);

        
if (source != null) {

            
// 3) found import source terminate search at the source

            result = source.loadClass(name);

            
if (result != null)

                
return result;

            
throw new ClassNotFoundException(name);

        }

        
// 4) search the required bundles

        source = findRequiredSource(pkgName);

        
if (source != null)

            
// 4) attempt to load from source but continue on failure

            result = source.loadClass(name);

        
// 5) search the local bundle

        if (result == null)

            result 
= findLocalClass(name);

        
if (result != null)

            
return result;

        
// 6) attempt to find a dynamic import source; only do this if a required source was not found

        if (source == null) {

            source 
= findDynamicSource(pkgName);

            
if (source != null)

                result 
= source.loadClass(name);

        }

        
// do buddy policy loading

        if (result == null && policy != null)

            result 
= policy.doBuddyClassLoading(name);

        
// last resort; do class context trick to work around VM bugs

        if (result == null && findParentResource(name))

            result 
= parent.loadClass(name);

        
if (result == null)

            
throw new ClassNotFoundException(name);

        
return result;

    }

posted on 2008-05-05 10:24 gembin 阅读(683) 评论(0)  编辑  收藏 所属分类: OSGi


只有注册用户登录后才能发表评论。


网站导航:
 

导航

统计

常用链接

留言簿(6)

随笔分类(440)

随笔档案(378)

文章档案(6)

新闻档案(1)

相册

收藏夹(9)

Adobe

Android

AS3

Blog-Links

Build

Design Pattern

Eclipse

Favorite Links

Flickr

Game Dev

HBase

Identity Management

IT resources

JEE

Language

OpenID

OSGi

SOA

Version Control

最新随笔

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜

free counters