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.*;
21import java.util.regex.*;
22import org.apache.hadoop.chukwa.Chunk;
23import org.apache.hadoop.chukwa.datacollection.ChunkReceiver;
24import org.apache.hadoop.chukwa.datacollection.agent.AdaptorFactory;
25import org.apache.hadoop.chukwa.datacollection.agent.AdaptorManager;
2627publicclassAbstractWrapperimplements NotifyOnCommitAdaptor,ChunkReceiver {
2829Adaptorinner;
30 String innerClassName;
31 String innerType;
32ChunkReceiver dest;
33AdaptorManager manager;
34 String adaptorID;
35 @Override
36public String getCurrentStatus() {
37return innerClassName + " " + inner.getCurrentStatus();
38 }
394041static Pattern p = Pattern.compile("([^ ]+) +([^ ].*)");
4243/**44 * Note that the name of the inner class will get parsed out as a type45 */46 @Override
47public String parseArgs(String innerClassName, String params, AdaptorManager a) {
48 manager = a;
49 Matcher m = p.matcher(params);
50this.innerClassName = innerClassName;
51 String innerCoreParams;
52if(m.matches()) {
53 innerType = m.group(1);
54inner = AdaptorFactory.createAdaptor(innerClassName);
55 innerCoreParams = inner.parseArgs(innerType,m.group(2),a);
56return innerClassName + innerCoreParams;
57 }
58elsereturnnull;
59 }
6061 @Override
62publiclong shutdown(AdaptorShutdownPolicy shutdownPolicy)
63throwsAdaptorException {
64returninner.shutdown(shutdownPolicy);
65 }
6667 @Override
68public String getType() {
69return innerType;
70 }
7172/**73 * Note that the name of the inner class will get parsed out as a type74 */75 @Override
76publicvoid start(String adaptorID, String type, long offset,
77ChunkReceiver dest) throws AdaptorException {
78 String dummyAdaptorID = adaptorID;
79this.dest = dest;
80this.adaptorID = adaptorID;
81inner.start(dummyAdaptorID, type, offset, this);
82 }
8384 @Override
85publicvoid add(Chunk event) throws InterruptedException {
86 dest.add(event);
87 }
8889 @Override
90publicvoid committed(long commitedByte) { }
9192 }