001/* 002Copyright 2022 The OpenFunction Authors. 003 004Licensed under the Apache License, Version 2.0 (the "License"); 005you may not use this file except in compliance with the License. 006You may obtain a copy of the License at 007 008 http://www.apache.org/licenses/LICENSE-2.0 009 010Unless required by applicable law or agreed to in writing, software 011distributed under the License is distributed on an "AS IS" BASIS, 012WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013See the License for the specific language governing permissions and 014limitations under the License. 015*/ 016 017package dev.openfunction.functions; 018 019import io.cloudevents.CloudEvent; 020import io.dapr.client.DaprClient; 021 022import java.util.Map; 023 024/** 025 * An interface for event function context. 026 */ 027public interface Context { 028 /** 029 * send provides the ability to allow the user to send data to a specified output target. 030 * 031 * @param outputName output target name 032 * @param data Data String 033 * @return Error 034 */ 035 Error send(String outputName, String data); 036 037 /** 038 * getHttpRequest returns the Http request. 039 * 040 * @return HttpRequest 041 */ 042 HttpRequest getHttpRequest(); 043 044 /** 045 * getHttpResponse returns the Http response. 046 * 047 * @return HttpResponse 048 */ 049 HttpResponse getHttpResponse(); 050 051 /** 052 * getBindingEvent returns the binding event. 053 * 054 * @return BindingEvent GetBindingEvent(); 055 */ 056 BindingEvent getBindingEvent(); 057 058 /** 059 * getTopicEvent returns the topic event. 060 * 061 * @return TopicEvent 062 */ 063 TopicEvent getTopicEvent(); 064 065 /** 066 * getCloudEvent returns the cloud Event. 067 * 068 * @return CloudEvent 069 */ 070 CloudEvent getCloudEvent(); 071 072 /** 073 * getName returns the function's name. 074 * 075 * @return Function Name 076 */ 077 String getName(); 078 079 /** 080 * GetOut returns the returned value of function. 081 * 082 * @return Out 083 */ 084 Out getOut(); 085 086 /** 087 * getHttpPattern returns the path of the server listening for http function. 088 * 089 * @return String 090 */ 091 String getHttpPattern(); 092 093 /** 094 * getOutputs returns the Outputs of function. 095 * 096 * @return Outputs 097 */ 098 Map<String, Component> getOutputs(); 099 100 /** 101 * getStates returns the states of function. 102 * 103 * @return states 104 */ 105 Map<String, Component> getStates(); 106 107 /** 108 * getDaprClient return a dapr client, so that use user 109 * can call the dapr API directly. 110 * Be carefully, the dapr client maybe null; 111 * 112 * @return Dapr client 113 */ 114 DaprClient getDaprClient(); 115}