1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 */1819package org.apache.hadoop.chukwa.datacollection.test;
202122import org.apache.hadoop.chukwa.Chunk;
23import org.apache.hadoop.chukwa.datacollection.*;
24import org.apache.hadoop.chukwa.datacollection.agent.*;
25import org.apache.hadoop.chukwa.datacollection.connector.Connector;
26import java.util.*;
2728/**29 * Output events to stdout. Intended for debugging use.30 * 31 */32publicclassConsoleOutConnectorextends Thread implementsConnector {
3334finalChukwaAgent agent;
35volatileboolean shutdown;
36finalboolean silent;
3738publicConsoleOutConnector(ChukwaAgent a) {
39this(a, false);
40 }
4142publicConsoleOutConnector(ChukwaAgent a, boolean silent) {
43 agent = a;
44this.silent = silent;
45 }
4647publicvoid run() {
48try {
49 System.out.println("console connector started");
50ChunkQueue eventQueue = DataFactory.getInstance().getEventQueue();
51if (!silent)
52 System.out.println("-------------------");
5354while (!shutdown) {
55 List<Chunk> evts = new ArrayList<Chunk>();
56 eventQueue.collect(evts, 1);
5758for (Chunk e : evts) {
59if (!silent) {
60 System.out.println("Console out connector got event at offset "61 + e.getSeqID());
62 System.out.println("data type was " + e.getDataType());
63if (e.getData().length > 1000)
64 System.out.println("data length was " + e.getData().length
65 + ", not printing");
66else67 System.out.println(new String(e.getData()));
68 }
6970 agent.reportCommit(e.getInitiator(), e.getSeqID());
7172if (!silent)
73 System.out.println("-------------------");
74 }
75 }
76 } catch (InterruptedException e) {
77 } // thread is about to exit anyway78 }
7980publicvoid shutdown() {
81 shutdown = true;
82this.interrupt();
83 }
8485 @Override
86publicvoid reloadConfiguration() {
87 System.out.println("reloadConfiguration");
88 }
8990 }