Commit 0901fdf2 by Eli Ben Baruch

mde: last changes for develop

parent d3bb1794
......@@ -8,7 +8,7 @@ mde:
- "8200:8000"
- "50040:50040"
extra_hosts:
- "transportation:172.16.1.151"
- "transportation:172.16.1.56"
- "parking:172.16.1.56"
# volumes:
# - "/opt/mcz/user_images:/opt/mcz/user_images"
\ No newline at end of file
......@@ -3,8 +3,6 @@ package logic.webSocket;
import com.neovisionaries.ws.client.*;
import logic.adapter.HttpAdapter.ErrorLoginException;
import logic.adapter.HttpAdapter.OAuth2Client;
import logic.adapter.HttpAdapter.model.CredentialDetails;
import logic.adapter.HttpAdapter.model.CredentialResponse;
import logic.adapter.HttpAdapter.model.NameValueParam;
import java.io.IOException;
......@@ -31,7 +29,13 @@ public class WebSocketConnection extends Thread {
}
private Exception exception;
private boolean dontStop;
private volatile boolean webSocketOpen;
public boolean isWebSocketClosedWaitingForMaintenence() {
return webSocketClosedWaitingForMaintenence;
}
private boolean webSocketClosedWaitingForMaintenence;
public WebSocketConnection(String adapterId, String connectionId,
......@@ -42,7 +46,7 @@ public class WebSocketConnection extends Thread {
OnEventDetails details) throws IOException, ErrorLoginException, WebSocketException {
super();
this.adapterId=adapterId;
this.dontStop=true;
this.webSocketOpen =true;
this.factory = new WebSocketFactory();
this.connectionId = connectionId;
this.uid = uid;
......@@ -77,7 +81,7 @@ public class WebSocketConnection extends Thread {
webSocket.addHeader(header.getName(), header.getValue());
}
}
this.eventListener = new WebSocketEventListener(adapterId,connectionId, this.uid, details,null);
this.eventListener = new WebSocketEventListener(this, adapterId,connectionId, this.uid, details,null);
webSocket.addListener(eventListener);
webSocket.setPingInterval(50*1000);
......@@ -145,24 +149,41 @@ public class WebSocketConnection extends Thread {
this.notify();
}
}
this.waitForClosedWebSocket();
while(dontStop) {
if (exception != null){
this.dontStop = true;
try {
Thread.sleep(3600);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
private void waitForClosedWebSocket() {
while (webSocketOpen) {
try {
this.webSocketClosedWaitingForMaintenence=true;
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
//Let the websocket maintenance a chance to handle the closed websocket
try {
Thread.sleep(3600*1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void setException(Exception exception) {
this.exception = exception;
}
public void webSocketClosed() {
webSocketOpen = false;
}
}
......@@ -28,6 +28,7 @@ import java.util.concurrent.ExecutorService;
public class WebSocketEventListener implements WebSocketListener {
private final static JsonPointer uidPointer = JsonPointer.compile("/location-uid");
private final WebSocketConnection webSocketConnection;
private String adapterId;;
private String connectionId;;
......@@ -78,8 +79,9 @@ public class WebSocketEventListener implements WebSocketListener {
}
public WebSocketEventListener(String adapterId, String connectionId, String uid, OnEventDetails details, ILogger logFile) {
public WebSocketEventListener(WebSocketConnection webSocketConnection, String adapterId, String connectionId, String uid, OnEventDetails details, ILogger logFile) {
// String file=LOGS_LOCATION+Thread.currentThread().getName();
this.webSocketConnection=webSocketConnection;
this.adapterId=adapterId;
this.connectionId = connectionId;
this.logFile = logFile;
......@@ -198,7 +200,8 @@ public class WebSocketEventListener implements WebSocketListener {
*/
@Override
public void onDisconnected(WebSocket websocket, WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame, boolean closedByServer) throws Exception {
String str = connectionId +" "+ currentDate()+" "+"the WebSocket connection was closed.";
String str = connectionId +" "+ currentDate()+" "+"onDisconnected: the WebSocket connection was closed by"+ ((closedByServer)?" server": " client");
this.webSocketConnection.webSocketClosed();
setState(websocket.getState());
logging(str, eTraceLevel.eDEBUG,false);
}
......@@ -504,7 +507,7 @@ public class WebSocketEventListener implements WebSocketListener {
*/
@Override
public void onFrameError(WebSocket websocket, WebSocketException cause, WebSocketFrame frame) throws Exception {
String str = connectionId +" "+ currentDate()+" "+"a WebSocket frame failed to be read from the WebSocket: "+frame.toString();
String str = connectionId +" "+ currentDate()+" "+"a WebSocket frame failed to be read from the WebSocket, frame: "+frame.toString();
logging(str, eTraceLevel.eDEBUG,false);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment