Changes for checkstyle 8.32
[policy/apex-pdp.git] / core / core-infrastructure / src / main / java / org / onap / policy / apex / core / infrastructure / messaging / impl / ws / client / WebSocketClientImpl.java
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.core.infrastructure.messaging.impl.ws.client;
22
23 import java.net.URI;
24 import org.java_websocket.client.WebSocketClient;
25 import org.java_websocket.handshake.ServerHandshake;
26 import org.slf4j.ext.XLogger;
27 import org.slf4j.ext.XLoggerFactory;
28
29 /**
30  * This class implements {@link WebSocketClient} specific methods in order to act as a Java Web Socket client.
31  *
32  * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com)
33  */
34 abstract class WebSocketClientImpl extends WebSocketClient {
35     // The logger for this class
36     private static final XLogger LOGGER = XLoggerFactory.getXLogger(WebSocketClientImpl.class);
37
38     /**
39      * Constructs a WebSocketClient instance and sets it to the connect to the specified URI. The channel does not
40      * attempt to connect automatically. You must call {@link connect} first to initiate the socket connection.
41      *
42      * @param serverUri the URI of the web socket server to connect to
43      */
44     WebSocketClientImpl(final URI serverUri) {
45         super(serverUri);
46     }
47
48     /**
49      * {@inheritDoc}.
50      */
51     @Override
52     public void onOpen(final ServerHandshake handshakedata) {
53         if (LOGGER.isDebugEnabled()) {
54             LOGGER.debug("Connection opened to server {} --> {}", this.getURI(), handshakedata.getHttpStatusMessage());
55         }
56     }
57
58     /**
59      * {@inheritDoc}.
60      */
61     @Override
62     public void onClose(final int code, final String reason, final boolean remote) {
63         if (LOGGER.isDebugEnabled()) {
64             LOGGER.debug("Connection closed to server {} --> code \"{}\", reason \"{}\"", this.getURI(), code, reason);
65         }
66     }
67
68     /**
69      * {@inheritDoc}.
70      */
71     @Override
72     public void onError(final Exception ex) {
73         LOGGER.info("Failed to make a connection to the server {} ", getURI());
74         LOGGER.catching(ex);
75     }
76 }