Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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 org.apache.flume.configfilter;

/**
* Provides one configuration filter type, selected by the {@code type} property of the filter configuration.
*
* <p>Providers are discovered with {@link java.util.ServiceLoader}:
* register implementations in {@code META-INF/services/org.apache.flume.configfilter.ConfigFilterProvider}.
*/
public interface ConfigFilterProvider {

/**
* Returns the value of the {@code type} configuration property that selects this provider.
*
* <p>Types are compared case-insensitively.
*/
String getName();

/**
* Returns the filter class, which must have a public no-argument constructor.
*/
Class<? extends ConfigFilter> getComponentClass();
}
5 changes: 5 additions & 0 deletions flume-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
<artifactId>log4j-api</artifactId>
</dependency>

<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bnd.annotation</artifactId>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,34 @@
*/
package org.apache.flume.channel;

import aQute.bnd.annotation.Cardinality;
import aQute.bnd.annotation.Resolution;
import aQute.bnd.annotation.spi.ServiceConsumer;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.apache.flume.Channel;
import org.apache.flume.ChannelSelector;
import org.apache.flume.Context;
import org.apache.flume.FlumeException;
import org.apache.flume.conf.BasicConfigurationConstants;
import org.apache.flume.conf.ComponentWithClassName;
import org.apache.flume.conf.Configurables;
import org.apache.flume.conf.channel.ChannelSelectorConfiguration;
import org.apache.flume.conf.channel.ChannelSelectorType;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.flume.spi.ChannelSelectorProvider;
import org.apache.flume.spi.ComponentRegistry;

