public void createTweet() throws AerospikeException, InterruptedException {

    console.printf("\n********** Create Tweet **********\n");

    Record userRecord = null;
    Key userKey = null;
    Key tweetKey = null;

    // Get username
    String username;
    console.printf("\nEnter username:"******"test", "users", username);
      userRecord = client.get(null, userKey);
      if (userRecord != null) {
        int nextTweetCount = Integer.parseInt(userRecord.getValue("tweetcount").toString()) + 1;

        // Get tweet
        String tweet;
        console.printf("Enter tweet for " + username + ":");
        tweet = console.readLine();

        // Write record
        WritePolicy wPolicy = new WritePolicy();
        wPolicy.recordExistsAction = RecordExistsAction.UPDATE;

        // Create timestamp to store along with the tweet so we can
        // query, index and report on it
        long ts = getTimeStamp();

        tweetKey = new Key("test", "tweets", username + ":" + nextTweetCount);
        Bin bin1 = new Bin("tweet", tweet);
        Bin bin2 = new Bin("ts", ts);
        Bin bin3 = new Bin("username", username);

        client.put(wPolicy, tweetKey, bin1, bin2, bin3);
        console.printf("\nINFO: Tweet record created!\n");

        // Update tweet count and last tweet'd timestamp in the user
        // record
        updateUser(client, userKey, wPolicy, ts, nextTweetCount);
      } else {
        console.printf("ERROR: User record not found!\n");
      }
    }
  } // createTweet
예제 #2
0
 @Override
 public void writeAerospike(
     Text sessid,
     Session session,
     AerospikeClient client,
     WritePolicy writePolicy,
     String namespace,
     String setName)
     throws IOException {
   writePolicy.timeout = 10000;
   Key kk = new Key(namespace, setName, sessid.toString());
   Bin bin0 = new Bin("userid", session.userid);
   Bin bin1 = new Bin("start", session.start);
   Bin bin2 = new Bin("end", session.end);
   Bin bin3 = new Bin("nhits", session.nhits);
   Bin bin4 = new Bin("age", session.age);
   Bin bin5 = new Bin("isMale", session.isMale);
   client.put(writePolicy, kk, bin0, bin1, bin2, bin3, bin4, bin5);
 }
  public void createTweets() throws AerospikeException {
    String[] randomTweets = {
      "For just $1 you get a half price download of half of the song and listen to it just once.",
      "People tell me my body looks like a melted candle",
      "Come on movie! Make it start!",
      "Byaaaayy",
      "Please, please, win! Meow, meow, meow!",
      "Put. A. Bird. On. It.",
      "A weekend wasted is a weekend well spent",
      "Would you like to super spike your meal?",
      "We have a mean no-no-bring-bag up here on aisle two.",
      "SEEK: See, Every, EVERY, Kind... of spot",
      "We can order that for you. It will take a year to get there.",
      "If you are pregnant, have a soda.",
      "Hear that snap? Hear that clap?",
      "Follow me and I may follow you",
      "Which is the best cafe in Portland? Discuss...",
      "Portland Coffee is for closers!",
      "Lets get this party started!",
      "How about them portland blazers!",
      "You got school'd, yo",
      "I love animals",
      "I love my dog",
      "What's up Portland",
      "Which is the best cafe in Portland? Discuss...",
      "I dont always tweet, but when I do it is on Tweetaspike"
    };
    Random rnd1 = new Random();
    Random rnd2 = new Random();
    Random rnd3 = new Random();
    Key userKey;
    Record userRecord;
    int totalUsers = 10000;
    int maxTweets = 20;
    String username;
    long ts = 0;

    WritePolicy wPolicy = new WritePolicy();
    wPolicy.recordExistsAction = RecordExistsAction.UPDATE;

    console.printf(
        "\nCreate up to "
            + maxTweets
            + " tweets each for "
            + totalUsers
            + " users. Press any key to continue...\n");
    console.readLine();

    for (int j = 0; j < totalUsers; j++) {
      // Check if user record exists
      username = "******" + rnd3.nextInt(100000);
      userKey = new Key("test", "users", username);
      userRecord = client.get(null, userKey);
      if (userRecord != null) {
        // create up to maxTweets random tweets for this user
        int totalTweets = rnd1.nextInt(maxTweets);
        for (int k = 1; k <= totalTweets; k++) {
          // Create timestamp to store along with the tweet so we can
          // query, index and report on it
          ts = getTimeStamp();
          Key tweetKey = new Key("test", "tweets", username + ":" + k);
          Bin bin1 = new Bin("tweet", randomTweets[rnd2.nextInt(randomTweets.length)]);
          Bin bin2 = new Bin("ts", ts);
          Bin bin3 = new Bin("username", username);

          client.put(wPolicy, tweetKey, bin1, bin2, bin3);
        }
        console.printf("\nWrote " + totalTweets + " tweets for " + username + "!");
        if (totalTweets > 0) {
          // Update tweet count and last tweet'd timestamp in the user
          // record
          client.put(
              wPolicy, userKey, new Bin("tweetcount", totalTweets), new Bin("lasttweeted", ts));
          // console.printf("\nINFO: The tweet count now is: " + totalTweets);
        }
      }
    }
    console.printf(
        "\n\nDone creating up to " + maxTweets + " tweets each for " + totalUsers + " users!\n");
  } // createTweets