예제 #1
0
 // Enqueue the Tweets received
 public void WriteTweet(TweetSentimentData tweet)
 {
     lock (this.WriteQueue)
     {
         this.WriteQueue.Enqueue(tweet);
     }
 }
예제 #2
0
        // 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);
        }
예제 #3
0
 // 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);
         }
     }
 }