本文整理汇总了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();
}
}
}
示例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;
}
示例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();
}
}
}
示例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();
}
}
}
示例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");
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
示例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;
}
示例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();
}
示例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());
}
}
示例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;
}
示例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;
}