package org.apache.cassandra;

import java.nio.ByteBuffer;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.cassandra.config.CFMetaData;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.config.KSMetaData;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.thrift.*;
import org.apache.cassandra.utils.FBUtilities;
import org.apache.thrift.TException;


/**
 * A test server that mainly throws errors.  Needed to test the CassandraProxyClientCode...
 *
 */
public class BriskErrorServer implements Brisk.Iface
{

    private AtomicInteger counter = new AtomicInteger(0);
 // thread local state containing session information
    public final ThreadLocal<ClientState> clientState = new ThreadLocal<ClientState>()
    {
        @Override
        public ClientState initialValue()
        {
            return new ClientState();
        }
    };

    public List<List<String>> describe_keys(String keyspace, List<ByteBuffer> keys) throws TException
    {
        // TODO Auto-generated method stub
        return null;
    }

    public void batch_mutate(Map<ByteBuffer, Map<String, List<Mutation>>> arg0, ConsistencyLevel arg1)
            throws InvalidRequestException, UnavailableException, TimedOutException, TException
    {
        // TODO Auto-generated method stub

    }

    public String describe_cluster_name() throws TException
    {
        // TODO Auto-generated method stub
        return null;
    }

    public KsDef describe_keyspace(String table) throws NotFoundException, InvalidRequestException, TException
    {
        KSMetaData ksm = DatabaseDescriptor.getTableDefinition(table);
        if (ksm == null)
            throw new NotFoundException();

        List<CfDef> cfDefs = new ArrayList<CfDef>();
        for (CFMetaData cfm : ksm.cfMetaData().values())
            cfDefs.add(CFMetaData.convertToThrift(cfm));
        KsDef ksdef = new KsDef(ksm.name, ksm.strategyClass.getName(), cfDefs);
        ksdef.setStrategy_options(ksm.strategyOptions);
        return ksdef;
    }

    public List<KsDef> describe_keyspaces() throws InvalidRequestException, TException
    {
        Set<String> keyspaces = DatabaseDescriptor.getTables();
        List<KsDef> ksset = new ArrayList<KsDef>();
        for (String ks : keyspaces)
        {
            try
            {
                ksset.add(describe_keyspace(ks));
            }
            catch (NotFoundException nfe)
            {
            }
        }
        return ksset;
    }

    public String describe_partitioner() throws TException
    {
        // TODO Auto-generated method stub
        return null;
    }

    public List<TokenRange> describe_ring(String arg0) throws InvalidRequestException, TException
    {
        return null;
    }

    public Map<String, List<String>> describe_schema_versions() throws InvalidRequestException, TException
    {
        // TODO Auto-generated method stub
        return null;
    }

    public String describe_snitch() throws TException
    {
        // TODO Auto-generated method stub
        return null;
    }

    public List<String> describe_splits(String arg0, String arg1, String arg2, int arg3) throws TException
    {
        // TODO Auto-generated method stub
        return null;
    }

    public String describe_version() throws TException
    {
        // TODO Auto-generated method stub
        return null;
    }

    /**
     * This method tracks down how many times this method has been called.
     */
    public ColumnOrSuperColumn get(ByteBuffer arg0, ColumnPath arg1, ConsistencyLevel arg2)
            throws InvalidRequestException, NotFoundException, UnavailableException, TimedOutException, TException
    {
        counter.incrementAndGet();
        throw new TimedOutException();
    }

    public int get_count(ByteBuffer arg0, ColumnParent arg1, SlicePredicate arg2, ConsistencyLevel arg3)
            throws InvalidRequestException, UnavailableException, TimedOutException, TException
    {
        return counter.incrementAndGet();
    }

    public List<KeySlice> get_indexed_slices(ColumnParent arg0, IndexClause arg1, SlicePredicate arg2,
            ConsistencyLevel arg3) throws InvalidRequestException, UnavailableException, TimedOutException, TException
    {
        // TODO Auto-generated method stub
        return null;
    }

