예제 #1
0
 private ThreadFactory getThreadFactory(CuratorFrameworkFactory.Builder builder) {
   ThreadFactory threadFactory = builder.getThreadFactory();
   if (threadFactory == null) {
     threadFactory = ThreadUtils.newThreadFactory("CuratorFramework");
   }
   return threadFactory;
 }
예제 #2
0
  public CuratorFrameworkImpl(CuratorFrameworkFactory.Builder builder) {
    this.client =
        new CuratorZookeeperClient(
            builder.getZookeeperFactory(),
            builder.getEnsembleProvider(),
            builder.getSessionTimeoutMs(),
            builder.getConnectionTimeoutMs(),
            new Watcher() {
              @Override
              public void process(WatchedEvent watchedEvent) {
                CuratorEvent event =
                    new CuratorEventImpl(
                        CuratorFrameworkImpl.this,
                        CuratorEventType.WATCHED,
                        watchedEvent.getState().getIntValue(),
                        unfixForNamespace(watchedEvent.getPath()),
                        null,
                        null,
                        null,
                        null,
                        null,
                        watchedEvent,
                        null);
                processEvent(event);
              }
            },
            builder.getRetryPolicy(),
            builder.canBeReadOnly());

    listeners = new ListenerContainer<CuratorListener>();
    unhandledErrorListeners = new ListenerContainer<UnhandledErrorListener>();
    backgroundOperations = new DelayQueue<OperationAndData<?>>();
    namespace = new NamespaceImpl(this, builder.getNamespace());
    threadFactory = getThreadFactory(builder);
    connectionStateManager = new ConnectionStateManager(this, builder.getThreadFactory());
    compressionProvider = builder.getCompressionProvider();
    aclProvider = builder.getAclProvider();
    state = new AtomicReference<CuratorFrameworkState>(CuratorFrameworkState.LATENT);

    byte[] builderDefaultData = builder.getDefaultData();
    defaultData =
        (builderDefaultData != null)
            ? Arrays.copyOf(builderDefaultData, builderDefaultData.length)
            : new byte[0];

    if (builder.getAuthScheme() != null) {
      authInfo.set(new AuthInfo(builder.getAuthScheme(), builder.getAuthValue()));
    }

    failedDeleteManager = new FailedDeleteManager(this);
    namespaceFacadeCache = new NamespaceFacadeCache(this);
  }