Commit a0e671b9 by Eli Ben Baruch

mde - phase 1 : fix bug- high cpu usage

parent dcc59bb1
{
"bustime-response": {
"route": [{
"rt": 1,
"rtnm": "Bronzeville/Union Station",
"rtclr": "#336633"
}, {
"rt": 2,
"rtnm": "Hyde Park Express",
"rtclr": "#993366"
}, {
"rt": 3,
"rtnm": "King Drive",
"rtclr": "#009900"
}, {
"rt": 4,
"rtnm": "Cottage Grove",
"rtclr": "#cc3300"
}, {
"rt": 5,
"rtnm": "South Shore Night Bus",
"rtclr": "#996633"
}, {
"rt": 6,
"rtnm": "Jackson Park Express",
"rtclr": "#ff0066"
}, {
"rt": 7,
"rtnm": "Harrison",
"rtclr": "#666600"
}, {
"rt": 8,
"rtnm": "Halsted",
"rtclr": "#ff00ff"
}, {
"rt": "8A",
"rtnm": "South Halsted",
"rtclr": "#66cc66"
}, {
"rt": 9,
"rtnm": "Ashland",
"rtclr": "#cc3366"
}, {
"rt": "X9",
"rtnm": "Ashland Express",
"rtclr": "#33ff00"
}, {
"rt": 10,
"rtnm": "Museum of S & I",
"rtclr": "#cc66ff"
}, {
"rt": 11,
"rtnm": "Lincoln",
"rtclr": "#ff6600"
}, {
"rt": 12,
"rtnm": "Roosevelt",
"rtclr": "#33ccff"
}, {
"rt": "J14",
"rtnm": "Jeffery Jump",
"rtclr": "#c8c8c8"
}, {
"rt": 15,
"rtnm": "Jeffery Local",
"rtclr": "#ff9999"
}, {
"rt": 18,
"rtnm": "16th/18th",
"rtclr": "#6699ff"
}, {
"rt": 19,
"rtnm": "United Center Express",
"rtclr": "#78aa50"
}, {
"rt": 20,
"rtnm": "Madison",
"rtclr": "#336633"
}, {
"rt": 21,
"rtnm": "Cermak",
"rtclr": "#009900"
}, {
"rt": 22,
"rtnm": "Clark",
"rtclr": "#cc3300"
}, {
"rt": 24,
"rtnm": "Wentworth",
"rtclr": "#9900cc"
}, {
"rt": 26,
"rtnm": "South Shore Express",
"rtclr": "#006666"
}, {
"rt": 28,
"rtnm": "Stony Island",
"rtclr": "#996633"
}, {
"rt": 29,
"rtnm": "State",
"rtclr": "#666600"
}, {
"rt": 30,
"rtnm": "South Chicago",
"rtclr": "#ff00ff"
}, {
"rt": 34,
"rtnm": "South Michigan",
"rtclr": "#cc3366"
}, {
"rt": 35,
"rtnm": "31st/35th",
"rtclr": "#33ff00"
}, {
"rt": 36,
"rtnm": "Broadway",
"rtclr": "#cc66ff"
}, {
"rt": 37,
"rtnm": "Sedgwick",
"rtclr": "#c8c8c8"
}, {
"rt": 39,
"rtnm": "Pershing",
"rtclr": "#33ccff"
}, {
"rt": 43,
"rtnm": "43rd",
"rtclr": "#cc9966"
}, {
"rt": 44,
"rtnm": "Wallace-Racine",
"rtclr": "#ff9999"
}, {
"rt": 47,
"rtnm": "47th",
"rtclr": "#99cc33"
}, {
"rt": 48,
"rtnm": "South Damen",
"rtclr": "#6699ff"
}, {
"rt": 49,
"rtnm": "Western",
"rtclr": "#336633"
}, {
"rt": "49B",
"rtnm": "North Western",
"rtclr": "#009900"
}, {
"rt": "X49",
"rtnm": "Western Express",
"rtclr": "#9900cc"
}, {
"rt": 50,
"rtnm": "Damen",
"rtclr": "#cc3300"
}, {
"rt": 51,
"rtnm": "51st",
"rtclr": "#006666"
}, {
"rt": 52,
"rtnm": "Kedzie/California",
"rtclr": "#996633"
}, {
"rt": "52A",
"rtnm": "South Kedzie",
"rtclr": "#ff0066"
}, {
"rt": 53,
"rtnm": "Pulaski",
"rtclr": "#666600"
}, {
"rt": "53A",
"rtnm": "South Pulaski",
"rtclr": "#ff00ff"
}, {
"rt": 54,
"rtnm": "Cicero",
"rtclr": "#cc3366"
}, {
"rt": "54A",
"rtnm": "North Cicero/Skokie Blvd.",
"rtclr": "#33ff00"
}, {
"rt": "54B",
"rtnm": "South Cicero",
"rtclr": "#cc66ff"
}, {
"rt": 55,
"rtnm": "Garfield",
"rtclr": "#33ccff"
}, {
"rt": "55A",
"rtnm": "55th/Austin",
"rtclr": "#cc9966"
}, {
"rt": "55N",
"rtnm": "55th/Narragansett",
"rtclr": "#ff9999"
}, {
"rt": 56,
"rtnm": "Milwaukee",
"rtclr": "#6699ff"
}, {
"rt": 57,
"rtnm": "Laramie",
"rtclr": "#993366"
}, {
"rt": 59,
"rtnm": "59th/61st",
"rtclr": "#009900"
}, {
"rt": 60,
"rtnm": "Blue Island/26th",
"rtclr": "#9900cc"
}, {
"rt": 62,
"rtnm": "Archer",
"rtclr": "#cc3300"
}, {
"rt": "62H",
"rtnm": "Archer/Harlem",
"rtclr": "#006666"
}, {
"rt": 63,
"rtnm": "63rd",
"rtclr": "#996633"
}, {
"rt": "63W",
"rtnm": "West 63rd",
"rtclr": "#ff0066"
}, {
"rt": 65,
"rtnm": "Grand",
"rtclr": "#ff00ff"
}, {
"rt": 66,
"rtnm": "Chicago",
"rtclr": "#66cc66"
}, {
"rt": 67,
"rtnm": "67th-69th-71st",
"rtclr": "#cc3366"
}, {
"rt": 68,
"rtnm": "Northwest Highway",
"rtclr": "#33ff00"
}, {
"rt": 70,
"rtnm": "Division",
"rtclr": "#ff6600"
}, {
"rt": 71,
"rtnm": "71st/South Shore",
"rtclr": "#33ccff"
}, {
"rt": 72,
"rtnm": "North",
"rtclr": "#cc9966"
}, {
"rt": 73,
"rtnm": "Armitage",
"rtclr": "#ff9999"
}, {
"rt": 74,
"rtnm": "Fullerton",
"rtclr": "#99cc33"
}, {
"rt": 75,
"rtnm": "74th-75th",
"rtclr": "#6699ff"
}, {
"rt": 76,
"rtnm": "Diversey",
"rtclr": "#336633"
}, {
"rt": 77,
"rtnm": "Belmont",
"rtclr": "#993366"
}, {
"rt": 78,
"rtnm": "Montrose",
"rtclr": "#009900"
}, {
"rt": 79,
"rtnm": "79th",
"rtclr": "#9900cc"
}, {
"rt": 80,
"rtnm": "Irving Park",
"rtclr": "#cc3300"
}, {
"rt": 81,
"rtnm": "Lawrence",
"rtclr": "#996633"
}, {
"rt": "81W",
"rtnm": "West Lawrence",
"rtclr": "#ff0066"
}, {
"rt": 82,
"rtnm": "Kimball-Homan",
"rtclr": "#666600"
}, {
"rt": 84,
"rtnm": "Peterson",
"rtclr": "#ff00ff"
}, {
"rt": 85,
"rtnm": "Central",
"rtclr": "#66cc66"
}, {
"rt": "85A",
"rtnm": "North Central",
"rtclr": "#cc3366"
}, {
"rt": 86,
"rtnm": "Narragansett/Ridgeland",
"rtclr": "#33ff00"
}, {
"rt": 87,
"rtnm": "87th",
"rtclr": "#cc66ff"
}, {
"rt": 88,
"rtnm": "Higgins",
"rtclr": "#ff6600"
}, {
"rt": 90,
"rtnm": "Harlem",
"rtclr": "#33ccff"
}, {
"rt": 91,
"rtnm": "Austin",
"rtclr": "#ff9999"
}, {
"rt": 92,
"rtnm": "Foster",
"rtclr": "#99cc33"
}, {
"rt": 93,
"rtnm": "California/Dodge",
"rtclr": "#6699ff"
}, {
"rt": 94,
"rtnm": "South California",
"rtclr": "#336633"
}, {
"rt": "95E",
"rtnm": "93rd-95th",
"rtclr": "#993366"
}, {
"rt": "95W",
"rtnm": "West 95th",
"rtclr": "#009900"
}, {
"rt": 96,
"rtnm": "Lunt",
"rtclr": "#9900cc"
}, {
"rt": 97,
"rtnm": "Skokie",
"rtclr": "#cc3300"
}, {
"rt": "X98",
"rtnm": "Avon Express",
"rtclr": "#006666"
}, {
"rt": 100,
"rtnm": "Jeffery Manor Express",
"rtclr": "#996633"
}, {
"rt": 103,
"rtnm": "West 103rd",
"rtclr": "#ff0066"
}, {
"rt": 106,
"rtnm": "East 103rd",
"rtclr": "#666600"
}, {
"rt": 108,
"rtnm": "Halsted/95th",
"rtclr": "#ff00ff"
}, {
"rt": 111,
"rtnm": "111th/King Drive",
"rtclr": "#66cc66"
}, {
"rt": "111A",
"rtnm": "Pullman Shuttle",
"rtclr": "#c8c8c8"
}, {
"rt": 112,
"rtnm": "Vincennes/111th",
"rtclr": "#cc3366"
}, {
"rt": 115,
"rtnm": "Pullman/115th",
"rtclr": "#c8c8c8"
}, {
"rt": 119,
"rtnm": "Michigan/119th",
"rtclr": "#33ff00"
}, {
"rt": 120,
"rtnm": "Ogilvie/Streeterville Express",
"rtclr": "#cc66ff"
}, {
"rt": 121,
"rtnm": "Union/Streeterville Express",
"rtclr": "#ff6600"
}, {
"rt": 124,
"rtnm": "Navy Pier",
"rtclr": "#ff9999"
}, {
"rt": 125,
"rtnm": "Water Tower Express",
"rtclr": "#99cc33"
}, {
"rt": 126,
"rtnm": "Jackson",
"rtclr": "#6699ff"
}, {
"rt": 130,
"rtnm": "Museum Campus",
"rtclr": "#c8c8c8"
}, {
"rt": 132,
"rtnm": "Goose Island Express",
"rtclr": "#993366"
}, {
"rt": 134,
"rtnm": "Stockton/LaSalle Express",
"rtclr": "#009900"
}, {
"rt": 135,
"rtnm": "Clarendon/LaSalle Express",
"rtclr": "#9900cc"
}, {
"rt": 136,
"rtnm": "Sheridan/LaSalle Express",
"rtclr": "#cc3300"
}, {
"rt": 143,
"rtnm": "Stockton/Michigan Express",
"rtclr": "#006666"
}, {
"rt": 146,
"rtnm": "Inner Drive/Michigan Express",
"rtclr": "#666600"
}, {
"rt": 147,
"rtnm": "Outer Drive Express",
"rtclr": "#ff00ff"
}, {
"rt": 148,
"rtnm": "Clarendon/Michigan Express",
"rtclr": "#66cc66"
}, {
"rt": 151,
"rtnm": "Sheridan",
"rtclr": "#cc3366"
}, {
"rt": 152,
"rtnm": "Addison",
"rtclr": "#33ff00"
}, {
"rt": 155,
"rtnm": "Devon",
"rtclr": "#cc66ff"
}, {
"rt": 156,
"rtnm": "LaSalle",
"rtclr": "#ff6600"
}, {
"rt": 157,
"rtnm": "Streeterville/Taylor",
"rtclr": "#33ccff"
}, {
"rt": 165,
"rtnm": "West 65th",
"rtclr": "#cc9966"
}, {
"rt": 169,
"rtnm": "69th-UPS Express",
"rtclr": "#99cc33"
}, {
"rt": 171,
"rtnm": "U. of Chicago/Hyde Park",
"rtclr": "#336633"
}, {
"rt": 172,
"rtnm": "U. of Chicago/Kenwood",
"rtclr": "#993366"
}, {
"rt": 192,
"rtnm": "U. of Chicago Hospitals Express",
"rtclr": "#cc3300"
}, {
"rt": 201,
"rtnm": "Central/Ridge",
"rtclr": "#996633"
}, {
"rt": 205,
"rtnm": "Chicago/Golf",
"rtclr": "#ff0066"
}, {
"rt": 206,
"rtnm": "Evanston Circulator",
"rtclr": "#666600"
}]
}
}
......@@ -31,7 +31,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 +48,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 +83,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,17 +151,26 @@ 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();
}
......@@ -165,4 +180,15 @@ public class WebSocketConnection extends Thread {
public void setException(Exception exception) {
this.exception = exception;
}
public void webSocketClosed() {
webSocketOpen = false;
}
}
......@@ -33,6 +33,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;;
......@@ -83,8 +84,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;
......@@ -203,7 +205,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);
}
......@@ -509,7 +512,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