    public List<KeySlice> get_range_slices(ColumnParent arg0, SlicePredicate arg1, KeyRange arg2, ConsistencyLevel arg3)
            throws InvalidRequestException, UnavailableException, TimedOutException, TException
    {
        // TODO Auto-generated method stub
        return null;
    }

    public List<ColumnOrSuperColumn> get_slice(ByteBuffer arg0, ColumnParent arg1, SlicePredicate arg2,
            ConsistencyLevel arg3) throws InvalidRequestException, UnavailableException, TimedOutException, TException
    {
        // TODO Auto-generated method stub
        return null;
    }

    public void insert(ByteBuffer arg0, ColumnParent arg1, Column arg2, ConsistencyLevel arg3)
            throws InvalidRequestException, UnavailableException, TimedOutException, TException
    {
        // TODO Auto-generated method stub

    }

    public void login(AuthenticationRequest arg0) throws AuthenticationException, AuthorizationException, TException
    {
        // TODO Auto-generated method stub

    }

    public Map<ByteBuffer, Integer> multiget_count(List<ByteBuffer> arg0, ColumnParent arg1, SlicePredicate arg2,
            ConsistencyLevel arg3) throws InvalidRequestException, UnavailableException, TimedOutException, TException
    {
        // TODO Auto-generated method stub
        return null;
    }

    public Map<ByteBuffer, List<ColumnOrSuperColumn>> multiget_slice(List<ByteBuffer> arg0, ColumnParent arg1,
            SlicePredicate arg2, ConsistencyLevel arg3) throws InvalidRequestException, UnavailableException,
            TimedOutException, TException
    {
        // TODO Auto-generated method stub
        return null;
    }

    public void remove(ByteBuffer arg0, ColumnPath arg1, long arg2, ConsistencyLevel arg3)
            throws InvalidRequestException, UnavailableException, TimedOutException, TException
    {
        // TODO Auto-generated method stub

    }

    public void set_keyspace(String arg0) throws InvalidRequestException, TException
    {
        // TODO Auto-generated method stub

    }

    public String system_add_column_family(CfDef arg0) throws InvalidRequestException, TException
    {
        // TODO Auto-generated method stub
        return null;
    }

    public String system_add_keyspace(KsDef arg0) throws InvalidRequestException, TException
    {
        return "ok";
    }

    public String system_drop_column_family(String arg0) throws InvalidRequestException, TException
    {
        // TODO Auto-generated method stub
        return null;
    }

    public String system_drop_keyspace(String arg0) throws InvalidRequestException, TException
    {
        // TODO Auto-generated method stub
        return null;
    }

    public String system_update_column_family(CfDef arg0) throws InvalidRequestException, TException
    {
        // TODO Auto-generated method stub
        return null;
    }

    public String system_update_keyspace(KsDef arg0) throws InvalidRequestException, TException
    {
        // TODO Auto-generated method stub
        return null;
    }

    public void truncate(String arg0) throws InvalidRequestException, UnavailableException, TException
    {
        // TODO Auto-generated method stub

    }

    public void add(ByteBuffer arg0, ColumnParent arg1, CounterColumn arg2, ConsistencyLevel arg3)
            throws InvalidRequestException, UnavailableException, TimedOutException, TException
    {
        // TODO Auto-generated method stub
        
    }

    public CqlResult execute_cql_query(ByteBuffer arg0, Compression arg1) throws InvalidRequestException,
            UnavailableException, TimedOutException, SchemaDisagreementException, TException
    {
        // TODO Auto-generated method stub
        return null;
    }

    public void remove_counter(ByteBuffer arg0, ColumnPath arg1, ConsistencyLevel arg2) throws InvalidRequestException,
            UnavailableException, TimedOutException, TException
    {
        // TODO Auto-generated method stub
        
    }

}

@@ -8392,10 +8392,301 @@
 %0A    %7D%0A%0A
+    public LocalOrRemoteBlock get_cfs_block(String callerHostName, ByteBuffer blockId, int offset)%0A            throws InvalidRequestException, UnavailableException, TimedOutException, NotFoundException, TException%0A    %7B%0A        // TODO Auto-generated method stub%0A        return null;%0A    %7D%0A%0A
 %7D%0A

add new service methods