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 */18package org.apache.hadoop.chukwa.datacollection.adaptor;
1920import java.util.regex.*;
21import org.apache.hadoop.chukwa.Chunk;
22import org.apache.hadoop.chukwa.datacollection.ChunkReceiver;
23import org.apache.hadoop.chukwa.datacollection.agent.AdaptorFactory;
24import org.apache.hadoop.chukwa.datacollection.agent.AdaptorManager;
2526publicclassAbstractWrapperimplements NotifyOnCommitAdaptor,ChunkReceiver {
2728Adaptorinner;
29 String innerClassName;
30 String innerType;
31ChunkReceiver dest;
32AdaptorManager manager;
33 String adaptorID;
34 @Override
35public String getCurrentStatus() {
36return innerClassName + " " + inner.getCurrentStatus();
37 }
383940static Pattern p = Pattern.compile("([^ ]+) +([^ ].*)");
4142/**43 * Note that the name of the inner class will get parsed out as a type44 */45 @Override
46public String parseArgs(String innerClassName, String params, AdaptorManager a) {
47 manager = a;
48 Matcher m = p.matcher(params);
49this.innerClassName = innerClassName;
50 String innerCoreParams;
51if(m.matches()) {
52 innerType = m.group(1);
53inner = AdaptorFactory.createAdaptor(innerClassName);
54 innerCoreParams = inner.parseArgs(innerType,m.group(2),a);
55return innerClassName + innerCoreParams;
56 }
57elsereturnnull;
58 }
5960 @Override
61publiclong shutdown(AdaptorShutdownPolicy shutdownPolicy)
62throwsAdaptorException {
63returninner.shutdown(shutdownPolicy);
64 }
6566 @Override
67public String getType() {
68return innerType;
69 }
7071/**72 * Note that the name of the inner class will get parsed out as a type73 */74 @Override
75publicvoid start(String adaptorID, String type, long offset,
76ChunkReceiver dest) throws AdaptorException {
77 String dummyAdaptorID = adaptorID;
78this.dest = dest;
79this.adaptorID = adaptorID;
80inner.start(dummyAdaptorID, type, offset, this);
81 }
8283 @Override
84publicvoid add(Chunk event) throws InterruptedException {
85 dest.add(event);
86 }
8788 @Override
89publicvoid committed(long commitedByte) { }
9091 }