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.WsStringMessageClient;
26 import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageListener;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 * The Class WebSocketEventSubscriberClient.
33 public class WebSocketEventSubscriberClient implements WsStringMessageListener {
34 private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketEventSubscriberClient.class);
36 private final int port;
37 private long eventsReceivedCount = 0;
39 private final WsStringMessageClient client;
42 * Instantiates a new web socket event subscriber client.
44 * @param host the host
45 * @param port the port
46 * @throws MessagingException the messaging exception
48 public WebSocketEventSubscriberClient(final String host, final int port) throws MessagingException {
51 client = new WsStringMessageClient(host, port);
59 public void receiveString(final String eventString) {
60 LOGGER.debug("{}: port {}, received event {}", WebSocketEventSubscriberClient.class.getName(), 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.getName());
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 != 2) {
90 LOGGER.error("usage WebSocketEventSubscriberClient host port");
96 port = Integer.parseInt(args[0]);
97 } catch (final Exception e) {
98 LOGGER.error("usage WebSocketEventSubscriberClient port");
103 new WebSocketEventSubscriberClient(args[0], port);