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 from https://github.com/concord/concord-jvm 018 * bdelbosc 019 */ 020package org.nuxeo.lib.stream.computation; 021 022/** 023 * @since 9.3 024 */ 025public interface ComputationContext { 026 027 /** 028 * Register a timer callback for some point in the future 029 * 030 * @param key Name of the timer callback. 031 * @param time The (ms since epoch) at which the callback should be fired 032 */ 033 void setTimer(String key, long time); 034 035 /** 036 * Emit a record downstream. Records are send effectively on checkpoint using {@link #askForCheckpoint()}. 037 * 038 * @param streamName The name of the stream on which the record should be emitted. 039 * @param key The key associated with the record. Only relevant when routing method is `GROUP_BY`. 040 * @param data: The binary blob to send downstream. 041 */ 042 default void produceRecord(String streamName, String key, byte[] data) { 043 produceRecord(streamName, Record.of(key, data)); 044 } 045 046 void produceRecord(String streamName, Record record); 047 048 /** 049 * Set the low watermark for a source computation. 050 */ 051 void setSourceLowWatermark(long watermark); 052 053 /** 054 * Ask for checkpoint in order to send records, save input stream offset positions. 055 */ 056 void askForCheckpoint(); 057}