Ich bin neu bei Apache-Cassandra 0.8.2. Ich versuche, einige Daten einzufügen, erhalte aber diese Ausnahme.
Exception in thread "main" UnavailableException()
at org.apache.cassandra.thrift.Cassandra$insert\_result.read(Cassandra.java:14902)
at org.apache.cassandra.thrift.Cassandra$Client.recv\_insert(Cassandra.java:858)
at org.apache.cassandra.thrift.Cassandra$Client.insert(Cassandra.java:830)
at TestCassandra.main(TestCassandra.java:166)
Mein Code lautet:
public class TestCassandra {
public static void createKeySpace( Cassandra.Client client,String ksname)
throws TException, InvalidRequestException, UnavailableException, UnsupportedEncodingException, NotFoundException, TimedOutException, SchemaDisagreementException {
KsDef ksdef = new KsDef();
ksdef.name = ksname;
ksdef.strategy\_class = "NetworkTopologyStrategy";
List l = new ArrayList();
ksdef.cf\_defs =l;
client.system\_add\_keyspace(ksdef);
System.out.println("KeySpace Created");
}
public static void createColumnFamily(Cassandra.Client client,String ksname,String cfname)
throws TException, InvalidRequestException, UnavailableException, UnsupportedEncodingException, NotFoundException, TimedOutException, SchemaDisagreementException {
CfDef cfd = new CfDef(ksname, cfname);
client.system\_add\_column\_family(cfd);
System.out.println("ColumnFamily Created");
}
public static void main(String\[\] args)
throws TException, InvalidRequestException, UnavailableException, UnsupportedEncodingException, NotFoundException, TimedOutException, SchemaDisagreementException {
TTransport tr = new TFramedTransport(new TSocket("localhost", 9160));
TProtocol proto = new TBinaryProtocol(tr);
Cassandra.Client client = new Cassandra.Client(proto);
tr.open();
String keySpace = "Keyspace1";
String columnFamily = "Users";
//Drop the Keyspace
client.system\_drop\_keyspace(keySpace);
//Creating keyspace
KsDef ksdef = new KsDef();
ksdef.name = keySpace;
ksdef.strategy\_class = "NetworkTopologyStrategy";
List l = new ArrayList();
ksdef.cf\_defs =l;
client.system\_add\_keyspace(ksdef);
System.out.println("KeySpace Created");
//createKeySpace(client,keySpace);
client.set\_keyspace(keySpace);
//Creating column Family
CfDef cfd = new CfDef(keySpace, columnFamily);
client.system\_add\_column\_family(cfd);
System.out.println("ColumnFamily Created");
//createColumnFamily(client,keySpace,columnFamily);
ColumnParent parent = new ColumnParent(columnFamily);
Column description = new Column();
description.setName("description".getBytes());
description.setValue("I’m a nice guy".getBytes());
description.setTimestamp(System.currentTimeMillis());
ConsistencyLevel consistencyLevel = ConsistencyLevel.ONE;
ByteBuffer rowid = ByteBuffer.wrap("0".getBytes());
//Line No. 166
client.insert(rowid, parent, description, consistencyLevel);
System.out.println("Record Inserted...");
tr.flush();
tr.close();
}
}
Kann mir jemand sagen, warum das so ist?