当前位置: 首页>>代码示例>>Java>>正文


Java ConnectionState类代码示例

本文整理汇总了Java中org.apache.curator.framework.state.ConnectionState的典型用法代码示例。如果您正苦于以下问题:Java ConnectionState类的具体用法?Java ConnectionState怎么用?Java ConnectionState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ConnectionState类属于org.apache.curator.framework.state包,在下文中一共展示了ConnectionState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setMetricsCacheLocation

import org.apache.curator.framework.state.ConnectionState; //导入依赖的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

示例2: stateChanged

import org.apache.curator.framework.state.ConnectionState; //导入依赖的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

示例3: stateChanged

import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
/**
 * This implementation is done in parallel because some listeners can hang the thread for a few minutes
 * while waiting for the others.
 * @param client
 * @param newState
 */
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
    if (this.client instanceof  RedirectorCuratorFramework) {
        if (((RedirectorCuratorFramework) this.client).getConnection().equals(client)) {
            currentConnectionState = newState;
        }
    } else  {
        if (this.client.equals(client)) {
            currentConnectionState = newState;
        }
    }

    Metrics.reportConnectionState(newState.name());

    connectionListeners.forEach(listener ->
            listenerParallelRunner.submit(
                    (Runnable) () -> listener.stateChanged(getConnectorState(newState))));
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:25,代码来源:ZookeeperConnector.java

示例4: CuratorZookeeperClient

