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 @Deprecated 036 Error send(String outputName, String data); 037 038 /** 039 * getHttpRequest returns the Http request. 040 * 041 * @return HttpRequest 042 */ 043 HttpRequest getHttpRequest(); 044 045 /** 046 * getHttpResponse returns the Http response. 047 * 048 * @return HttpResponse 049 */ 050 HttpResponse getHttpResponse(); 051 052 /** 053 * getBindingEvent returns the binding event. 054 * 055 * @return BindingEvent GetBindingEvent(); 056 */ 057 BindingEvent getBindingEvent(); 058 059 /** 060 * getTopicEvent returns the topic event. 061 * 062 * @return TopicEvent 063 */ 064 TopicEvent getTopicEvent(); 065 066 /** 067 * getCloudEvent returns the cloud Event. 068 * 069 * @return CloudEvent 070 */ 071 CloudEvent getCloudEvent(); 072 073 /** 074 * getName returns the function's name. 075 * 076 * @return Function Name 077 */ 078 String getName(); 079 080 /** 081 * GetOut returns the returned value of function. 082 * 083 * @return Out 084 */ 085 Out getOut(); 086 087 /** 088 * getHttpPattern returns the path of the server listening for http function. 089 * 090 * @return String 091 */ 092 String getHttpPattern(); 093 094 /** 095 * getInputs returns the inputs of function. 096 * 097 * @return Inputs 098 */ 099 Map<String, Component> getInputs(); 100 101 /** 102 * getOutputs returns the Outputs of function. 103 * 104 * @return Outputs 105 */ 106 Map<String, Component> getOutputs(); 107 108 /** 109 * getStates returns the states of function. 110 * 111 * @return states 112 */ 113 Map<String, Component> getStates(); 114 115 /** 116 * getDaprClient return a dapr client, so that use user 117 * can call the dapr API directly. 118 * Be carefully, the dapr client maybe null; 119 * 120 * @return Dapr client 121 */ 122 DaprClient getDaprClient(); 123 124 CloudEvent packageAsCloudevent(String payload); 125}