Hallo zusammen,
ich versuche eine websocket anwendung zu implmentieren. Websocket Verbindung kann erstellt werden. ich wollte es nun in threads packen damit es besser synchronisiert ist dazu habe ich folgenden runnable geschrieben
und die websocket class mit dem on connect welches das wait freigeben soll
aber die synchronisation funkioniert nicht.....Wo st der Fehler???
ich versuche eine websocket anwendung zu implmentieren. Websocket Verbindung kann erstellt werden. ich wollte es nun in threads packen damit es besser synchronisiert ist dazu habe ich folgenden runnable geschrieben
Code:
public class YIOremoteDockHandler extends BaseThingHandler {
private void establishconnectionfunction() {
establishconnection = new Runnable() {
@Override
public void run() {
try {
try {
uriyiodockwebsocketaddress = new URI("ws://" + localConfig.host + ":946");
yioremotedockactualstatus = YIOREMOTEDOCKHANDLESTATUS.AUTHENTICATION_PROCESS;
} catch (URISyntaxException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR,
"Initialize web socket failed");
}
try {
yioremoteDockHandlerwebSocketClient.start();
} catch (Exception e) {
}
yioremoteDockHandlerwebSocketClient.connect(yioremoteDockwebSocketClient,
uriyiodockwebsocketaddress, yioremoteDockwebSocketClientrequest);
yioremoteDockwebSocketClient.getLatch().await();
this.wait();
if (yioremoteDockwebSocketClient.getbooleanwebsocketconnected()) {
wait(10000);
if (yioremoteDockwebSocketClient.getbooleanauthenticationrequired()) {
yioremoteDockwebSocketClient.sendMessage(YIOREMOTEMESSAGETYPE.AUTHENTICATE,
localConfig.accesstoken);
establishconnection.wait(10000);
if (yioremoteDockwebSocketClient.getbooleanauthenticationok()) {
yioremotedockactualstatus = YIOREMOTEDOCKHANDLESTATUS.AUTHENTICATED_COMPLETE;
logger.debug("authentication to YIO dock ok");
updateStatus(ThingStatus.ONLINE);
scheduler.notify();
} else {
updateState(GROUP_OUTPUT, YIODOCKSTATUS, UnDefType.UNDEF);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"No connection to the websocket");
yioremotedockactualstatus = YIOREMOTEDOCKHANDLESTATUS.AUTHENTICATION_PROCESS_FAILED;
}
} else {
updateState(GROUP_OUTPUT, YIODOCKSTATUS, UnDefType.UNDEF);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"No connection to the websocket");
yioremotedockactualstatus = YIOREMOTEDOCKHANDLESTATUS.AUTHENTICATION_PROCESS_FAILED;
}
} else {
updateState(GROUP_OUTPUT, YIODOCKSTATUS, UnDefType.UNDEF);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"No connection to the websocket");
yioremotedockactualstatus = YIOREMOTEDOCKHANDLESTATUS.AUTHENTICATION_PROCESS_FAILED;
}
} catch (IOException | InterruptedException e) {
}
}
};
establishconnectionthread = scheduler.schedule(establishconnection, 0, TimeUnit.SECONDS);
}
und die websocket class mit dem on connect welches das wait freigeben soll
Code:
@NonNullByDefault
@WebSocket
public class YIOremoteDockWebsocket {
@OnWebSocketConnect
public void onConnect(Session session) {
this.session = session;
latch.countDown();
yioremotedockhandler.establishconnectionthread.notify();
booleanwebsocketconnected = true;
}
}
aber die synchronisation funkioniert nicht.....Wo st der Fehler???