import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
public CuratorZookeeperClient(URL url) {
    super(url);
    try {
        Builder builder = CuratorFrameworkFactory.builder()
                .connectString(url.getBackupAddress())
                .retryPolicy(new RetryNTimes(Integer.MAX_VALUE, 1000))
                .connectionTimeoutMs(5000);
        String authority = url.getAuthority();
        if (authority != null && authority.length() > 0) {
            builder = builder.authorization("digest", authority.getBytes());
        }
        client = builder.build();
        client.getConnectionStateListenable().addListener((client, state) -> {
            if (state == ConnectionState.LOST) {
                CuratorZookeeperClient.this.stateChanged(StateListener.DISCONNECTED);
            } else if (state == ConnectionState.CONNECTED) {
                CuratorZookeeperClient.this.stateChanged(StateListener.CONNECTED);
            } else if (state == ConnectionState.RECONNECTED) {
                CuratorZookeeperClient.this.stateChanged(StateListener.RECONNECTED);
            }
        });
        client.start();
    } catch (Exception e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
 
开发者ID:linux-china,项目名称:dubbo3,代码行数:27,代码来源:CuratorZookeeperClient.java

示例5: stateChanged

import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
/**
 * some state make effect to the lock, we have to handle it.
 *
 * @param client   curator
 * @param newState the state of connection to the io.vertx.spi.cluster.impl.zookeeper.zookeeper.
 */
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
  switch (newState) {
    case LOST:
      //release locks and clean locks
      locks.values().stream().forEach(ZKLock::release);
      locks.clear();
      break;
    case SUSPENDED:
      //just release locks on this node.
      locks.values().stream().forEach(ZKLock::release);
      break;
    case RECONNECTED:
      break;
  }
}
 
开发者ID:IBYoung,项目名称:vert.3x-gateway,代码行数:23,代码来源:ZookeeperClusterManager.java

示例6: stateChanged

import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
	
    switch (newState) {
    case LOST:
    case SUSPENDED:

        Collection<InterProcessMutex> oldLocks = new ArrayList<>(locks.values());
        locks.clear();

        oldLocks.stream().parallel().forEach(lock -> {
            try {
                lock.release();
            } catch (Exception e) {
                logger.trace("Can't release lock on " + newState);
            }
        });
        break;
    default:
    }
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:22,代码来源:DistributedLockServiceCuratorImpl.java

示例7: destroy

import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
@Override
public void destroy() {
    if (connectionState == ConnectionState.CONNECTED) {
        for (ServiceDescription service : services.values()) {
            String path = pathForProvider(service.getName(), service.getId());
            try {
                client.delete().forPath(path);
            } catch (Exception ignore) {
                // ignore
            }
        }
    }
    services.clear();

    client.getConnectionStateListenable().removeListener(connectionStateListener);
    client.close();
}
 
开发者ID:dinstone,项目名称:jrpc,代码行数:18,代码来源:ZookeeperServiceRegistry.java

示例8: stateChanged

import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * @see org.apache.curator.framework.state.ConnectionStateListener#stateChanged(org.apache.curator.framework.CuratorFramework, org.apache.curator.framework.state.ConnectionState)
 */
@Override
public void stateChanged(final CuratorFramework client, final ConnectionState newState) {
	SimpleLogger.log("ZK Connection State Change to [%s]", newState.name());
	connected.set(newState.isConnected());
	switch(newState) {			
		case CONNECTED:						
			registerPending();
			dropConnectLatches();
			break;
		case LOST:
			setAllPending();
			break;
		case READ_ONLY:
			break;
		case RECONNECTED:
			registerPending();
			dropConnectLatches();
			break;
		case SUSPENDED:
			break;
		default:
			break;
	}
	
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:30,代码来源:EndpointPublisher.java

示例9: stateChanged

import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * @see org.apache.curator.framework.state.ConnectionStateListener#stateChanged(org.apache.curator.framework.CuratorFramework, org.apache.curator.framework.state.ConnectionState)
 */
@Override
public void stateChanged(final CuratorFramework client, final ConnectionState newState) {
	log.info("ZK Connection State Change to [{}]", newState.name());
	connected.set(newState.isConnected());
	switch(newState) {			
		case CONNECTED:							
			registerPending();
			break;
		case LOST:
			setAllPending();
			break;
		case READ_ONLY:
			break;
		case RECONNECTED:
			registerPending();
			break;
		case SUSPENDED:
			break;
		default:
			break;
	
	}		
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:28,代码来源:EndpointPublisher.java

示例10: stateChanged

import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * @see org.apache.curator.framework.state.ConnectionStateListener#stateChanged(org.apache.curator.framework.CuratorFramework, org.apache.curator.framework.state.ConnectionState)
 */
@Override
public void stateChanged(final CuratorFramework client, final ConnectionState newState) {
	log.info("ZK Connection State Change to [{}]", newState.name());
	connected.set(newState.isConnected());
	switch(newState) {			
		case CONNECTED:	
			sendNotification(new Notification(NOTIF_SERVICE_CONNECT, OBJECT_NAME, notifSerial.incrementAndGet(), System.currentTimeMillis(), "EndpointListener connected to Zookeeper at [" + zkConnect + "]"));
			break;
		case LOST:
			final int lostEndpoints = registered.size();
			registered.clear();
			sendNotification(new Notification(NOTIF_SERVICE_DISCONNECT, OBJECT_NAME, notifSerial.incrementAndGet(), System.currentTimeMillis(), "EndpointListener lost connection to Zookeeper [" + zkConnect + "]. Lost [" + lostEndpoints + "] endpoints"));
			break;
		case READ_ONLY:
			break;
		case RECONNECTED:
			sendNotification(new Notification(NOTIF_SERVICE_RECONNECT, OBJECT_NAME, notifSerial.incrementAndGet(), System.currentTimeMillis(), "EndpointListener re-connected to Zookeeper at [" + zkConnect + "]"));
			break;
		case SUSPENDED:
			break;
		default:
			break;
	}		
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:29,代码来源:EndpointListener.java

示例11: stateChanged

import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * @see org.apache.curator.framework.state.ConnectionStateListener#stateChanged(org.apache.curator.framework.CuratorFramework, org.apache.curator.framework.state.ConnectionState)
 */
@Override
public void stateChanged(final CuratorFramework client, final ConnectionState newState) {
	final ConnectionState cs = cfState.getAndSet(newState);
	log.info("cfState transition: [{}] --> [{}]", cs, newState);
	
	switch(newState) {			
		case CONNECTED:
			break;
		case LOST:
			break;
		case READ_ONLY:
			break;
		case RECONNECTED:
			break;
		case SUSPENDED:
			break;
		default:
			break;
			
		}
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:26,代码来源:AdminFinder.java

示例12: stateChanged

import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {

  logger.debug("StateChanged: {}", newState);

  switch (newState) {
    case SUSPENDED:
      resignLeadership();
      break;

    case RECONNECTED:
      try {
        takeLeadership();
      } catch (InterruptedException e) {
        logger.error("While handling RECONNECTED", e);
      }
      break;

    case LOST:
      resignLeadership();
      break;
  }
}
 
开发者ID:networknt,项目名称:light-eventuate-4j,代码行数:24,代码来源:EventuateLeaderSelectorListener.java

示例13: stateChanged

import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
@Override
public void stateChanged(CuratorFramework framework, ConnectionState connectionState) {
    switch (connectionState) {
        case CONNECTED:
            metricUpdater.incZKConnected();
            break;
        case SUSPENDED:
            metricUpdater.incZKSuspended();
            break;
        case RECONNECTED:
            metricUpdater.incZKReconnected();
            break;
        case LOST:
            metricUpdater.incZKConnectionLost();
            break;
        case READ_ONLY:
            // NOTE: Should not be relevant for configserver.
            break;
    }
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:21,代码来源:Tenants.java

示例14: stateChanged

import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
@Override
public void stateChanged(final CuratorFramework client, final ConnectionState newState) {
    JobScheduleController jobScheduleController = JobRegistry.getInstance().getJobScheduleController(jobName);
    if (ConnectionState.LOST == newState) {
        jobScheduleController.pauseJob();
    } else if (ConnectionState.RECONNECTED == newState) {
        if (!leaderElectionService.hasLeader()) {
            leaderElectionService.leaderElection();
        }
        serverService.persistServerOnline();
        executionService.clearRunningInfo(shardingService.getLocalHostShardingItems());
        if (!serverService.isJobPausedManually()) {
            jobScheduleController.resumeJob();
        }
    }
}
 
开发者ID:artoderk,项目名称:elastic-jobx,代码行数:17,代码来源:JobOperationListenerManager.java

示例15: getAndIncrement

import org.apache.curator.framework.state.ConnectionState; //导入依赖的package包/类
@Override
public long getAndIncrement() throws Exception {
	while (true) {
		ConnectionState connState = connStateListener.getLastState();

		if (connState != null) {
			throw new IllegalStateException("Connection state: " + connState);
		}

		VersionedValue<Integer> current = sharedCount.getVersionedValue();
		int newCount = current.getValue() + 1;

		if (newCount < 0) {
			// overflow and wrap around
			throw new Exception("Checkpoint counter overflow. ZooKeeper checkpoint counter only supports " +
					"checkpoints Ids up to " + Integer.MAX_VALUE);
		}

		if (sharedCount.trySetCount(current, newCount)) {
			return current.getValue();
		}
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:24,代码来源:ZooKeeperCheckpointIDCounter.java


注:本文中的org.apache.curator.framework.state.ConnectionState类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。