Hello, I like to do some thread synchronizing between my different objects…
But it doesn’t work…
public class YIOremoteDockHandler extends BaseThingHandler {
private YIOremoteDockWebsocket yioremoteDockwebSocketClient = new YIOremoteDockWebsocket(this);
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();
yioremoteDockwebSocketClient.wait();
if (yioremoteDockwebSocketClient.getbooleanwebsocketconnected()) {
yioremoteDockwebSocketClient.wait(10000);
if (yioremoteDockwebSocketClient.getbooleanauthenticationrequired()) {
yioremoteDockwebSocketClient.sendMessage(YIOREMOTEMESSAGETYPE.AUTHENTICATE,
localConfig.accesstoken);
yioremoteDockwebSocketClient.wait(10000);
if (yioremoteDockwebSocketClient.getbooleanauthenticationok()) {
yioremotedockactualstatus = YIOREMOTEDOCKHANDLESTATUS.AUTHENTICATED_COMPLETE;
logger.debug("authentication to YIO dock ok");
updateStatus(ThingStatus.ONLINE);
} 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);
}
and the other object
public class YIOremoteDockWebsocket {
private @Nullable YIOremoteDockHandler yioremotedockhandler;
@OnWebSocketConnect
public void onConnect(Session session) {
synchronized (yioremotedockhandler) {
this.session = session;
latch.countDown();
yioremotedockhandler.notify();
booleanwebsocketconnected = true;
}
}
}
what is wrong???