cdh4用到ServiceLoader的地方

1 FileSystem
  private static void loadFileSystems() {
    synchronized (FileSystem.class) {
      if (!FILE_SYSTEMS_LOADED) {
        ServiceLoader<FileSystem> serviceLoader = ServiceLoader.load(FileSystem.class);
        for (FileSystem fs : serviceLoader) {
          SERVICE_FILE_SYSTEMS.put(fs.getScheme(), fs.getClass());
        }
        FILE_SYSTEMS_LOADED = true;
      }
    }
  }


2 CompressionCodec
private static final ServiceLoader<CompressionCodec> CODEC_PROVIDERS =
    ServiceLoader.load(CompressionCodec.class);


3 TokenIdentifier
private static synchronized Class<? extends TokenIdentifier>
      getClassForIdentifier(Text kind) {
    if (tokenKindMap == null) {
      tokenKindMap = Maps.newHashMap();
      for (TokenIdentifier id : ServiceLoader.load(TokenIdentifier.class)) {
        tokenKindMap.put(id.getKind(), id.getClass());
      }
    }
    Class<? extends TokenIdentifier> cls = tokenKindMap.get(kind);
    if (cls == null) {
      LOG.warn("Cannot find class for token kind " + kind);
       return null;
    }
    return cls;
  }


4 SecurityInfo
private static ServiceLoader<SecurityInfo> securityInfoProviders = 
    ServiceLoader.load(SecurityInfo.class);


上面都是hadoop-commom的。下面的这个是mapreduce的:
5 ClientProtocolProvider

 private static ServiceLoader<ClientProtocolProvider> frameworkLoader =
      ServiceLoader.load(ClientProtocolProvider.class);


cdh4用到ServiceLoader的地方_第1张图片

你可能感兴趣的:(service)