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 *     Adapted from https://github.com/concord/concord-jvm
018 *     bdelbosc
019 */
020package org.nuxeo.ecm.platform.importer.mqueues.computation;
021
022
023/**
024 * Computation receive record from input streams one at a time, it can produce record on its output streams.
025 * A timer processing can be used to windowing computation.
026 *
027 * @since 9.2
028 */
029public interface Computation {
030
031    /**
032     * Called when the framework has registered the computation successfully.
033     * Gives users a first opportunity to schedule timer callbacks and produce records.
034     *
035     * @param context The computation context object provided by the system.
036     */
037    void init(ComputationContext context);
038
039    /**
040     * Called when the framework is ready to shutdown the computation.
041     * Gives users a chance to perform some cleanup before the process is killed.
042     */
043    void destroy();
044
045    /**
046     * Process an incoming record on one of the computation's input streams.
047     *
048     * @param context The computation context object provided by the system.
049     * @param inputStreamName Name of the input stream that provides the record.
050     * @param record The record.
051     */
052    void processRecord(ComputationContext context, String inputStreamName, Record record);
053
054    /**
055     * Process a timer callback previously set via {@link ComputationContext#setTimer(String, long)}.
056     *
057     * @param context The computation context object provided by the system.
058     * @param key The name of the timer.
059     * @param timestamp The timestamp (in ms) for which the callback was scheduled.
060     */
061    void processTimer(ComputationContext context, String key, long timestamp);
062
063    /**
064     * Identify the computation.
065     *
066     * @return computation's metadata.
067     */
068    ComputationMetadata metadata();
069}