Commit 0901fdf2 by Eli Ben Baruch

mde: last changes for develop

parent d3bb1794
...@@ -8,7 +8,7 @@ mde: ...@@ -8,7 +8,7 @@ mde:
- "8200:8000" - "8200:8000"
- "50040:50040" - "50040:50040"
extra_hosts: extra_hosts:
- "transportation:172.16.1.151" - "transportation:172.16.1.56"
- "parking:172.16.1.56" - "parking:172.16.1.56"
# volumes: # volumes:
# - "/opt/mcz/user_images:/opt/mcz/user_images" # - "/opt/mcz/user_images:/opt/mcz/user_images"
\ No newline at end of file
...@@ -3,8 +3,6 @@ package logic.webSocket; ...@@ -3,8 +3,6 @@ package logic.webSocket;
import com.neovisionaries.ws.client.*; import com.neovisionaries.ws.client.*;
import logic.adapter.HttpAdapter.ErrorLoginException; import logic.adapter.HttpAdapter.ErrorLoginException;
import logic.adapter.HttpAdapter.OAuth2Client; import logic.adapter.HttpAdapter.OAuth2Client;
import logic.adapter.HttpAdapter.model.CredentialDetails;
import logic.adapter.HttpAdapter.model.CredentialResponse;
import logic.adapter.HttpAdapter.model.NameValueParam; import logic.adapter.HttpAdapter.model.NameValueParam;
import java.io.IOException; import java.io.IOException;
...@@ -31,7 +29,13 @@ public class WebSocketConnection extends Thread { ...@@ -31,7 +29,13 @@ public class WebSocketConnection extends Thread {
} }
private Exception exception; private Exception exception;
private boolean dontStop; private volatile boolean webSocketOpen;
public boolean isWebSocketClosedWaitingForMaintenence() {
return webSocketClosedWaitingForMaintenence;
}
private boolean webSocketClosedWaitingForMaintenence;
public WebSocketConnection(String adapterId, String connectionId, public WebSocketConnection(String adapterId, String connectionId,
...@@ -42,7 +46,7 @@ public class WebSocketConnection extends Thread { ...@@ -42,7 +46,7 @@ public class WebSocketConnection extends Thread {
OnEventDetails details) throws IOException, ErrorLoginException, WebSocketException { OnEventDetails details) throws IOException, ErrorLoginException, WebSocketException {
super(); super();
this.adapterId=adapterId; this.adapterId=adapterId;
this.dontStop=true; this.webSocketOpen =true;
this.factory = new WebSocketFactory(); this.factory = new WebSocketFactory();
this.connectionId = connectionId; this.connectionId = connectionId;
this.uid = uid; this.uid = uid;
...@@ -77,7 +81,7 @@ public class WebSocketConnection extends Thread { ...@@ -77,7 +81,7 @@ public class WebSocketConnection extends Thread {
webSocket.addHeader(header.getName(), header.getValue()); 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.addListener(eventListener);
webSocket.setPingInterval(50*1000); webSocket.setPingInterval(50*1000);
...@@ -145,24 +149,41 @@ public class WebSocketConnection extends Thread { ...@@ -145,24 +149,41 @@ public class WebSocketConnection extends Thread {
this.notify(); 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) { public void setException(Exception exception) {
this.exception = exception; this.exception = exception;
} }
public void webSocketClosed() {
webSocketOpen = false;
}
} }
...@@ -28,6 +28,7 @@ import java.util.concurrent.ExecutorService; ...@@ -28,6 +28,7 @@ import java.util.concurrent.ExecutorService;
public class WebSocketEventListener implements WebSocketListener { public class WebSocketEventListener implements WebSocketListener {
private final static JsonPointer uidPointer = JsonPointer.compile("/location-uid"); private final static JsonPointer uidPointer = JsonPointer.compile("/location-uid");
private final WebSocketConnection webSocketConnection;
private String adapterId;; private String adapterId;;
private String connectionId;; private String connectionId;;
...@@ -78,8 +79,9 @@ public class WebSocketEventListener implements WebSocketListener { ...@@ -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(); // String file=LOGS_LOCATION+Thread.currentThread().getName();
this.webSocketConnection=webSocketConnection;
this.adapterId=adapterId; this.adapterId=adapterId;
this.connectionId = connectionId; this.connectionId = connectionId;
this.logFile = logFile; this.logFile = logFile;
...@@ -198,7 +200,8 @@ public class WebSocketEventListener implements WebSocketListener { ...@@ -198,7 +200,8 @@ public class WebSocketEventListener implements WebSocketListener {
*/ */
@Override @Override
public void onDisconnected(WebSocket websocket, WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame, boolean closedByServer) throws Exception { 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()); setState(websocket.getState());
logging(str, eTraceLevel.eDEBUG,false); logging(str, eTraceLevel.eDEBUG,false);
} }
...@@ -504,7 +507,7 @@ public class WebSocketEventListener implements WebSocketListener { ...@@ -504,7 +507,7 @@ public class WebSocketEventListener implements WebSocketListener {
*/ */
@Override @Override
public void onFrameError(WebSocket websocket, WebSocketException cause, WebSocketFrame frame) throws Exception { 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); 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