All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.kafka.listener.adapter.AbstractDelegatingMessageListenerAdapter Maven / Gradle / Ivy

There is a newer version: 3.1.4
Show newest version
/*
 * Copyright 2016-2019 the original author or authors.
 *
 * Licensed 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
 *
 *      https://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.springframework.kafka.listener.adapter;

import java.util.Collection;
import java.util.Map;

import org.apache.commons.logging.LogFactory;
import org.apache.kafka.common.TopicPartition;

import org.springframework.core.log.LogAccessor;
import org.springframework.kafka.listener.ConsumerSeekAware;
import org.springframework.kafka.listener.DelegatingMessageListener;
import org.springframework.kafka.listener.ListenerType;
import org.springframework.kafka.listener.ListenerUtils;

/**
 * Top level class for all listener adapters.
 *
 * @param  the delegate type.
 *
 * @author Gary Russell
 * @since 1.1
 *
 */
public abstract class AbstractDelegatingMessageListenerAdapter
		implements ConsumerSeekAware, DelegatingMessageListener {

	protected final LogAccessor logger = new LogAccessor(LogFactory.getLog(this.getClass())); // NOSONAR

	protected final T delegate; //NOSONAR

	protected final ListenerType delegateType; // NOSONAR

	private final ConsumerSeekAware seekAware;

	public AbstractDelegatingMessageListenerAdapter(T delegate) {
		this.delegate = delegate;
		this.delegateType = ListenerUtils.determineListenerType(delegate);
		if (delegate instanceof ConsumerSeekAware) {
			this.seekAware = (ConsumerSeekAware) delegate;
		}
		else {
			this.seekAware = null;
		}
	}

	@Override
	public T getDelegate() {
		return this.delegate;
	}

	@Override
	public void registerSeekCallback(ConsumerSeekCallback callback) {
		if (this.seekAware != null) {
			this.seekAware.registerSeekCallback(callback);
		}
	}

	@Override
	public void onPartitionsAssigned(Map assignments, ConsumerSeekCallback callback) {
		if (this.seekAware != null) {
			this.seekAware.onPartitionsAssigned(assignments, callback);
		}
	}

	@Override
	public void onPartitionsRevoked(Collection partitions) {
		if (this.seekAware != null) {
			this.seekAware.onPartitionsRevoked(partitions);
		}
	}

	@Override
	public void onIdleContainer(Map assignments, ConsumerSeekCallback callback) {
		if (this.seekAware != null) {
			this.seekAware.onIdleContainer(assignments, callback);
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy