示例#1
0
  public Tweet getTweet(String tweetid) {

    Map<String, String> map = cassandra.listColumns(tweetid, TWEETS, false);

    return new Tweet(
        tweetid.getBytes(),
        map.get("uname"),
        map.get("body"),
        map.get("timestamp") == null ? null : Long.parseLong(map.get("timestamp")));
  }
示例#2
0
  private Timeline getLine(
      String COL_FAM, String uname, String startkey, int count, final boolean reversed) {

    Map<String, String> map = cassandra.listColumns(uname, COL_FAM, startkey, count, reversed);

    if (null == map || 0 == map.size()) {
      return null;
    }

    List<String> tweetids = ImmutableList.<String>copyOf(map.values());
    List<Tweet> tweets = getTweetsForTweetids(tweetids);

    return new Timeline(tweets, Long.valueOf(String.valueOf(getLast(map.keySet(), 0))));

    /*
     * Selector selector = makeSel(); List<Column> timeline; byte[]
     * longTypeStartKey = (startkey.equals("") ? new byte[0] :
     * NumberHelper.toBytes(Long.parseLong(startkey))); try { timeline =
     * selector.getColumnsFromRow(uname, COL_FAM,
     * Selector.newColumnsPredicate(longTypeStartKey,new
     * byte[0],true,count+1), RCL); } catch (Exception e) {
     * log.error("Unable to retrieve timeline for uname: " + uname); return
     * null; } Long mintimestamp = null; if (timeline.size() > count) {
     * //find min timestamp mintimestamp = Long.MAX_VALUE; Column removeme =
     * timeline.get(0); //This cannot fail. Count is 0+, and size is thus
     * 1+. Only needed for initialization. for (Column c : timeline) { long
     * ctime = ByteBuffer.wrap(c.name).getLong(); if (ctime < mintimestamp)
     * { mintimestamp = ctime; removeme = c; } } //eject column from list
     * after saving the timestamp timeline.remove(removeme); }
     * ArrayList<String> tweetids = new ArrayList<String>(timeline.size());
     * for (Column c : timeline) { tweetids.add(bToS(c.value)); }
     * Map<String, List<Column>> unordered_tweets = Collections.emptyMap();
     * try { unordered_tweets = selector.getColumnsFromRows(tweetids,
     * TWEETS, SPall(), RCL); } catch (Exception e) {
     * log.error("Unable to retrieve tweets from timeline for uname: " +
     * uname); return null; } //Order the tweets by the ordered tweetids
     * ArrayList<Tweet> ordered_tweets = new
     * ArrayList<Tweet>(tweetids.size()); for (String tweetid : tweetids) {
     * ordered_tweets
     * .add(makeTweet(tweetid.getBytes(),unordered_tweets.get(tweetid))); }
     * return new Timeline(ordered_tweets, mintimestamp);
     */

    // return null;
  }
示例#3
0
  // Helpers
  private List<String> getFriendOrFollowerUnames(String COL_FAM, String uname, int count) {

    Map<String, String> map = cassandra.listColumns(uname, COL_FAM, null, count, false);
    return ImmutableList.<String>copyOf(map.keySet());
  }