001/*
002 * (C) Copyright 2017 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     bdelbosc
018 */
019package org.nuxeo.ecm.platform.importer.mqueues.computation;
020
021import java.util.stream.Collectors;
022import java.util.stream.IntStream;
023
024/**
025 * An abstract {@link Computation} that manage the metadata init.
026 * The inputs streams are named i1, i2 ...
027 * The output streams are named o1, o2 ...
028 *
029 * @since 9.2
030 */
031public abstract class AbstractComputation implements Computation {
032    protected ComputationMetadata metadata;
033
034    public AbstractComputation(String name, int nbInputStreams, int nbOutputStreams) {
035        this.metadata = new ComputationMetadata(
036                name,
037                IntStream.range(1, nbInputStreams + 1).boxed().map(i -> "i" + i).collect(Collectors.toSet()),
038                IntStream.range(1, nbOutputStreams + 1).boxed().map(i -> "o" + i).collect(Collectors.toSet()));
039    }
040
041    @Override
042    public void init(ComputationContext context) {
043
044    }
045
046    @Override
047    public void destroy() {
048
049    }
050
051    @Override
052    public void processTimer(ComputationContext context, String key, long timestamp) {
053
054    }
055
056    @Override
057    public ComputationMetadata metadata() {
058        return metadata;
059    }
060}