@ServiceConsumer(
value = ChannelSelectorProvider.class,
resolution = Resolution.OPTIONAL,
cardinality = Cardinality.MULTIPLE)
public class ChannelSelectorFactory {

private static final Logger logger = LogManager.getLogger();
@SuppressWarnings("deprecation")
private static final ComponentRegistry<ChannelSelector> REGISTRY = new ComponentRegistry<>(
ChannelSelectorProvider.class,
ChannelSelector.class,
"channel selector",
type -> ComponentWithClassName.getClassName(ChannelSelectorType.class, type));

public static ChannelSelector create(List<Channel> channels, Map<String, String> config) {

Expand Down Expand Up @@ -62,31 +73,6 @@ private static ChannelSelector getSelectorForType(String type) {
if (type == null || type.trim().length() == 0) {
return new ReplicatingChannelSelector();
}

String selectorClassName = type;
ChannelSelectorType selectorType = ChannelSelectorType.OTHER;

try {
selectorType = ChannelSelectorType.valueOf(type.toUpperCase(Locale.ENGLISH));
} catch (IllegalArgumentException ex) {
logger.debug("Selector type {} is a custom type", type);
}

if (!selectorType.equals(ChannelSelectorType.OTHER)) {
selectorClassName = selectorType.getChannelSelectorClassName();
}

ChannelSelector selector = null;

try {
@SuppressWarnings("unchecked")
Class<? extends ChannelSelector> selectorClass =
(Class<? extends ChannelSelector>) Class.forName(selectorClassName);
selector = selectorClass.newInstance();
} catch (Exception ex) {
throw new FlumeException("Unable to load selector type: " + type + ", class: " + selectorClassName, ex);
}

return selector;
return REGISTRY.newInstance(type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,50 +16,43 @@
*/
package org.apache.flume.channel;

import aQute.bnd.annotation.Cardinality;
import aQute.bnd.annotation.Resolution;
import aQute.bnd.annotation.spi.ServiceConsumer;
import com.google.common.base.Preconditions;
import java.util.Locale;
import org.apache.flume.Channel;
import org.apache.flume.ChannelFactory;
import org.apache.flume.FlumeException;
import org.apache.flume.conf.ComponentWithClassName;
import org.apache.flume.conf.channel.ChannelType;
import org.apache.flume.spi.ChannelProvider;
import org.apache.flume.spi.ComponentRegistry;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@ServiceConsumer(value = ChannelProvider.class, resolution = Resolution.OPTIONAL, cardinality = Cardinality.MULTIPLE)
public class DefaultChannelFactory implements ChannelFactory {

private static final Logger logger = LogManager.getLogger();

@SuppressWarnings("deprecation")
private static final ComponentRegistry<Channel> REGISTRY = new ComponentRegistry<>(
ChannelProvider.class,
Channel.class,
"channel",
type -> ComponentWithClassName.getClassName(ChannelType.class, type));

@Override
public Channel create(String name, String type) throws FlumeException {
Preconditions.checkNotNull(name, "name");
Preconditions.checkNotNull(type, "type");
logger.info("Creating instance of channel {} type {}", name, type);
Class<? extends Channel> channelClass = getClass(type);
try {
return channelClass.newInstance();
} catch (Exception ex) {
throw new FlumeException(
"Unable to create channel: " + name + ", type: " + type + ", class: " + channelClass.getName(), ex);
}
logger.info("Creating instance of channel {}, type {}", name, type);
return REGISTRY.newInstance(type);
}

@SuppressWarnings("unchecked")
@Override
public Class<? extends Channel> getClass(String type) throws FlumeException {
String channelClassName = type;
ChannelType channelType = ChannelType.OTHER;
try {
channelType = ChannelType.valueOf(type.toUpperCase(Locale.ENGLISH));
} catch (IllegalArgumentException ex) {
logger.debug("Channel type {} is a custom type", type);
}
if (!channelType.equals(ChannelType.OTHER)) {
channelClassName = channelType.getChannelClassName();
}
try {
return (Class<? extends Channel>) Class.forName(channelClassName);
} catch (Exception ex) {
throw new FlumeException("Unable to load channel type: " + type + ", class: " + channelClassName, ex);
}
Preconditions.checkNotNull(type, "type");
return REGISTRY.getComponentClass(type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@
*/
package org.apache.flume.channel;

import aQute.bnd.annotation.Resolution;
import aQute.bnd.annotation.spi.ServiceProvider;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.flume.Channel;
import org.apache.flume.ChannelSelector;
import org.apache.flume.Context;
import org.apache.flume.conf.internal.SuppressFBWarnings;
import org.apache.flume.event.Event;
import org.apache.flume.spi.AbstractComponentProvider;
import org.apache.flume.spi.ChannelSelectorProvider;

/**
* Load balancing channel selector. This selector allows for load balancing
Expand Down Expand Up @@ -143,4 +148,16 @@ public Channel getChannel() {
return channels.get(pick);
}
}

/**
* Provides the {@code load_balancing} channel selector type.
*/
@ServiceProvider(value = ChannelSelectorProvider.class, resolution = Resolution.OPTIONAL)
public static final class Provider extends AbstractComponentProvider<ChannelSelector>
implements ChannelSelectorProvider {

public Provider() {
super("load_balancing", LoadBalancingChannelSelector.class);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
*/
package org.apache.flume.channel;

import aQute.bnd.annotation.Resolution;
import aQute.bnd.annotation.spi.ServiceProvider;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import javax.annotation.concurrent.GuardedBy;
import org.apache.flume.Channel;
import org.apache.flume.Context;
import org.apache.flume.annotations.InterfaceAudience;
import org.apache.flume.annotations.InterfaceStability;
Expand All @@ -31,6 +34,8 @@
import org.apache.flume.exception.ChannelException;
import org.apache.flume.exception.ChannelFullException;
import org.apache.flume.instrumentation.ChannelCounter;
import org.apache.flume.spi.AbstractComponentProvider;
import org.apache.flume.spi.ChannelProvider;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -396,4 +401,15 @@ int getBytesRemainingValue() {
public long getTransactionCapacity() {
return transCapacity;
}

/**
* Provides the {@code memory} channel type.
*/
@ServiceProvider(value = ChannelProvider.class, resolution = Resolution.OPTIONAL)
public static final class Provider extends AbstractComponentProvider<Channel> implements ChannelProvider {

public Provider() {
super("memory", MemoryChannel.class);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@
*/
package org.apache.flume.channel;

import aQute.bnd.annotation.Resolution;
import aQute.bnd.annotation.spi.ServiceProvider;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.flume.Channel;
import org.apache.flume.ChannelSelector;
import org.apache.flume.Context;
import org.apache.flume.FlumeException;
import org.apache.flume.conf.internal.SuppressFBWarnings;
import org.apache.flume.event.Event;
import org.apache.flume.spi.AbstractComponentProvider;
import org.apache.flume.spi.ChannelSelectorProvider;

@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
public class MultiplexingChannelSelector extends AbstractChannelSelector {
Expand Down Expand Up @@ -126,4 +131,16 @@ public void configure(Context context) {
}
}
}

/**
* Provides the {@code multiplexing} channel selector type.
*/
@ServiceProvider(value = ChannelSelectorProvider.class, resolution = Resolution.OPTIONAL)
public static final class Provider extends AbstractComponentProvider<ChannelSelector>
implements ChannelSelectorProvider {

public Provider() {
super("multiplexing", MultiplexingChannelSelector.class);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@
*/
package org.apache.flume.channel;

import aQute.bnd.annotation.Resolution;
import aQute.bnd.annotation.spi.ServiceProvider;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.flume.Channel;
import org.apache.flume.ChannelSelector;
import org.apache.flume.Context;
import org.apache.flume.event.Event;
import org.apache.flume.spi.AbstractComponentProvider;
import org.apache.flume.spi.ChannelSelectorProvider;

/**
* Replicating channel selector. This selector allows the event to be placed
Expand Down Expand Up @@ -70,4 +75,16 @@ public void configure(Context context) {
}
}
}

/**
* Provides the {@code replicating} channel selector type.
*/
@ServiceProvider(value = ChannelSelectorProvider.class, resolution = Resolution.OPTIONAL)
public static final class Provider extends AbstractComponentProvider<ChannelSelector>
implements ChannelSelectorProvider {

public Provider() {
super("replicating", ReplicatingChannelSelector.class);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.flume.channel;

import aQute.bnd.annotation.Resolution;
import aQute.bnd.annotation.spi.ServiceProvider;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -29,6 +31,8 @@
import org.apache.flume.Context;
import org.apache.flume.conf.Configurables;
import org.apache.flume.event.Event;
import org.apache.flume.spi.AbstractComponentProvider;
import org.apache.flume.spi.ChannelSelectorProvider;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -124,4 +128,16 @@ private String getRequiredNonNull(Map<String, String> map, String keyName, Strin
}
return value;
}

/**
* Provides the {@code routable_proxy} channel selector type.
*/
@ServiceProvider(value = ChannelSelectorProvider.class, resolution = Resolution.OPTIONAL)
public static final class Provider extends AbstractComponentProvider<ChannelSelector>
implements ChannelSelectorProvider {

public Provider() {
super("routable_proxy", RoutableProxyChannelSelector.class);
}
}
}
Loading
Loading