// Enqueue the Tweets received public void WriteTweet(TweetSentimentData tweet) { lock (this.WriteQueue) { this.WriteQueue.Enqueue(tweet); } }
// Popular a CellSet object to be written into HBase private void CreateTweetByWordsCells(CellSet set, TweetSentimentData tweet) { // Create a row with a key var row = new CellSet.Row { key = Encoding.UTF8.GetBytes(tweet.Id) }; // Add columns to the row row.values.Add( new Cell { column = Encoding.UTF8.GetBytes("d:Text"), data = Encoding.UTF8.GetBytes(tweet.Text) }); row.values.Add( new Cell { column = Encoding.UTF8.GetBytes("d:CreatedOn"), data = Encoding.UTF8.GetBytes(tweet.CreatedOn.ToString()) }); row.values.Add( new Cell { column = Encoding.UTF8.GetBytes("d:ReplyToId"), data = Encoding.UTF8.GetBytes(tweet.ReplyToId) }); row.values.Add( new Cell { column = Encoding.UTF8.GetBytes("d:Sentiment"), data = Encoding.UTF8.GetBytes(tweet.Sentiment.ToString()) }); if (tweet.Coordinates != null) { row.values.Add( new Cell { column = Encoding.UTF8.GetBytes("d:Coordinates"), data = Encoding.UTF8.GetBytes(tweet.Coordinates) }); } set.rows.Add(row); }
// Write a Tweet (CellSet) to HBase public void WriterThreadFunction() { while (ThreadRunning) { if (WriteQueue.Count > 0) { CellSet set = new CellSet(); lock (WriteQueue) { do { TweetSentimentData tweet = WriteQueue.Dequeue(); CreateTweetByWordsCells(set, tweet); } while (WriteQueue.Count > 0); } // Write the Tweet by words cell set to the HBase table client.StoreCells(this.HBaseTableName, set); Console.WriteLine("\tRows written: {0}", set.rows.Count); } } }