@Override public ConnectionPool<?> getConnectionPool() throws ConnectionException { return getPrimaryKS().getConnectionPool(); }
public Keyspace toHost(String hostName) throws ConnectionException { Host host = _keyspace.getConnectionPool().getPools().stream() .map(HostConnectionPool::getHost) .filter(poolHost -> hostName.equals(poolHost.getHostName())) .findFirst().orElseThrow(() -> new NoAvailableHostsException("No hosts pools found")); return pinToVerifiedHost(host); }
public Keyspace toHost(String hostName) throws ConnectionException { Host host = _keyspace.getConnectionPool().getPools().stream() .map(HostConnectionPool::getHost) .filter(poolHost -> hostName.equals(poolHost.getHostName())) .findFirst().orElseThrow(() -> new NoAvailableHostsException("No hosts pools found")); return pinToVerifiedHost(host); }
/** * Returns a view of the provided Keyspace that pins all operations to the provided host. */ public Keyspace toHost(Host host) throws ConnectionException { if (!_keyspace.getConnectionPool().getPools().stream() .map(HostConnectionPool::getHost) .anyMatch(poolHost -> poolHost.equals(host))) { throw new NoAvailableHostsException("Host not found in pool"); } return pinToVerifiedHost(host); }
/** * Returns a view of the provided Keyspace that pins all operations to the provided host. */ public Keyspace toHost(Host host) throws ConnectionException { if (!_keyspace.getConnectionPool().getPools().stream() .map(HostConnectionPool::getHost) .anyMatch(poolHost -> poolHost.equals(host))) { throw new NoAvailableHostsException("Host not found in pool"); } return pinToVerifiedHost(host); }
private Keyspace pinToVerifiedHost(Host host) throws ConnectionException { //noinspection unchecked PinnedConnectionPool<Cassandra.Client> pinnedPool = new PinnedConnectionPool(_keyspace.getConnectionPool(), host); return new ThriftKeyspaceImpl( _keyspace.getKeyspaceName(), pinnedPool, _keyspace.getConfig(), EmptyKeyspaceTracerFactory.getInstance()); } }
private Keyspace pinToVerifiedHost(Host host) throws ConnectionException { //noinspection unchecked PinnedConnectionPool<Cassandra.Client> pinnedPool = new PinnedConnectionPool(_keyspace.getConnectionPool(), host); return new ThriftKeyspaceImpl( _keyspace.getKeyspaceName(), pinnedPool, _keyspace.getConfig(), EmptyKeyspaceTracerFactory.getInstance()); } }
/** * Gets the topology for a Cassandra keyspace as a Multimap, where the keys identify a rack (or availability zone * in Amazon) and the values are the token ranges for each host in that rack. For example, for a well distributed * ring of 12 hosts and a replication factor of 3 this method would return a Multimap with 3 keys and each key would * contain 4 token ranges. */ private Multimap<String, TokenRange> describeCassandraTopology(final Keyspace keyspace) { try { @SuppressWarnings ("unchecked") ConnectionPool<Cassandra.Client> connectionPool = (ConnectionPool<Cassandra.Client>) keyspace.getConnectionPool(); return connectionPool.executeWithFailover( new AbstractKeyspaceOperationImpl<Multimap<String, TokenRange>>(EmptyKeyspaceTracerFactory.getInstance().newTracer(CassandraOperationType.DESCRIBE_RING), keyspace.getKeyspaceName()) { @Override protected Multimap<String, TokenRange> internalExecute(Cassandra.Client client, ConnectionContext state) throws Exception { Multimap<String, TokenRange> racks = ArrayListMultimap.create(); for (org.apache.cassandra.thrift.TokenRange tokenRange : client.describe_local_ring(getKeyspace())) { // The final local endpoint "owns" the token range, the rest are for replication EndpointDetails endpointDetails = Iterables.getLast(tokenRange.getEndpoint_details()); racks.put(endpointDetails.getRack(), new TokenRangeImpl(tokenRange.getStart_token(), tokenRange.getEnd_token(), tokenRange.getEndpoints())); } return Multimaps.unmodifiableMultimap(racks); } }, keyspace.getConfig().getRetryPolicy().duplicate()).getResult(); } catch (ConnectionException e) { throw Throwables.propagate(e); } }
/** * Gets the topology for a Cassandra keyspace as a Multimap, where the keys identify a rack (or availability zone * in Amazon) and the values are the token ranges for each host in that rack. For example, for a well distributed * ring of 12 hosts and a replication factor of 3 this method would return a Multimap with 3 keys and each key would * contain 4 token ranges. */ private Multimap<String, TokenRange> describeCassandraTopology(final Keyspace keyspace) { try { @SuppressWarnings ("unchecked") ConnectionPool<Cassandra.Client> connectionPool = (ConnectionPool<Cassandra.Client>) keyspace.getConnectionPool(); return connectionPool.executeWithFailover( new AbstractKeyspaceOperationImpl<Multimap<String, TokenRange>>(EmptyKeyspaceTracerFactory.getInstance().newTracer(CassandraOperationType.DESCRIBE_RING), keyspace.getKeyspaceName()) { @Override protected Multimap<String, TokenRange> internalExecute(Cassandra.Client client, ConnectionContext state) throws Exception { Multimap<String, TokenRange> racks = ArrayListMultimap.create(); for (org.apache.cassandra.thrift.TokenRange tokenRange : client.describe_local_ring(getKeyspace())) { // The final local endpoint "owns" the token range, the rest are for replication EndpointDetails endpointDetails = Iterables.getLast(tokenRange.getEndpoint_details()); racks.put(endpointDetails.getRack(), new TokenRangeImpl(tokenRange.getStart_token(), tokenRange.getEnd_token(), tokenRange.getEndpoints())); } return Multimaps.unmodifiableMultimap(racks); } }, keyspace.getConfig().getRetryPolicy().duplicate()).getResult(); } catch (ConnectionException e) { throw Throwables.propagate(e); } }
/** * Gets the topology for a Cassandra keyspace as a Multimap, where the keys identify a rack (or availability zone * in Amazon) and the values are the token ranges for each host in that rack. For example, for a well distributed * ring of 12 hosts and a replication factor of 3 this method would return a Multimap with 3 keys and each key would * contain 4 token ranges. */ private Multimap<String, TokenRange> describeCassandraTopology(final Keyspace keyspace) { try { @SuppressWarnings ("unchecked") ConnectionPool<Cassandra.Client> connectionPool = (ConnectionPool<Cassandra.Client>) keyspace.getConnectionPool(); return connectionPool.executeWithFailover( new AbstractKeyspaceOperationImpl<Multimap<String, TokenRange>>(EmptyKeyspaceTracerFactory.getInstance().newTracer(CassandraOperationType.DESCRIBE_RING), keyspace.getKeyspaceName()) { @Override protected Multimap<String, TokenRange> internalExecute(Cassandra.Client client, ConnectionContext state) throws Exception { Multimap<String, TokenRange> racks = ArrayListMultimap.create(); for (org.apache.cassandra.thrift.TokenRange tokenRange : client.describe_local_ring(getKeyspace())) { // The final local endpoint "owns" the token range, the rest are for replication EndpointDetails endpointDetails = Iterables.getLast(tokenRange.getEndpoint_details()); racks.put(endpointDetails.getRack(), new TokenRangeImpl(tokenRange.getStart_token(), tokenRange.getEnd_token(), tokenRange.getEndpoints())); } return Multimaps.unmodifiableMultimap(racks); } }, keyspace.getConfig().getRetryPolicy().duplicate()).getResult(); } catch (ConnectionException e) { throw Throwables.propagate(e); } }
/** * Gets the topology for a Cassandra keyspace as a Multimap, where the keys identify a rack (or availability zone * in Amazon) and the values are the token ranges for each host in that rack. For example, for a well distributed * ring of 12 hosts and a replication factor of 3 this method would return a Multimap with 3 keys and each key would * contain 4 token ranges. */ private Multimap<String, TokenRange> describeCassandraTopology(final Keyspace keyspace) { try { @SuppressWarnings ("unchecked") ConnectionPool<Cassandra.Client> connectionPool = (ConnectionPool<Cassandra.Client>) keyspace.getConnectionPool(); return connectionPool.executeWithFailover( new AbstractKeyspaceOperationImpl<Multimap<String, TokenRange>>(EmptyKeyspaceTracerFactory.getInstance().newTracer(CassandraOperationType.DESCRIBE_RING), keyspace.getKeyspaceName()) { @Override protected Multimap<String, TokenRange> internalExecute(Cassandra.Client client, ConnectionContext state) throws Exception { Multimap<String, TokenRange> racks = ArrayListMultimap.create(); for (org.apache.cassandra.thrift.TokenRange tokenRange : client.describe_local_ring(getKeyspace())) { // The final local endpoint "owns" the token range, the rest are for replication EndpointDetails endpointDetails = Iterables.getLast(tokenRange.getEndpoint_details()); racks.put(endpointDetails.getRack(), new TokenRangeImpl(tokenRange.getStart_token(), tokenRange.getEnd_token(), tokenRange.getEndpoints())); } return Multimaps.unmodifiableMultimap(racks); } }, keyspace.getConfig().getRetryPolicy().duplicate()).getResult(); } catch (ConnectionException e) { throw Throwables.propagate(e); } }