當前位置: 首頁>>代碼示例>>Java>>正文


Java ConnectionStateListener類代碼示例

本文整理匯總了Java中org.apache.curator.framework.state.ConnectionStateListener的典型用法代碼示例。如果您正苦於以下問題:Java ConnectionStateListener類的具體用法?Java ConnectionStateListener怎麽用?Java ConnectionStateListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ConnectionStateListener類屬於org.apache.curator.framework.state包,在下文中一共展示了ConnectionStateListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: SingularityCuratorProvider

import org.apache.curator.framework.state.ConnectionStateListener; //導入依賴的package包/類
@Inject
public SingularityCuratorProvider(final SingularityConfiguration configuration, final Set<ConnectionStateListener> connectionStateListeners) {

  checkNotNull(configuration, "configuration is null");
  checkNotNull(connectionStateListeners, "connectionStateListeners is null");

  ZooKeeperConfiguration zookeeperConfig = configuration.getZooKeeperConfiguration();

  this.curatorFramework = CuratorFrameworkFactory.builder()
      .defaultData(null)
      .sessionTimeoutMs(zookeeperConfig.getSessionTimeoutMillis())
      .connectionTimeoutMs(zookeeperConfig.getConnectTimeoutMillis())
      .connectString(zookeeperConfig.getQuorum())
      .retryPolicy(new ExponentialBackoffRetry(zookeeperConfig.getRetryBaseSleepTimeMilliseconds(), zookeeperConfig.getRetryMaxTries()))
      .namespace(zookeeperConfig.getZkNamespace()).build();

  for (ConnectionStateListener connectionStateListener : connectionStateListeners) {
    curatorFramework.getConnectionStateListenable().addListener(connectionStateListener);
  }
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:21,代碼來源:SingularityCuratorProvider.java

示例2: setMetricsCacheLocation

import org.apache.curator.framework.state.ConnectionStateListener; //導入依賴的package包/類
@Override
public ListenableFuture<Boolean> setMetricsCacheLocation(
    TopologyMaster.MetricsCacheLocation location,
    String topologyName) {
  client.getConnectionStateListenable().addListener(new ConnectionStateListener() {
    @Override
    public void stateChanged(CuratorFramework arg0, ConnectionState arg1) {
      if (arg1 != ConnectionState.CONNECTED) {
        // if not the first time successful connection, fail fast
        throw new RuntimeException("Unexpected state change to: " + arg1.name());
      }
    }
  });
  return createNode(
      StateLocation.METRICSCACHE_LOCATION, topologyName, location.toByteArray(), true);
}
 
開發者ID:twitter,項目名稱:heron,代碼行數:17,代碼來源:CuratorStateManager.java

示例3: stateChanged

import org.apache.curator.framework.state.ConnectionStateListener; //導入依賴的package包/類
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
    if (newState == ConnectionState.CONNECTED) {
        isConnected.set(true);
        if (!isFirstConnection.get()) {
            for (ConnectionStateListener listener : listenerStateProxy.getListeners()) {
                listener.stateChanged(client, ConnectionState.RECONNECTED);
            }
        }
        return;
    }

    if (newState == ConnectionState.LOST) {
        isConnected.set(false);
        isFirstConnection.set(false);
        retryConnection();
    }
}
 
開發者ID:Comcast,項目名稱:redirector,代碼行數:19,代碼來源:RedirectorCuratorFramework.java

示例4: before

import org.apache.curator.framework.state.ConnectionStateListener; //導入依賴的package包/類
@Override
protected void before() throws Throwable
{
    ts = new TestingServer();
    curator = CuratorFrameworkFactory.builder()
                                     .namespace("ezkr")
                                     .connectString(ts.getConnectString())
                                     .retryPolicy(new BoundedExponentialBackoffRetry(10, 100, 7))
                                     .build();
    curator.getConnectionStateListenable().addListener(new ConnectionStateListener()
    {
        @Override
        public void stateChanged(final CuratorFramework client, final ConnectionState newState)
        {

        }
    });
    curator.start();
}
 
開發者ID:brianm,項目名稱:dx,代碼行數:20,代碼來源:EmbeddedZooKeeperRule.java

示例5: testBasic

import org.apache.curator.framework.state.ConnectionStateListener; //導入依賴的package包/類
@Test
public void     testBasic() throws Exception
{
    Timing                          timing = new Timing();
    DistributedDelayQueue<Long>     queue = null;
    CuratorFramework                client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
    client.start();
    try
    {
        BlockingQueueConsumer<Long> consumer = new BlockingQueueConsumer<Long>(Mockito.mock(ConnectionStateListener.class));
        queue = QueueBuilder.builder(client, consumer, new LongSerializer(), "/test").buildDelayQueue();
        queue.start();

        queue.put(1L, System.currentTimeMillis() + 1000);
        Thread.sleep(100);
        Assert.assertEquals(consumer.size(), 0);    // delay hasn't been reached

        Long        value = consumer.take(timing.forWaiting().seconds(), TimeUnit.SECONDS);
        Assert.assertEquals(value, Long.valueOf(1));
    }
    finally
    {
        CloseableUtils.closeQuietly(queue);
        CloseableUtils.closeQuietly(client);
    }
}
 
