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


Java NoHostAvailableException類代碼示例

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


NoHostAvailableException類屬於com.datastax.driver.core.exceptions包,在下文中一共展示了NoHostAvailableException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


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