use of com.datastax.driver.core.exceptions.DriverInternalError in project java-driver by datastax.
the class ArrayBackedRow method getToken.
@Override
public Token getToken(int i) {
if (tokenFactory == null)
throw new DriverInternalError("Token factory not set. This should only happen at initialization time");
checkType(i, tokenFactory.getTokenType().getName());
ByteBuffer value = data.get(i);
if (value == null || value.remaining() == 0)
return null;
return tokenFactory.deserialize(value, protocolVersion);
}
use of com.datastax.driver.core.exceptions.DriverInternalError in project java-driver by datastax.
the class CBUtil method readInetWithoutPort.
public static InetAddress readInetWithoutPort(ByteBuf cb) {
int addrSize = cb.readByte() & 0xFF;
byte[] address = new byte[addrSize];
cb.readBytes(address);
try {
return InetAddress.getByAddress(address);
} catch (UnknownHostException e) {
throw new DriverInternalError(String.format("Invalid IP address (%d.%d.%d.%d) while deserializing inet address", address[0], address[1], address[2], address[3]));
}
}
use of com.datastax.driver.core.exceptions.DriverInternalError in project java-driver by datastax.
the class CBUtil method readBytes.
public static byte[] readBytes(ByteBuf cb) {
try {
int length = cb.readUnsignedShort();
byte[] bytes = new byte[length];
cb.readBytes(bytes);
return bytes;
} catch (IndexOutOfBoundsException e) {
throw new DriverInternalError("Not enough bytes to read a byte array preceded by it's 2 bytes length");
}
}
use of com.datastax.driver.core.exceptions.DriverInternalError in project java-driver by datastax.
the class CBUtil method readInet.
public static InetSocketAddress readInet(ByteBuf cb) {
int addrSize = cb.readByte() & 0xFF;
byte[] address = new byte[addrSize];
cb.readBytes(address);
int port = cb.readInt();
try {
return new InetSocketAddress(InetAddress.getByAddress(address), port);
} catch (UnknownHostException e) {
throw new DriverInternalError(String.format("Invalid IP address (%d.%d.%d.%d) while deserializing inet address", address[0], address[1], address[2], address[3]));
}
}
use of com.datastax.driver.core.exceptions.DriverInternalError in project java-driver by datastax.
the class DirectedGraph method topologicalSort.
/**
* one-time use only, calling this multiple times on the same graph won't work
*/
List<V> topologicalSort() {
Preconditions.checkState(!wasSorted);
wasSorted = true;
Queue<V> queue = new LinkedList<V>();
// Sort vertices so order of evaluation is always the same (instead of depending on undefined map order behavior)
List<V> orderedVertices = new ArrayList<V>(vertices.keySet());
Collections.sort(orderedVertices, comparator);
for (V v : orderedVertices) {
if (vertices.get(v) == 0)
queue.add(v);
}
List<V> result = Lists.newArrayList();
while (!queue.isEmpty()) {
V vertex = queue.remove();
result.add(vertex);
List<V> adjacentVertices = new ArrayList<V>(adjacencyList.get(vertex));
Collections.sort(adjacentVertices, comparator);
for (V successor : adjacentVertices) {
if (decrementAndGetCount(successor) == 0)
queue.add(successor);
}
}
if (result.size() != vertices.size())
throw new DriverInternalError("failed to perform topological sort, graph has a cycle");
return result;
}
Aggregations