開發者ID:apache,項目名稱:curator,代碼行數:27,代碼來源:TestDistributedDelayQueue.java

示例6: makeConsumer

import org.apache.curator.framework.state.ConnectionStateListener; //導入依賴的package包/類
private BlockingQueueConsumer<String> makeConsumer(final CountDownLatch latch)
{
    ConnectionStateListener connectionStateListener = new ConnectionStateListener()
    {
        @Override
        public void stateChanged(CuratorFramework client, ConnectionState newState)
        {
        }
    };

    return new BlockingQueueConsumer<String>(connectionStateListener)
    {
        @Override
        public void consumeMessage(String message) throws Exception
        {
            if ( latch != null )
            {
                latch.await();
            }
            super.consumeMessage(message);
        }
    };
}
 
開發者ID:apache,項目名稱:curator,代碼行數:24,代碼來源:TestQueueSharder.java

示例7: buildCuratorWithZookeeperDirectly

import org.apache.curator.framework.state.ConnectionStateListener; //導入依賴的package包/類
private CuratorFramework buildCuratorWithZookeeperDirectly(Configuration configuration) {
      LOGGER.debug("configuring direct zookeeper connection.");
      
      CuratorFramework curator = CuratorFrameworkFactory.newClient(
              this.zookeeperConnectionString,
              configuration.getInt(ZOOKEEPER_SESSION_TIMEOUT_MILLIS.getPropertyName()),
              configuration.getInt(ZOOKEEPER_CONNECTION_TIMEOUT_MILLIS.getPropertyName()),
              buildZookeeperRetryPolicy(configuration));
      curator.getConnectionStateListenable().addListener(new ConnectionStateListener() {
	public void stateChanged(CuratorFramework client, ConnectionState newState) {
		LOGGER.debug("Connection state to ZooKeeper changed: " + newState);
	}
});
      
      return curator;
  }
 
開發者ID:Kixeye,項目名稱:chassis,代碼行數:17,代碼來源:CuratorFrameworkBuilder.java

示例8: ZookeeperClient

import org.apache.curator.framework.state.ConnectionStateListener; //導入依賴的package包/類
private ZookeeperClient(){
	//1000 是重試間隔時間基數,3 是重試次數
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
    zkClient = createWithOptions(zkConnectionString, retryPolicy, 2000, 10000);
    zkClient.getConnectionStateListenable().addListener(new ConnectionStateListener() {
        @Override
        public void stateChanged(CuratorFramework client, ConnectionState newState) {
            logger.info("CuratorFramework state changed: {}", newState);
            if(newState == ConnectionState.CONNECTED || newState == ConnectionState.RECONNECTED){
            	for (String key : listeners.keySet()) {
            		System.out.println(key);
		IZoopkeeperListener listener = listeners.get(key);
		listener.execute(client);
	}
            }
        }
    });
    zkClient.getUnhandledErrorListenable().addListener(new UnhandledErrorListener() {
        @Override
        public void unhandledError(String message, Throwable e) {
            logger.info("CuratorFramework unhandledError: {}", message);
        }
    });
    zkClient.start();
}
 
開發者ID:willwangcn,項目名稱:gemini,代碼行數:26,代碼來源:ZookeeperClient.java

示例9: buildCuratorFramework

import org.apache.curator.framework.state.ConnectionStateListener; //導入依賴的package包/類
/**
 * Builds a {@link org.apache.curator.framework.CuratorFramework} from the specified {@link java.util.Map<String, ?>}.
 */
private synchronized CuratorFramework buildCuratorFramework(ZookeeperConfig curatorConfig) {
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder()
            .ensembleProvider(new FixedEnsembleProvider(curatorConfig.getZookeeperUrl()))
            .connectionTimeoutMs(curatorConfig.getZookeeperConnectionTimeOut())
            .sessionTimeoutMs(curatorConfig.getZookeeperSessionTimeout())
            .retryPolicy(new RetryNTimes(curatorConfig.getZookeeperRetryMax(), curatorConfig.getZookeeperRetryInterval()));

    if (!StringUtils.isNullOrBlank(curatorConfig.getZookeeperPassword())) {
        String scheme = "digest";
        byte[] auth = ("fabric:" + PasswordEncoder.decode(curatorConfig.getZookeeperPassword())).getBytes();
        builder = builder.authorization(scheme, auth).aclProvider(aclProvider.get());
    }

    CuratorFramework framework = builder.build();

    for (ConnectionStateListener listener : connectionStateListeners) {
        framework.getConnectionStateListenable().addListener(listener);
    }
    return framework;
}
 
