2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2019 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.testsuites.integration.uservice.adapt.websocket;
24 import org.onap.policy.apex.core.infrastructure.messaging.MessagingException;
25 import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageListener;
26 import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageServer;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 * The Class WebSocketEventSubscriberServer.
33 public class WebSocketEventSubscriberServer implements WsStringMessageListener {
34 private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketEventSubscriberServer.class);
36 private final int port;
37 private long eventsReceivedCount = 0;
39 private final WsStringMessageServer server;
42 * Instantiates a new web socket event subscriber server.
44 * @param port the port
45 * @throws MessagingException the messaging exception
47 public WebSocketEventSubscriberServer(final int port) throws MessagingException {
50 server = new WsStringMessageServer(port);
53 LOGGER.debug("{}: port {}, waiting for events", WebSocketEventSubscriberServer.class.getName(), port);
60 public void receiveString(final String eventString) {
61 LOGGER.debug("{}: port {}, received event {}", WebSocketEventSubscriberServer.class.getName(), port,
63 eventsReceivedCount++;
67 * Gets the events received count.
69 * @return the events received count
71 public long getEventsReceivedCount() {
72 return eventsReceivedCount;
78 public void shutdown() {
80 LOGGER.debug("{} : stopped", WebSocketEventSubscriberServer.class.getName());
86 * @param args the arguments
87 * @throws MessagingException the messaging exception
89 public static void main(final String[] args) throws MessagingException {
90 if (args.length != 1) {
91 LOGGER.error("usage WebSocketEventSubscriberClient port");
97 port = Integer.parseInt(args[0]);
98 } catch (final Exception e) {
99 LOGGER.error("usage WebSocketEventSubscriberClient port");
104 new WebSocketEventSubscriberServer(port);