/** * Licensed to Cloudera, Inc. under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. Cloudera, Inc. licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.cloudera.flume.conf; import java.util.Collections; import java.util.HashSet; import java.util.Set; import com.cloudera.flume.core.EventSink; import com.cloudera.flume.core.EventSinkDecorator; import com.google.common.base.Preconditions; /** * This provides a linked symbol table structure useful for handling symbolic * sinks generated by let declarations contexts. */ public class LinkedSinkFactory extends SinkFactory { SinkFactory parent; String sinkname; EventSink sink; public LinkedSinkFactory(SinkFactory parent, String name, EventSink snk) { Preconditions.checkArgument(parent != null); Preconditions.checkArgument(name != null); Preconditions.checkArgument(snk != null); this.parent = parent; this.sinkname = name; this.sink = snk; } @Override public EventSinkDecorator<EventSink> getDecorator(Context context, String name, String... args) throws FlumeSpecException { return parent.getDecorator(context, name, args); } @Override public EventSink getSink(Context context, String name, String... args) throws FlumeSpecException { if (sinkname.equals(name)) { // TODO (jon) we are actually close to allowing in sink templates return sink; } return parent.getSink(context, name, args); } @Override public Set<String> getSinkNames() { HashSet<String> set = new HashSet<String>(parent.getSinkNames()); set.add(sinkname); return Collections.unmodifiableSet(set); } @Override public Set<String> getDecoratorNames() { return parent.getDecoratorNames(); } }