2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.testsuites.integration.uservice.adapt.websocket;
23 import org.onap.policy.apex.core.infrastructure.messaging.MessagingException;
24 import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageListener;
25 import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageServer;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
30 * The Class WebSocketEventSubscriberServer.
32 public class WebSocketEventSubscriberServer implements WsStringMessageListener {
33 private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketEventSubscriberServer.class);
35 private final int port;
36 private long eventsReceivedCount = 0;
38 private final WsStringMessageServer server;
41 * Instantiates a new web socket event subscriber server.
43 * @param port the port
44 * @throws MessagingException the messaging exception
46 public WebSocketEventSubscriberServer(final int port) throws MessagingException {
49 server = new WsStringMessageServer(port);
52 LOGGER.debug("{}: port {}, waiting for events", WebSocketEventSubscriberServer.class.getCanonicalName(), port);
59 public void receiveString(final String eventString) {
60 LOGGER.debug("{}: port {}, received event {}", WebSocketEventSubscriberServer.class.getCanonicalName(), port,
62 eventsReceivedCount++;
66 * Gets the events received count.
68 * @return the events received count
70 public long getEventsReceivedCount() {
71 return eventsReceivedCount;
77 public void shutdown() {
79 LOGGER.debug("{} : stopped", WebSocketEventSubscriberServer.class.getCanonicalName());
85 * @param args the arguments
86 * @throws MessagingException the messaging exception
88 public static void main(final String[] args) throws MessagingException {
89 if (args.length != 1) {
90 LOGGER.error("usage WebSocketEventSubscriberClient port");
96 port = Integer.parseInt(args[0]);
97 } catch (final Exception e) {
98 LOGGER.error("usage WebSocketEventSubscriberClient port");
103 new WebSocketEventSubscriberServer(port);