2 * ===============================LICENSE_START======================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============================LICENSE_END===========================================
21 package org.onap.dcae.apod.analytics.common.service.processor;
23 import org.onap.dcae.apod.analytics.common.utils.MessageProcessorUtils.MessageProcessorFunction;
25 import java.util.List;
27 import static org.onap.dcae.apod.analytics.common.utils.MessageProcessorUtils.computeMessageProcessorChain;
31 * A Generic Message Processor which passes the {@link ProcessorContext} from first to second
32 * {@link MessageProcessor}
35 * @param <P> Processor Context sub classes
37 * @author Rajiv Singla . Creation Date: 11/8/2016.
39 public class GenericMessageChainProcessor<P extends ProcessorContext> {
41 private final List<? extends MessageProcessor<P>> messageProcessors;
42 private final P initialProcessorContext;
44 public GenericMessageChainProcessor(List<? extends MessageProcessor<P>> messageProcessors,
45 P initialProcessorContext) {
46 this.messageProcessors = messageProcessors;
47 this.initialProcessorContext = initialProcessorContext;
51 * Process a processor chain
53 * @return Processor Context after processing the processor chain
55 public P processChain() {
57 final MessageProcessorFunction<P> messageProcessorFunction =
58 new MessageProcessorFunction<P>() {
60 public <M extends MessageProcessor<P>> P apply(P context, M processor) {
61 return processor.apply(context);
65 return computeMessageProcessorChain(messageProcessors, initialProcessorContext,
66 messageProcessorFunction);