416DAT

Check-in [2e47e1000f]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added couch client.. for real this time!
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:2e47e1000ff98e56a2195588c1550d6ae7d8beec
User & Date: jchezenko 2013-04-09 06:31:23
Context
2013-04-09
06:33
cleand up duplicate couchbase clients and boring files check-in: af1efca2d4 user: jchezenko tags: trunk
06:31
Added couch client.. for real this time! check-in: 2e47e1000f user: jchezenko tags: trunk
06:25
Added webpage, couchClient.java, ruby scripts check-in: 713aa0ce75 user: jchezenko tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added couchbase/db/CouchClient.java.





























































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.Vector;
import java.util.concurrent.atomic.AtomicInteger;

import com.couchbase.client.CouchbaseClient;
import com.couchbase.client.*;
import java.io.IOException;
import java.net.URI;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import net.spy.memcached.internal.OperationFuture;
import net.spy.memcached.internal.GetFuture;

import com.yahoo.ycsb.ByteArrayByteIterator;
import com.yahoo.ycsb.ByteIterator;
import com.yahoo.ycsb.DB;
import com.yahoo.ycsb.DBException;

import org.json.simple.JSONValue;

public class CouchClient extends DB {


  // the unique key of the document
  public static final String KEY = "beer_Wrath";

  // expiration time of the document (use 0 to persist forever)
  public static final int EXP_TIME = 0;
  public CouchbaseClient client = null;

  public CouchClient(){
    client=null;
  }

  public void init() throws DBException {

    Properties props = getProperties();
    //do soemethign with properties.
    props.list(System.out);

    // Set the URIs and get a client
    List<URI> uris = new LinkedList<URI>();

    CouchbaseConnectionFactoryBuilder cfb = new CouchbaseConnectionFactoryBuilder();
    cfb.setOpQueueMaxBlockTime(100000); // wait up to 5 seconds when trying to enq

    // Connect to localhost or to the appropriate URI(s)
    //uris.add(URI.create("http://192.168.1.101:8091/pools"));
    //    uris.add(URI.create("http://localhost:8091/pools"));
     uris.add(URI.create("http://10.249.39.43:8091/pools"));
    // uris.add(URI.create("http://10.254.16.112:8091/pools"));
    // uris.add(URI.create("http://10.254.20.155:8091/pools"));
    // uris.add(URI.create("http://10.254.27.60:8091/pools"));
    // uris.add(URI.create("http://10.253.39.9:8091/pools"));
    try {
      // Use the "default" bucket with no password
      client = new CouchbaseClient(cfb.buildCouchbaseConnection(uris, "usertable", ""));
      System.out.println("couch base connected!");
    } catch (IOException e) {
      System.err.println("IOException connecting to Couchbase: " + e.getMessage());
      System.exit(1);
    }    

  }

   //Read a single record
  @Override
  public int read(String table, String key, Set<String> fields, HashMap<String,ByteIterator> result){
    //System.out.println("Couchbase client: inside read");
    Object obj;
    GetFuture getOp = client.asyncGet(key);
    try {
	if((obj = getOp.get()) != null) {
	    System.out.println("async get suceeded");
	    return 0;
	} else {
	    //System.err.println("async get failed");
	    return 1;
	}
    } catch (Exception e){
	System.err.println("Exception async get:" + e.getMessage());
	return 1;
    }
  }

  //Perform a range scan
  @Override
  public int scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String,ByteIterator>> result){
      //System.out.println("Couchbase client: inside scan");
      return 0;
  }
  
  //Update a single record
  @Override
  public int update(String table, String key, HashMap<String,ByteIterator> values){
      //System.out.println("Couchbase client: inside update");
      client.replace(key,0,JSONValue.toJSONString(values));
      return 0;
  }

  //Insert a single record
  @Override
  public int insert(String table, String key, HashMap<String,ByteIterator> values){
      // Do an asynchronous set
    //System.out.println("the table is: " + table);
    //System.out.println("the key is :" + key);

    //System.out.println("the values are as follows");
    //System.out.println("the size of the hash map is:" + values.size());
      
    
	  OperationFuture<Boolean> setOp = client.set(key, 0,JSONValue.toJSONString(values));
    //System.out.println("set the testvalue");

    // long unixTime = System.currentTimeMillis() / 1000L;
    // if(unixTime % 60==0){
    // 	//System.out.println(unixTime);
    // }
    
    // Check to see if our set succeeded
    try {
      if (setOp.get().booleanValue()) {
        //System.out.println("Set Succeeded");
      } else {
        System.err.println("Set failed: " + setOp.getStatus().getMessage());
        return 1;
      }
    } catch (InterruptedException e) {
      System.err.println("InterruptedException while doing set: " + e.getMessage());
      return 1;
    } catch (ExecutionException e) {
      System.err.println("ExecutionException while doing set: " + e.getMessage());
      return 1;
    }

    // Shutdown and wait a maximum of three seconds to finish up operations
    //client.shutdown(3, TimeUnit.SECONDS);
    //System.out.println("Couchbase client: inside insert");
    return 0;
  }

  //Delete a single record
  @Override
  public int delete(String table, String key){
    System.out.println("Couchbase client: inside delete");
    client.delete(key);
    return 0;
  }
    // /**
    //  * Cleanup any state for this DB.
    //  * Called once per DB instance; there is one DB instance per client thread.
    //  */
    // @Override
    // public void cleanup() throws DBException {
    //     if (initCount.decrementAndGet() <= 0) {
    //         try {
    //             mongo.close();
    //         }
    //         catch (Exception e1) {
    //             System.err.println("Could not close MongoDB connection pool: "
    //                     + e1.toString());
    //             e1.printStackTrace();
    //             return;
    //         }
    //     }
    // }

}

Deleted test1Results/readme.txt.

1
2
3
4
5
Test 1 Setup:



Test 1 Results Format: 
<
<
<
<
<










Deleted test1Results/readme.txt~.