7333c8a0510c8d96ed03f733d50fddd2f10b8264
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2020 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.plugins.event.carrier.grpc;
22
23 import org.onap.policy.apex.service.engine.event.ApexEventException;
24 import org.onap.policy.apex.service.engine.event.ApexEventReceiver;
25 import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
26 import org.onap.policy.apex.service.engine.event.ApexPluginsEventConsumer;
27 import org.onap.policy.apex.service.engine.event.PeeredReference;
28 import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
29 import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
30
31 /**
32  * This class implements an Apex gRPC consumer. It is not expected to receive events using gRPC.
33  * So, initializing a gRPC consumer will result in error.
34  *
35  * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
36  */
37 public class ApexGrpcConsumer extends ApexPluginsEventConsumer {
38
39     private static final String GRPC_CONSUMER_ERROR_MSG =
40         "A gRPC Consumer may not be specified. Only sending events is possible using gRPC";
41
42     @Override
43     public void init(final String consumerName, final EventHandlerParameters consumerParameters,
44         final ApexEventReceiver incomingEventReceiver) throws ApexEventException {
45         throw new ApexEventException(GRPC_CONSUMER_ERROR_MSG);
46     }
47
48     @Override
49     public void run() {
50         throw new ApexEventRuntimeException(GRPC_CONSUMER_ERROR_MSG);
51     }
52
53     @Override
54     public void start() {
55         throw new ApexEventRuntimeException(GRPC_CONSUMER_ERROR_MSG);
56     }
57
58     @Override
59     public void stop() {
60         throw new ApexEventRuntimeException(GRPC_CONSUMER_ERROR_MSG);
61     }
62
63     @Override
64     public PeeredReference getPeeredReference(EventHandlerPeeredMode peeredMode) {
65         throw new ApexEventRuntimeException(GRPC_CONSUMER_ERROR_MSG);
66     }
67
68     @Override
69     public void setPeeredReference(EventHandlerPeeredMode peeredMode, PeeredReference peeredReference) {
70         throw new ApexEventRuntimeException(GRPC_CONSUMER_ERROR_MSG);
71     }
72 }