2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd.
7 * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.common.endpoints.event.comm.bus;
25 import java.util.List;
26 import org.onap.policy.common.endpoints.event.comm.bus.internal.TopicBase;
27 import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
28 import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * No Operation topic endpoint.
35 public abstract class NoopTopicEndpoint extends TopicBase {
40 private static Logger logger = LoggerFactory.getLogger(NoopTopicEndpoint.class);
43 * Constructs the object.
45 protected NoopTopicEndpoint(List<String> servers, String topic) {
46 super(servers, topic);
52 * @param type "IN" or "OUT".
53 * @param message message.
54 * @return true if successful.
56 protected boolean io(EventType type, String message) {
58 if (message == null || message.isEmpty()) {
59 throw new IllegalArgumentException("Message is empty");
63 throw new IllegalStateException(this + " is stopped");
68 this.recentEvents.add(message);
71 NetLoggerUtil.log(type, this.getTopicCommInfrastructure(), this.topic, message);
74 } catch (Exception e) {
75 logger.warn("{}: cannot send because of {}", this, e.getMessage(), e);
86 public CommInfrastructure getTopicCommInfrastructure() {
87 return CommInfrastructure.NOOP;
94 public boolean start() {
95 logger.info("{}: starting", this);
100 throw new IllegalStateException(this + " is locked.");
114 public boolean stop() {
115 logger.info("{}: stopping", this);
117 synchronized (this) {
127 public void shutdown() {
128 logger.info("{}: shutdown", this);
137 public String toString() {
138 return "NoopTopicEndpoint[" + super.toString() + "]";