• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java NoHostAvailableException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



NoHostAvailableException类属于com.datastax.driver.core.exceptions包,在下文中一共展示了NoHostAvailableException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: connectToCassaCluster

import com.datastax.driver.core.exceptions.NoHostAvailableException; //导入依赖的package包/类
private void connectToCassaCluster(){
		Iterator<String> it = getAllPossibleLocalIps().iterator();
		String address= "localhost";
		logger.debug("Connecting to cassa cluster: Iterating through possible ips:"+getAllPossibleLocalIps());
		while(it.hasNext()){
			try {
				cluster = Cluster.builder().withPort(9042).addContactPoint(address).build();
				//cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(Integer.MAX_VALUE);
				Metadata metadata = cluster.getMetadata();
				logger.debug("Connected to cassa cluster "+metadata.getClusterName()+" at "+address);
/*				for ( Host host : metadata.getAllHosts() ) {
						.out.printf("Datacenter: %s; Host broadcast: %s; Rack: %s\n",
							host.getDatacenter(), host.getBroadcastAddress(), host.getRack());
							
				}*/
				session = cluster.connect();
				
				break;
			} catch (NoHostAvailableException e) {
				address= it.next();
			} 
		}
	}
 
开发者ID:att,项目名称:music,代码行数:24,代码来源:MusicDataStore.java


示例2: createSession

import com.datastax.driver.core.exceptions.NoHostAvailableException; //导入依赖的package包/类
@Bean
public Session createSession(CassandraProperties properties, Cluster cluster) throws Exception {

    Session session = Retriable.wrap(cluster::connect)
        .withErrorMessage("Cannot connect to cassandra cluster")
        .retryOn(NoHostAvailableException.class)
        .withDelaySec(properties.getConnectDelaySec())
        .call();

    initDb(properties, session);

    if (!session.getCluster().getMetadata().checkSchemaAgreement()) {
        log.warn("SCHEMA IS NOT IN AGREEMENT!!!");
    }

    return session;
}
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:18,代码来源:CassandraConfiguration.java


示例3: connectToCassaCluster

import com.datastax.driver.core.exceptions.NoHostAvailableException; //导入依赖的package包/类
@SuppressWarnings("unused")
private void connectToCassaCluster(String address) {
	PoolingOptions poolingOptions =
		new PoolingOptions()
    	.setConnectionsPerHost(HostDistance.LOCAL,  4, 10)
    	.setConnectionsPerHost(HostDistance.REMOTE, 2, 4);
	Iterator<String> it = getAllPossibleLocalIps().iterator();
	logger.debug("Iterating through possible ips:"+getAllPossibleLocalIps());
	while (it.hasNext()) {
		try {
			cluster = Cluster.builder()
				.withPort(9042)
				.withPoolingOptions(poolingOptions)
				.withoutMetrics()
				.addContactPoint(address)
				.build();
			//cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(Integer.MAX_VALUE);
			Metadata metadata = cluster.getMetadata();
			logger.debug("Connected to cluster:"+metadata.getClusterName()+" at address:"+address);
			session = cluster.connect();
			break;
		} catch (NoHostAvailableException e) {
			address = it.next();
		}
	}
}
 
开发者ID:att,项目名称:music,代码行数:27,代码来源:MusicConnector.java


示例4: connectToCassaCluster

import com.datastax.driver.core.exceptions.NoHostAvailableException; //导入依赖的package包/类
private void connectToCassaCluster(){
		Iterator<String> it = getAllPossibleLocalIps().iterator();
		String address= "localhost";
//		logger.debug("Connecting to cassa cluster: Iterating through possible ips:"+getAllPossibleLocalIps());
		while(it.hasNext()){
			try {
				cluster = Cluster.builder().withPort(9042).addContactPoint(address).build();
				//cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(Integer.MAX_VALUE);
				Metadata metadata = cluster.getMetadata();
//				logger.debug("Connected to cassa cluster "+metadata.getClusterName()+" at "+address);
/*				for ( Host host : metadata.getAllHosts() ) {
					System.out.printf("Datacenter: %s; Host broadcast: %s; Rack: %s\n",
							host.getDatacenter(), host.getBroadcastAddress(), host.getRack());
							
				}*/
				session = cluster.connect();
				
				break;
			} catch (NoHostAvailableException e) {
				address= it.next();
			} 
		}
	}
 