開發者ID:tdiesler,項目名稱:fabric8poc,代碼行數:24,代碼來源:ManagedCuratorFramework.java

示例10: RestablishingKeeper

import org.apache.curator.framework.state.ConnectionStateListener; //導入依賴的package包/類
public RestablishingKeeper(String hostList)  {
  RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 5);
  client = CuratorFrameworkFactory.newClient(hostList, retryPolicy);
  client.getConnectionStateListenable().addListener(new ConnectionStateListener(){
    @Override
    public void stateChanged(CuratorFramework framework, ConnectionState state) {
      LOGGER.debug("State change "+ state);
      if (state.equals(ConnectionState.CONNECTED) || state.equals(ConnectionState.RECONNECTED)){
        reEstablished.incrementAndGet();
        try {
          onReconnect(framework.getZookeeperClient().getZooKeeper(), framework);
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
      }
    }});
}
 
開發者ID:edwardcapriolo,項目名稱:teknek-core,代碼行數:18,代碼來源:RestablishingKeeper.java

示例11: addListener

import org.apache.curator.framework.state.ConnectionStateListener; //導入依賴的package包/類
@Override
public void addListener(Object listener) {
    ConnectionStateListener stateListener = (ConnectionStateListener) listener;
    if (curator != null) {
        curator.getConnectionStateListenable().addListener(stateListener);
    }
    listeners.add(stateListener);
}
 
開發者ID:Comcast,項目名稱:redirector,代碼行數:9,代碼來源:ListenerStateProxy.java

示例12: removeListener

import org.apache.curator.framework.state.ConnectionStateListener; //導入依賴的package包/類
@Override
public void removeListener(Object listener) {
    ConnectionStateListener stateListener = (ConnectionStateListener) listener;
    if (curator != null) {
        curator.getConnectionStateListenable().removeListener(stateListener);
    }
    listeners.remove(stateListener);
}
 
開發者ID:Comcast,項目名稱:redirector,代碼行數:9,代碼來源:ListenerStateProxy.java

示例13: clearCurator

import org.apache.curator.framework.state.ConnectionStateListener; //導入依賴的package包/類
public void clearCurator() {
    for (ConnectionStateListener stateListener : listeners) {
        if (curator != null) {
            curator.getConnectionStateListenable().removeListener(stateListener);
        }
    }
}
 
開發者ID:Comcast,項目名稱:redirector,代碼行數:8,代碼來源:ListenerStateProxy.java

示例14: updateCurator

import org.apache.curator.framework.state.ConnectionStateListener; //導入依賴的package包/類
public void updateCurator(CuratorFramework curator) {
    this.curator = curator;
    for (ConnectionStateListener stateListener : listeners) {
        if (this.curator != null) {
            this.curator.getConnectionStateListenable().addListener(stateListener);
        }
    }
}
 
開發者ID:Comcast,項目名稱:redirector,代碼行數:9,代碼來源:ListenerStateProxy.java

示例15: KafkaConsumerCache

import org.apache.curator.framework.state.ConnectionStateListener; //導入依賴的package包/類
/**
 * Creates a KafkaConsumerCache object. Before it is used, you must call
 * startCache()
 * 
 * @param apiId
 * @param s
 * @param metrics
 */
public KafkaConsumerCache(String apiId,  MetricsSet metrics) {

	if (apiId == null) {
		throw new IllegalArgumentException("API Node ID must be specified.");
	}

	fApiId = apiId;
//	fSettings = s;
	fMetrics = metrics;
	String strkSetting_ZkBasePath= AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop,kSetting_ZkBasePath);
	if(null==strkSetting_ZkBasePath)strkSetting_ZkBasePath = kDefault_ZkBasePath;
	fBaseZkPath = strkSetting_ZkBasePath;

	fConsumers = new ConcurrentHashMap<String, KafkaConsumer>();
	fSweepScheduler = Executors.newScheduledThreadPool(1);

	curatorConsumerCache = null;

	status = Status.NOT_STARTED;

	listener = new ConnectionStateListener() {
		public void stateChanged(CuratorFramework client, ConnectionState newState) {
			if (newState == ConnectionState.LOST) {
				log.info("ZooKeeper connection expired");
				handleConnectionLoss();
			} else if (newState == ConnectionState.READ_ONLY) {
				log.warn("ZooKeeper connection set to read only mode.");
			} else if (newState == ConnectionState.RECONNECTED) {
				log.info("ZooKeeper connection re-established");
				handleReconnection();
			} else if (newState == ConnectionState.SUSPENDED) {
				log.warn("ZooKeeper connection has been suspended.");
				handleConnectionSuspended();
			}
		}
	};
}
 
開發者ID:att,項目名稱:dmaap-framework,代碼行數:46,代碼來源:KafkaConsumerCache.java


注:本文中的org.apache.curator.framework.state.ConnectionStateListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。