当前位置: 首页>>代码示例>>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;未经允许,请勿转载。