Merge "Add period after inheritDoc for Sonar"
[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
25 import org.java_websocket.client.WebSocketClient;
26 import org.java_websocket.handshake.ServerHandshake;
27 import org.slf4j.ext.XLogger;
28 import org.slf4j.ext.XLoggerFactory;
29
30 /**
31  * This class implements {@link WebSocketClient} specific methods in order to act as a Java Web Socket client.
32  *
33  * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com)
34  */
35 abstract class WebSocketClientImpl extends WebSocketClient {
36     // The logger for this class
37     private static final XLogger LOGGER = XLoggerFactory.getXLogger(WebSocketClientImpl.class);
38
39     /**
40      * Constructs a WebSocketClient instance and sets it to the connect to the specified URI. The channel does not
41      * attempt to connect automatically. You must call {@link connect} first to initiate the socket connection.
42      *
43      * @param serverUri the URI of the web socket server to connect to
44      */
45     WebSocketClientImpl(final URI serverUri) {
46         super(serverUri);
47     }
48
49     /*
50      * (non-Javadoc)
51      *
52      * @see org.java_websocket.client.WebSocketClient#onOpen(org.java_websocket.handshake.ServerHandshake)
53      */
54     @Override
55     public void onOpen(final ServerHandshake handshakedata) {
56         if (LOGGER.isDebugEnabled()) {
57             LOGGER.debug("Connection opened to server {} --> {}", this.getURI(), handshakedata.getHttpStatusMessage());
58         }
59     }
60
61     /*
62      * (non-Javadoc)
63      *
64      * @see org.java_websocket.client.WebSocketClient#onClose(int, java.lang.String, boolean)
65      */
66     @Override
67     public void onClose(final int code, final String reason, final boolean remote) {
68         if (LOGGER.isDebugEnabled()) {
69             LOGGER.debug("Connection closed to server {} --> code \"{}\", reason \"{}\"", this.getURI(), code, reason);
70         }
71     }
72
73     /*
74      * (non-Javadoc)
75      *
76      * @see org.java_websocket.client.WebSocketClient#onError(java.lang.Exception)
77      */
78     @Override
79     public void onError(final Exception ex) {
80         LOGGER.info("Failed to make a connection to the server {} ", getURI());
81         LOGGER.catching(ex);
82     }
83 }