开发者ID:att,项目名称:music,代码行数:24,代码来源:CassaHandle.java


示例5: testClusterHintsPollerWhenNodeDown

import com.datastax.driver.core.exceptions.NoHostAvailableException; //导入依赖的package包/类
@Test
public void testClusterHintsPollerWhenNodeDown() throws UnknownHostException {
    ClusterHintsPoller clusterHintsPoller = new ClusterHintsPoller();
    Session mockSession = mock(Session.class);
    Cluster mockCluster = mock(Cluster.class);
    Metadata mockMetadata = mock(Metadata.class);
    when(mockCluster.getMetadata()).thenReturn(mockMetadata);
    when(mockCluster.getClusterName()).thenReturn("test-cluster");
    Host node1 = mock(Host.class);
    when(node1.getAddress()).thenReturn(InetAddress.getByName("127.0.0.1"));
    Host node2 = mock(Host.class);
    when(node2.getAddress()).thenReturn(InetAddress.getByName("127.0.0.2"));
    Host node3 = mock(Host.class);
    when(node3.getAddress()).thenReturn(InetAddress.getByName("127.0.0.3"));

    when(mockSession.getCluster()).thenReturn(mockCluster);
    // The first node queried is down
    when(mockSession.execute(any(Statement.class))).thenThrow(new NoHostAvailableException(ImmutableMap.<InetSocketAddress, Throwable>of()));

    when(mockMetadata.getAllHosts()).thenReturn(ImmutableSet.of(node1, node2, node3));
    HintsPollerResult actualResult = clusterHintsPoller.getOldestHintsInfo(mockSession);

    // Make sure HintsPollerResult fails
    assertFalse(actualResult.areAllHostsPolling(), "Result should show hosts failing");
    assertEquals(actualResult.getHostFailure(), ImmutableSet.of(InetAddress.getByName("127.0.0.1")), "Node 1 should return with host failure");
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:27,代码来源:ClusterHintsPollerTest.java


示例6: testHostNotFoundErrorHandling

import com.datastax.driver.core.exceptions.NoHostAvailableException; //导入依赖的package包/类
@Test(expected = NoHostAvailableException.class)
public void testHostNotFoundErrorHandling() throws Exception {
	CassandraSinkBase base = new CassandraSinkBase(new ClusterBuilder() {
		@Override
		protected Cluster buildCluster(Cluster.Builder builder) {
			return builder
				.addContactPoint("127.0.0.1")
				.withoutJMXReporting()
				.withoutMetrics().build();
		}
	}) {
		@Override
		public ListenableFuture send(Object value) {
			return null;
		}
	};

	base.open(new Configuration());
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:20,代码来源:CassandraSinkBaseTest.java


示例7: executeWithSession

import com.datastax.driver.core.exceptions.NoHostAvailableException; //导入依赖的package包/类
public <T> T executeWithSession(String schemaName, SessionCallable<T> sessionCallable)
{
    NoHostAvailableException lastException = null;
    for (int i = 0; i < 2; i++) {
        Session session = getSession(schemaName);
        try {
            return sessionCallable.executeWithSession(session);
        }
        catch (NoHostAvailableException e) {
            lastException = e;

            // Something happened with our client connection.  We need to
            // re-establish the connection using our contact points.
            sessionBySchema.asMap().remove(schemaName, session);
        }
    }
    throw lastException;
}
 
开发者ID:y-lan,项目名称:presto,代码行数:19,代码来源:CassandraSession.java


示例8: checkCassandraReachable

import com.datastax.driver.core.exceptions.NoHostAvailableException; //导入依赖的package包/类
private boolean checkCassandraReachable(List<ConfigIssue> issues) {
  boolean isReachable = true;
  try (Cluster validationCluster = getCluster()) {
    Session validationSession = validationCluster.connect();
    validationSession.close();
  } catch (NoHostAvailableException | AuthenticationException | IllegalStateException | StageException e) {
    isReachable = false;
    Target.Context context = getContext();
    LOG.error(Errors.CASSANDRA_05.getMessage(), e.toString(), e);
    issues.add(
        context.createConfigIssue(
        Groups.CASSANDRA.name(),
        CONTACT_NODES_LABEL,
        Errors.CASSANDRA_05, e.toString()
        )
    );
  }
  return isReachable;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:20,代码来源:CassandraTarget.java


示例9: createCluster

import com.datastax.driver.core.exceptions.NoHostAvailableException; //导入依赖的package包/类
public void createCluster() {
    erroredOut = false;
    schemaCreated = false;
    cassandraCluster = CCMBridge.create("test", 1);
    try {
        Builder builder = Cluster.builder();
        builder = configure(builder);
        cluster = builder.addContactPoints(IP_PREFIX + '1').build();
        session = cluster.connect();
    } catch (NoHostAvailableException e) {
        erroredOut = true;
        for (Map.Entry<InetSocketAddress, Throwable> entry : e.getErrors().entrySet())
            logger.info("Error connecting to " + entry.getKey() + ": " + entry.getValue());
        throw new RuntimeException(e);
    }
}
 
开发者ID:adejanovski,项目名称:cassandra-jdbc-wrapper,代码行数:17,代码来源:CCMBridge.java


示例10: sendToNext

import com.datastax.driver.core.exceptions.NoHostAvailableException; //导入依赖的package包/类
@Override
public void sendToNext(Document doc) {
  if (isRemembering()) {
    try {
    Session session = getCassandra().getSession();
    PreparedStatement preparedQuery = getCassandra().getPreparedQuery(UPDATE_HASH_U);
    BoundStatement bind = preparedQuery.bind(doc.getHash(), doc.getId(), doc.getSourceScannerName());
    session.execute(bind);
    } catch (NoHostAvailableException e) {
      if (!Main.isShuttingDown()) {
        log.error("Could not contact our internal Cassandra!!!" + e);
      }
    }
  }
  superSendToNext(doc);
}
 
开发者ID:nsoft,项目名称:jesterj,代码行数:17,代码来源:ScannerImpl.java


示例11: createSession

import com.datastax.driver.core.exceptions.NoHostAvailableException; //导入依赖的package包/类
static Session createSession() throws Exception {
    Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1")
            // long read timeout is sometimes needed on slow travis ci machines
            .withSocketOptions(new SocketOptions().setReadTimeoutMillis(30000))
            .withQueryOptions(getQueryOptions())
            .build();
    Session session = cluster.connect();
    session.execute("CREATE KEYSPACE IF NOT EXISTS test WITH REPLICATION ="
            + " { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }");
    session.execute("CREATE TABLE IF NOT EXISTS test.users"
            + " (id int PRIMARY KEY, fname text, lname text)");
    try {
        session.execute("TRUNCATE test.users");
    } catch (NoHostAvailableException e) {
        // sometimes slow, so give it a second chance
        session.execute("TRUNCATE test.users");
    }
    for (int i = 0; i < 10; i++) {
        session.execute("INSERT INTO test.users (id, fname, lname) VALUES (" + i + ", 'f" + i
                + "', 'l" + i + "')");
    }
    return session;
}
 
开发者ID:glowroot,项目名称:glowroot,代码行数:24,代码来源:Sessions.java


示例12: testBadConnection

import com.datastax.driver.core.exceptions.NoHostAvailableException; //导入依赖的package包/类
@Test
    public void testBadConnection() {
        CassandraConnection cc = new CassandraConnection();

        cc.setProperty("contactPoints", "127.1.1.1");
//        cc.setProperty("keyspace", "testks");
        cc.setProperty("sessionName", "testsession");

        Boolean exeptionCaught=false;

        try {
            cc.testStarted();
        } catch (NoHostAvailableException e) {
            exeptionCaught = true;
        }
        assertTrue(exeptionCaught, "NoHostAvailable did not occur.");

        cc.testEnded();
    }
 
开发者ID:slowenthal,项目名称:jmeter-cassandra,代码行数:20,代码来源:ConnectionTest.java


示例13: CassandraConfig

import com.datastax.driver.core.exceptions.NoHostAvailableException; //导入依赖的package包/类
public CassandraConfig(DataService dataService, String configId, Map<String, String> properties,
                       boolean odataEnable) throws DataServiceFault {
    super(dataService, configId, DataSourceTypes.CASSANDRA, properties, odataEnable);
    Builder builder = Cluster.builder();
    this.populateSettings(builder, properties);
    String keyspace = properties.get(DBConstants.Cassandra.KEYSPACE);
    this.cluster = builder.build();
    try {
        if (keyspace != null && keyspace.trim().length() > 0) {
            this.session = this.cluster.connect(keyspace);
        } else {
            this.session = this.cluster.connect();
        }
        this.nativeBatchRequestsSupported = this.session.getCluster().
                getConfiguration().getProtocolOptions().getProtocolVersion().toInt() > 1;
    } catch (NoHostAvailableException e) {
        throw new DataServiceFault(e, DBConstants.FaultCodes.CONNECTION_UNAVAILABLE_ERROR, e.getMessage());
    }
}
 
开发者ID:wso2,项目名称:carbon-data,代码行数:20,代码来源:CassandraConfig.java


示例14: getApplicationSession

import com.datastax.driver.core.exceptions.NoHostAvailableException; //导入依赖的package包/类
@Override
public synchronized Session getApplicationSession(){

    // always grab cluster from getCluster() in case it was prematurely closed
    if ( applicationSession == null || applicationSession.isClosed() ){
        int retries = 3;
        int retryCount = 0;
        while ( retryCount < retries){
            try{
                retryCount++;
                applicationSession = getCluster().connect( CQLUtils.quote( cassandraConfig.getApplicationKeyspace() ) );
                break;
            }catch(NoHostAvailableException e){
                if(retryCount == retries){
                    throw e;
                }
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException ie) {
                    // swallow
                }
            }
        }
    }
    return applicationSession;
}
 
开发者ID:apache,项目名称:usergrid,代码行数:27,代码来源:DataStaxClusterImpl.java


示例15: getApplicationLocalSession

import com.datastax.driver.core.exceptions.NoHostAvailableException; //导入依赖的package包/类
@Override
public synchronized Session getApplicationLocalSession(){

    // always grab cluster from getCluster() in case it was prematurely closed
    if ( queueMessageSession == null || queueMessageSession.isClosed() ){
        int retries = 3;
        int retryCount = 0;
        while ( retryCount < retries){
            try{
                retryCount++;
                queueMessageSession = getCluster().connect( CQLUtils.quote( cassandraConfig.getApplicationLocalKeyspace() ) );
                break;
            }catch(NoHostAvailableException e){
                if(retryCount == retries){
                    throw e;
                }
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException ie) {
                    // swallow
                }
            }
        }
    }
    return queueMessageSession;
}
 
开发者ID:apache,项目名称:usergrid,代码行数:27,代码来源:DataStaxClusterImpl.java


示例16: matches

import com.datastax.driver.core.exceptions.NoHostAvailableException; //导入依赖的package包/类
@Override
public boolean matches(Object item) {
  if (item instanceof NoHostAvailableException) {
    NoHostAvailableException nhae = (NoHostAvailableException) item;
    if (nhae.getErrors().size() == 1) {
      Throwable error = nhae.getErrors().values().iterator().next();
      return expectedFirstErrorMatcher.matches(error);
    }
  }
  return false;
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:12,代码来源:ErrorResultIntegrationTest.java


示例17: testRejectAndAcceptAfter

import com.datastax.driver.core.exceptions.NoHostAvailableException; //导入依赖的package包/类
@Test
public void testRejectAndAcceptAfter() throws Exception {
  Collection<BoundDataCenter> datacenters = server.getCluster().getDataCenters();
  BoundDataCenter dc = datacenters.iterator().next();
  Iterator<BoundNode> nodeIterator = dc.getNodes().iterator();
  BoundNode node = nodeIterator.next();

  Scope scope = new Scope(server.getCluster().getId(), dc.getId(), node.getId());
  HttpTestResponse delete =
      server.delete("/listener/" + scope + "?after=" + 3 + "&type=" + "unbind");
  assertThat(delete.response.statusCode()).isEqualTo(200);

  // First try
  try (com.datastax.driver.core.Cluster driverCluster =
      defaultBuilder().addContactPointsWithPorts((InetSocketAddress) node.getAddress()).build()) {
    driverCluster.init();
  }

  // Second try
  try (com.datastax.driver.core.Cluster driverCluster =
      defaultBuilder().addContactPointsWithPorts((InetSocketAddress) node.getAddress()).build()) {
    driverCluster.init();
  }

  // Now it should be rejected
  try (com.datastax.driver.core.Cluster driverCluster =
      defaultBuilder().addContactPointsWithPorts((InetSocketAddress) node.getAddress()).build()) {
    driverCluster.init();
  } catch (NoHostAvailableException e) {
  }

  HttpTestResponse accept = server.put("/listener/" + scope);
  assertThat(accept.response.statusCode()).isEqualTo(200);

  // Now it should go back to normal
  try (com.datastax.driver.core.Cluster driverCluster =
      defaultBuilder().addContactPointsWithPorts((InetSocketAddress) node.getAddress()).build()) {
    driverCluster.init();
  }
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:41,代码来源:EndpointIntegrationTest.java


示例18: createCluster

import com.datastax.driver.core.exceptions.NoHostAvailableException; //导入依赖的package包/类
@Bean
public Cluster createCluster(CassandraProperties properties) {
    return Retriable.wrap(() -> doCreateCluster(properties))
        .withErrorMessage("Cannot connect to cassandra cluster")
        .retryOn(NoHostAvailableException.class, UnknownHostException.class)
        .withDelaySec(properties.getConnectDelaySec())
        .call();
}
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:9,代码来源:CassandraConfiguration.java


示例19: reportsSpanOnTransportException

import com.datastax.driver.core.exceptions.NoHostAvailableException; //导入依赖的package包/类
@Test public void reportsSpanOnTransportException() throws Exception {
  cluster.close();

  try {
    invokeBoundStatement();
    failBecauseExceptionWasNotThrown(NoHostAvailableException.class);
  } catch (NoHostAvailableException e) {
  }

  assertThat(spans).hasSize(1);
}
 
开发者ID:openzipkin,项目名称:brave-cassandra,代码行数:12,代码来源:ITTracingSession.java


示例20: check_failsInsteadOfThrowing

import com.datastax.driver.core.exceptions.NoHostAvailableException; //导入依赖的package包/类
@Test
public void check_failsInsteadOfThrowing() {
  CheckResult result =
      Cassandra3Storage.builder().contactPoints("1.1.1.1").build().check();

  assertThat(result.ok).isFalse();
  assertThat(result.exception)
      .isInstanceOf(NoHostAvailableException.class);
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:10,代码来源:Cassandra3StorageTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java OFFeaturesReply类代码示例发布时间:2022-05-21
下一篇:
Java LineNumberNode类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap