Search in sources :

Example 1 with DriverInternalError

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);
}
Also used : DriverInternalError(com.datastax.driver.core.exceptions.DriverInternalError) ByteBuffer(java.nio.ByteBuffer)

Example 2 with DriverInternalError

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]));
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) DriverInternalError(com.datastax.driver.core.exceptions.DriverInternalError)

Example 3 with DriverInternalError

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");
    }
}
Also used : DriverInternalError(com.datastax.driver.core.exceptions.DriverInternalError)

Example 4 with DriverInternalError

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]));
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) DriverInternalError(com.datastax.driver.core.exceptions.DriverInternalError) InetSocketAddress(java.net.InetSocketAddress)

Example 5 with DriverInternalError

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;
}
Also used : DriverInternalError(com.datastax.driver.core.exceptions.DriverInternalError)

Aggregations

DriverInternalError (com.datastax.driver.core.exceptions.DriverInternalError)9 ByteBuf (io.netty.buffer.ByteBuf)2 IOException (java.io.IOException)2 UnknownHostException (java.net.UnknownHostException)2 ByteBuffer (java.nio.ByteBuffer)2 Cluster (com.datastax.driver.core.Cluster)1 DataType (com.datastax.driver.core.DataType)1 Host (com.datastax.driver.core.Host)1 HostDistance (com.datastax.driver.core.HostDistance)1 PreparedStatement (com.datastax.driver.core.PreparedStatement)1 Session (com.datastax.driver.core.Session)1 Statement (com.datastax.driver.core.Statement)1 UnresolvedUserTypeException (com.datastax.driver.core.exceptions.UnresolvedUserTypeException)1 LoadBalancingPolicy (com.datastax.driver.core.policies.LoadBalancingPolicy)1 Iterators (com.google.common.collect.Iterators)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1