Pictogram 1.6, Beta 6, issue #437, #439,#440. Optimización de conexiones a…

Pictogram 1.6, Beta 6, issue #437, #439,#440. Optimización de conexiones a internet. Posible solución para caida de websockets
parent 080284e2
...@@ -321,19 +321,22 @@ public class Picto extends Img { ...@@ -321,19 +321,22 @@ public class Picto extends Img {
* *
* @return if the picto is visible * @return if the picto is visible
*/ */
public boolean is_invisible(LinkedList<Integer> visited) { private boolean is_invisible(LinkedList<Integer> visited) {
boolean visible=!is_invisible1(); boolean visible=!is_invisible1();
if (visible && has_child_grid() && !visited.contains(get_child_grid())) { if (visible && has_child_grid() && !visited.contains(get_child_grid())) {
visited.add(get_child_grid()); visited.add(get_child_grid());
LinkedList<Picto> childs = PCBcontext.getVocabulary().next(get_child_grid()); LinkedList<Picto> childs = PCBcontext.getVocabulary().next(get_child_grid());
if (childs==null)
Log.e(LOG_TAG,"Picto "+this.get_legend()+ " with empty grid "+get_child_grid()); if (childs==null) {
else Log.e(LOG_TAG, " Picto " + this.get_translation() + " with empty grid " + get_child_grid() + " is invisible?" + (!visible));
visible=false;
}else {
for (Picto child : childs) { for (Picto child : childs) {
visible = !child.is_invisible(visited); visible = !child.is_invisible(visited);
if (visible) break; if (visible) break;
} }
} }
}
return !visible; return !visible;
} }
......
...@@ -37,7 +37,7 @@ import java.util.concurrent.TimeUnit; ...@@ -37,7 +37,7 @@ import java.util.concurrent.TimeUnit;
public class NetService implements Runnable, RestapiWrapper.iSilentLogin { public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
private static final String LOG_TAG=NetService.class.getCanonicalName(); private static final String LOG_TAG=NetService.class.getCanonicalName();
private static final String ping_session="server/ping"; private static final String ping_session="server/ping_session";
private boolean updated; private boolean updated;
private final Vector<iNetServiceStatus> listeners; private final Vector<iNetServiceStatus> listeners;
...@@ -160,7 +160,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin { ...@@ -160,7 +160,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
return; return;
} }
long now = new Date().getTime(); long now = new Date().getTime();
if ( (now < nextServerPing)) return; if (now < nextServerPing || !!updated) return;
nextServerPing=now+serverPingTimming; nextServerPing=now+serverPingTimming;
PCBcontext.getRestapiWrapper().ask(ping_session, new RestapiWrapper.iRestapiListener() { PCBcontext.getRestapiWrapper().ask(ping_session, new RestapiWrapper.iRestapiListener() {
...@@ -193,7 +193,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin { ...@@ -193,7 +193,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
PCBcontext.getRestapiWrapper().setToken(result.getString(TAG_TOKEN)); PCBcontext.getRestapiWrapper().setToken(result.getString(TAG_TOKEN));
} catch (JSONException e) { } catch (JSONException e) {
Log.e(LOG_TAG,"Error when getting token:"+e.getMessage()+" res:"+result.toString()); Log.e(LOG_TAG,"Error when ping:"+e.getMessage()+" res:"+result.toString());
} }
if (PCBcontext.is_user_logged()) //si el usuario aun no hizo login, en realidad no es necesario hacer nada if (PCBcontext.is_user_logged()) //si el usuario aun no hizo login, en realidad no es necesario hacer nada
// Comprobar si hay usuario offline, para hacer login transparente // Comprobar si hay usuario offline, para hacer login transparente
...@@ -223,6 +223,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin { ...@@ -223,6 +223,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
@Override @Override
public void error(RestapiWrapper.HTTPException e) { public void error(RestapiWrapper.HTTPException e) {
Log.e(LOG_TAG,"Error when asking:"+e.getMessage());
setOffline(e); setOffline(e);
} }
}); });
...@@ -272,6 +273,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin { ...@@ -272,6 +273,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
@Override @Override
public void error(RestapiWrapper.HTTPException e) { public void error(RestapiWrapper.HTTPException e) {
Log.e(LOG_TAG, "Raw error from server when getting student info:" + e.getMessage() + " (error " + e.getCode() + ")"); Log.e(LOG_TAG, "Raw error from server when getting student info:" + e.getMessage() + " (error " + e.getCode() + ")");
restart_app(false);
} }
}); });
} }
...@@ -287,6 +289,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin { ...@@ -287,6 +289,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
public void setOffline(Exception e) { public void setOffline(Exception e) {
this.updated=false; this.updated=false;
PCBcontext.getRoom().exit();
Log.e(LOG_TAG, "PCB offline because exception happens: " + e.getMessage()); Log.e(LOG_TAG, "PCB offline because exception happens: " + e.getMessage());
notifyStatus(); notifyStatus();
} }
......
...@@ -33,6 +33,8 @@ public class Room { ...@@ -33,6 +33,8 @@ public class Room {
private SailsSocketsIO socket=null; private SailsSocketsIO socket=null;
private boolean inRoom=false; private boolean inRoom=false;
private final Hashtable<String, Emitter.Listener> listeners; private final Hashtable<String, Emitter.Listener> listeners;
public Room( ) { public Room( ) {
Log.i(this.getClass().getName(), "Entering room"); Log.i(this.getClass().getName(), "Entering room");
listeners=new Hashtable<>(); listeners=new Hashtable<>();
...@@ -102,10 +104,13 @@ public class Room { ...@@ -102,10 +104,13 @@ public class Room {
this.listeners.put(msg, listener); this.listeners.put(msg, listener);
} }
private void listen_again() { private void listen_again() {
for (String msg: this.listeners.keySet()) { for (String msg: this.listeners.keySet()) {
Log.e(this.getClass().getName(), "******************************Listening to "+msg); if (this.socket!=null) {
Log.e(this.getClass().getName(), "******************************Listening to " + msg);
this.socket.unregisterMessage(msg); this.socket.unregisterMessage(msg);
this.socket.registerMessage(msg, this.listeners.get(msg)); this.socket.registerMessage(msg, this.listeners.get(msg));
}else Log.e(this.getClass().getName(), "******************************NULL socket when listening to " + msg);
} }
} }
...@@ -147,7 +152,7 @@ public class Room { ...@@ -147,7 +152,7 @@ public class Room {
super.finalize(); super.finalize();
Log.i(this.getClass().getName(), "Discarding room"); Log.i(this.getClass().getName(), "Discarding room");
Log.e(LOG_TAG,"Websocket connection is lost because ojbect is finalized"); Log.e(LOG_TAG,"Websocket connection is lost because ojbect is finalized");
PCBcontext.getNetService().setOffline(new SocketIOException("Websocket connection is lost because ojbect is finalized")); PCBcontext.getNetService().setOffline(new SocketIOException("Websocket connection is lost because object is finalized"));
exit(); exit();
} }
......
...@@ -130,9 +130,11 @@ public final class PCBcontext { ...@@ -130,9 +130,11 @@ public final class PCBcontext {
Log.e(LOG_TAG, "Unset when transaction is active, aborting transaction"); Log.e(LOG_TAG, "Unset when transaction is active, aborting transaction");
TransactionMonitor.endTransaction(false); TransactionMonitor.endTransaction(false);
} }
pcbdb = null; pcbdb = null;
room = null; room = null;
vocabulary = null; vocabulary = null;
studentTalk = null;
getNetService().notifyStatus(); getNetService().notifyStatus();
} }
@Override @Override
......
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