Hierarchy.java 文件源码

java
阅读 24 收藏 0 点赞 0 评论 0

项目:cacheonix-core 作者:
/**
    Return a new logger instance named as the first parameter using
    <code>factory</code>.

    <p>If a logger of that name already exists, then it will be
    returned.  Otherwise, a new logger will be instantiated by the
    <code>factory</code> parameter and linked with its existing
    ancestors as well as children.

    @param name The name of the logger to retrieve.
    @param factory The factory that will make the new logger instance.

*/
 public
 Logger getLogger(String name, LoggerFactory factory) {
   //System.out.println("getInstance("+name+") called.");
   CategoryKey key = new CategoryKey(name);
   // Synchronize to prevent write conflicts. Read conflicts (in
   // getChainedLevel method) are possible only if variable
   // assignments are non-atomic.
   Logger logger;

   synchronized(ht) {
     Object o = ht.get(key);
     if(o == null) {
logger = factory.makeNewLoggerInstance(name);
logger.setHierarchy(this);
ht.put(key, logger);
updateParents(logger);
return logger;
     } else if(o instanceof Logger) {
return (Logger) o;
     } else if (o instanceof ProvisionNode) {
//System.out.println("("+name+") ht.get(this) returned ProvisionNode");
logger = factory.makeNewLoggerInstance(name);
logger.setHierarchy(this);
ht.put(key, logger);
updateChildren((ProvisionNode) o, logger);
updateParents(logger);
return logger;
     }
     else {
// It should be impossible to arrive here
return null;  // but let's keep the compiler happy.
     }
   }
 }
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号