1 package org.opendaylight.mwtn.impl.websocket;
4 import java.net.URISyntaxException;
6 import org.java_websocket.client.WebSocketClient;
7 import org.java_websocket.handshake.ServerHandshake;
8 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory;
11 public class SyncWebSocketClient extends WebSocketClient {
13 private static final Logger LOG = LoggerFactory.getLogger(SyncWebSocketClient.class.getName());
14 private String messageToSend;
16 public SyncWebSocketClient(URI serverUri) {
18 // TODO Auto-generated constructor stub
21 public SyncWebSocketClient(String uri) throws URISyntaxException {
26 public void onClose(int arg0, String arg1, boolean arg2) {
27 // TODO Auto-generated method stub
32 public void onError(Exception arg0) {
33 // TODO Auto-generated method stub
38 public void onMessage(String arg0) {
39 // TODO Auto-generated method stub
44 public void onOpen(ServerHandshake arg0) {
45 LOG.debug("ws opened");
46 if(this.messageToSend!=null)
48 LOG.debug("try to send: "+this.messageToSend);
49 this.send(this.messageToSend);
50 this.messageToSend=null;
55 public void openAndSendAsync(String message)
57 this.messageToSend=message;
60 public void openAndSendAndCloseSync(String message)
63 this.connectBlocking();
64 } catch (InterruptedException e) {
65 LOG.warn("problem connecting:"+e.getMessage());
70 } catch (InterruptedException e) {
71 LOG.warn("problem disconnecting:"+e.getMessage());