Пример #1
0
 public consumeThreadTask(IMessageHandler messageHandler, MessageCircleQueue queue)
 {
     this.messageHandler = messageHandler;
     this.queue = queue;
 }
Пример #2
0
 public ReportTask(MessageCircleQueue queue, string reportUrl, string appKey, string secret)
 {
     this.queue = queue;
     this.reportUrl = reportUrl;
     this.appKey = appKey;
     this.secret = secret;
     client = new JushitaTopClient(reportUrl, appKey, secret);
     lastReportTime = Message.currentTimeMills();
 }
Пример #3
0
 public void start()
 {
     if (this.messageHandler == null)
         throw new NullReferenceException("messageHandler must not be null");
     if (this.reportUrl == null)
         throw new NullReferenceException("reportUrl must not be null");
     int queueSizeMultiple = 20;
     long reportTimerInterval = 50;
     //初始化消息队列
     queue = new MessageCircleQueue(reportCount * queueSizeMultiple, timeoutSeconds);
     //初始化消费线程数组
     consumerThreads = new Thread[consumerThreadCount];
     //构建消费者线程的Task任务
     consumeTask = new consumeThreadTask(messageHandler, queue);
     //构建线程委托任务
     ThreadStart threadTask = new ThreadStart(consumeTask.doTask);
     for (int i = 0; i < consumerThreads.Length; i++)
     {
         consumerThreads[i] = new Thread(threadTask);
         consumerThreads[i].Start();
     }
     reportTask = new ReportTask(queue, reportUrl, appKey, secret);
     reportTask.reportCount = reportCount;
     reportTask.reportInterval = reportInterval;
     TimerCallback tcb = reportTask.run;
     timerTask = new Timer(tcb, null, reportTimerInterval, reportTimerInterval);
 }