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.WsStringMessageClient;
28 import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageListener;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * The Class WebSocketEventSubscriberClient.
35 public class WebSocketEventSubscriberClient implements WsStringMessageListener {
36 private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketEventSubscriberClient.class);
38 private final int port;
40 private long eventsReceivedCount = 0;
42 private final WsStringMessageClient client;
45 * Instantiates a new web socket event subscriber client.
47 * @param host the host
48 * @param port the port
49 * @throws MessagingException the messaging exception
51 public WebSocketEventSubscriberClient(final String host, final int port) throws MessagingException {
54 client = new WsStringMessageClient(host, port);
62 public void receiveString(final String eventString) {
63 LOGGER.debug("{}: port {}, received event {}", WebSocketEventSubscriberClient.class.getName(), port,
65 eventsReceivedCount++;
71 public void shutdown() {
73 LOGGER.debug("{}: stopped", WebSocketEventSubscriberServer.class.getName());
79 * @param args the arguments
80 * @throws MessagingException the messaging exception
82 public static void main(final String[] args) throws MessagingException {
83 if (args.length != 2) {
84 LOGGER.error("usage WebSocketEventSubscriberClient host port");
90 port = Integer.parseInt(args[0]);
91 } catch (final Exception e) {
92 LOGGER.error("usage WebSocketEventSubscriberClient port");
97 new WebSocketEventSubscriberClient(args[0], port);