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.ecm.platform.importer.mqueues.computation; 021 022/** 023 * @since 9.2 024 */ 025public interface ComputationContext { 026 027 /** 028 * Set local state for a given key. 029 * 030 * @param key Key to set in local store. 031 * @param binaryValue Value to store at key. 032 */ 033 void setState(final String key, final byte[] binaryValue); 034 035 /** 036 * Get local state for a given key 037 * 038 * @param key Key to receive from local store. 039 * @return the state executed upon data retrieval. 040 */ 041 byte[] getState(final String key); 042 043 /** 044 * Register a timer callback for some point in the future 045 * 046 * @param key Name of the timer callback. 047 * @param time The (ms since epoch) at which the callback should be fired 048 */ 049 void setTimer(final String key, final long time); 050 051 /** 052 * Emit a record downstream. Records are send effectively on checkpoint using {@link #askForCheckpoint()}. 053 * 054 * @param streamName The name of the stream on which the record should be emitted. 055 * @param key The key associated with the record. Only relevant when routing method is `GROUP_BY`. 056 * @param data: The binary blob to send downstream. 057 */ 058 void produceRecord(final String streamName, final String key, final byte[] data); 059 060 void produceRecord(final String streamName, final Record record); 061 062 /** 063 * Set the low watermark for a source computation. 064 */ 065 void setSourceLowWatermark(long watermark); 066 067 /** 068 * Ask for checkpoint in order to send records, save input stream offset positions. 069 */ 070 void askForCheckpoint(); 071}