Java tutorial
/* * Copyright (C) 2016 An Honest Effort LLC. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package io.radiowitness.kinesis.consumer; import com.amazonaws.services.kinesis.clientlibrary.interfaces.v2.IRecordProcessor; import com.amazonaws.services.kinesis.clientlibrary.interfaces.v2.IRecordProcessorFactory; import com.amazonaws.services.kinesis.clientlibrary.types.ShutdownReason; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public abstract class KinesisRecordConsumerFactory implements IRecordProcessorFactory, FutureCallback<ShutdownReason> { private static final Logger log = LoggerFactory.getLogger(KinesisRecordConsumerFactory.class); protected final SettableFuture<Void> errorFuture; protected KinesisRecordConsumerFactory() { errorFuture = SettableFuture.create(); } protected abstract KinesisRecordConsumer create(SettableFuture<ShutdownReason> shutdown); @Override public IRecordProcessor createProcessor() { log.info("creating new record consumer"); SettableFuture<ShutdownReason> shutdown = SettableFuture.create(); Futures.addCallback(shutdown, this); return create(shutdown); } public ListenableFuture<Void> getErrorFuture() { return errorFuture; } @Override public void onFailure(Throwable throwable) { errorFuture.setException(throwable); } @Override public void onSuccess(ShutdownReason shutdownReason) { } }