changeset 6:406fc1bd3251

Added -rep [num] option for setting of Replication factor
author Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 21 Jan 2014 08:09:32 +0900
parents 30717a443cd5
children a051a107abf2
files src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/App.java src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/CassandraBulletinBoard.java
diffstat 2 files changed, 29 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/App.java	Thu Jan 09 23:19:29 2014 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/App.java	Tue Jan 21 08:09:32 2014 +0900
@@ -20,25 +20,26 @@
     	if(args.length == 0){
     		cassaBBS = new JungleBulletinBoard();
     	}else{
-    		for(String arg : args) {
-    			if(arg.equals("-all")) {
-    				System.out.println("ConsistencyLevel ALL");
-    	       		cassaBBS = new CassandraBulletinBoard("test-cluster","localhost:9160","cassaBBS2",HConsistencyLevel.ALL);
-    	       		break;
-    			}else if(arg.equals("-one")){
-    				System.out.println("ConsistencyLevel ONE");
-    	       		cassaBBS = new CassandraBulletinBoard("test-cluster","localhost:9160","cassaBBS2",HConsistencyLevel.ONE);
-    	       		break;
-    			}else if(arg.equals("-quorum")){
-    				System.out.println("ConsistencyLevel QUORUM");
-    				cassaBBS = new CassandraBulletinBoard("test-cluster","localhost:9160","cassaBBS2",HConsistencyLevel.QUORUM);
-    			}else{
-    				System.out.println("ConsistencyLevel QUORUM");
-    				cassaBBS = new CassandraBulletinBoard("test-cluster","localhost:9160","cassaBBS2",HConsistencyLevel.QUORUM);
-    				break;
+    		HConsistencyLevel cLevel = HConsistencyLevel.QUORUM;
+    		int rep_factor = 1;
+    		int i=0;
+    		while(i<args.length) {
+    			if(args[i].equals("-all")) {
+    				cLevel = HConsistencyLevel.ALL;
+    			}else if(args[i].equals("-one")){
+    				cLevel = HConsistencyLevel.ONE;
+    			}else if(args[i].equals("-quorum")){
+    				cLevel = HConsistencyLevel.QUORUM;
+    			}else if(args[i].equals("-rep")){
+    				i++;
+    				rep_factor = Integer.parseInt(args[i]);
     			}
+    			i++;
     		}
-    	}
+			System.out.println("ConsistencyLevel "+cLevel.toString());
+			System.out.println("Replication factor "+rep_factor);
+       		cassaBBS = new CassandraBulletinBoard("test-cluster","localhost:9160","cassaBBS2", cLevel, rep_factor);
+   		}
     	
     	String createBoardMessagePath = "/createBoardMessage";
     	String createBoardPath = "/createBoard";
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/CassandraBulletinBoard.java	Thu Jan 09 23:19:29 2014 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/bbs/CassandraBulletinBoard.java	Tue Jan 21 08:09:32 2014 +0900
@@ -40,8 +40,9 @@
 	private final ConfigurableConsistencyLevel configurableConsistencyLevel = new ConfigurableConsistencyLevel(); 
 	
 	private static final String COLUMN_FAMILY_BOARD = "boards";
+	private final int REP_FACTOR;
 	
-	public CassandraBulletinBoard(String _clusterName,String _address,String _keyspaceName, HConsistencyLevel cLevel)
+	public CassandraBulletinBoard(String _clusterName,String _address,String _keyspaceName, HConsistencyLevel cLevel,int rep_factor )
 	{
 		address = _address;
 		clusterName = _clusterName;
@@ -51,14 +52,22 @@
 		clmap.put(COLUMN_FAMILY_BOARD, cLevel);
 		configurableConsistencyLevel.setReadCfConsistencyLevels(clmap);
 		configurableConsistencyLevel.setWriteCfConsistencyLevels(clmap);
+		REP_FACTOR = rep_factor;
 		initialize();
 	}
 	
+	public CassandraBulletinBoard(String _clusterName,String _address,String _keyspaceName, HConsistencyLevel cLevel)
+	{
+		this(_clusterName, _address, _keyspaceName, cLevel, 1);		
+	}
+	
+	
+	
 	private void initialize()
 	{
 		if(cluster.describeKeyspace(keyspace) == null){
 			KeyspaceDefinition keyspaceDefinition = HFactory.createKeyspaceDefinition(keyspace,
-					SimpleStrategy.class.getName(),1,Collections.<ColumnFamilyDefinition> emptyList());
+					SimpleStrategy.class.getName(),REP_FACTOR,Collections.<ColumnFamilyDefinition> emptyList());
 			cluster.addKeyspace(keyspaceDefinition,false);
 			ColumnFamilyDefinition columnFamilyDefinition = HFactory.createColumnFamilyDefinition(keyspace,COLUMN_FAMILY_BOARD,ComparatorType.UUIDTYPE);
 			columnFamilyDefinition.setColumnType(ColumnType.SUPER);