2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2019 Nordix Foundation.
5 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.apex.testsuites.integration.uservice.adapt.websocket;
26 import org.onap.policy.apex.core.infrastructure.messaging.MessagingException;
27 import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageListener;
28 import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageServer;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * The Class WebSocketEventSubscriberServer.
35 public class WebSocketEventSubscriberServer implements WsStringMessageListener {
36 private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketEventSubscriberServer.class);
38 private final int port;
40 private long eventsReceivedCount = 0;
42 private final WsStringMessageServer server;
45 * Instantiates a new web socket event subscriber server.
47 * @param port the port
48 * @throws MessagingException the messaging exception
50 public WebSocketEventSubscriberServer(final int port) throws MessagingException {
53 server = new WsStringMessageServer(port);
56 LOGGER.debug("{}: port {}, waiting for events", WebSocketEventSubscriberServer.class.getName(), port);
63 public void receiveString(final String eventString) {
64 LOGGER.debug("{}: port {}, received event {}", WebSocketEventSubscriberServer.class.getName(), port,
66 eventsReceivedCount++;
72 public void shutdown() {
74 LOGGER.debug("{} : stopped", WebSocketEventSubscriberServer.class.getName());
80 * @param args the arguments
81 * @throws MessagingException the messaging exception
83 public static void main(final String[] args) throws MessagingException {
84 if (args.length != 1) {
85 LOGGER.error("usage WebSocketEventSubscriberClient port");
91 port = Integer.parseInt(args[0]);
92 } catch (final Exception e) {
93 LOGGER.error("usage WebSocketEventSubscriberClient port");
98 new WebSocketEventSubscriberServer(port);