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 java.nio.ByteBuffer;
020import java.util.Map;
021
022public class TopicEvent {
023    /**
024     * The name of the pubsub the publisher sent to.
025     */
026    private final String name;
027
028    /**
029     * ID identifies the event.
030     */
031    private final String id;
032
033    /**
034     * The version of the CloudEvents specification.
035     */
036    private final String specversion;
037
038    /**
039     * The type of event related to the originating occurrence.
040     */
041    private final String type;
042
043    /**
044     * Source identifies the context in which an event happened.
045     */
046    private final String source;
047
048    /**
049     *
050     */
051    private final String datacontenttype;
052
053    /**
054     * The content of the event.
055     * Note, this is why the gRPC and HTTP implementations need separate structs for cloud events.
056     */
057    private final ByteBuffer data;
058
059    /**
060     * The pubsub topic which publisher sent to.
061     */
062    private final String topic;
063
064    private final Map<String, String> extensions;
065
066    public TopicEvent(String name, String id, String topic, String specversion, String source, String type, String datacontenttype, ByteBuffer data, Map<String, String> extensions) {
067        this.name = name;
068        this.id = id;
069        this.topic = topic;
070        this.specversion = specversion;
071        this.source = source;
072        this.type = type;
073        this.datacontenttype = datacontenttype;
074        this.data = data;
075        this.extensions = extensions;
076    }
077
078    public String getName() {
079        return name;
080    }
081
082    public String getId() {
083        return id;
084    }
085
086    public String getSpecversion() {
087        return specversion;
088    }
089
090    public String getType() {
091        return type;
092    }
093
094    public String getSource() {
095        return source;
096    }
097
098    public String getDatacontenttype() {
099        return datacontenttype;
100    }
101
102    public ByteBuffer getData() {
103        return data;
104    }
105
106    public String getTopic() {
107        return topic;
108    }
109
110    public Map<String, String> getExtensions() {
111        return this.extensions;
112    }
113}