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 {
*
* @return if the picto is visible
*/
public boolean is_invisible(LinkedList<Integer> visited) {
private boolean is_invisible(LinkedList<Integer> visited) {
boolean visible=!is_invisible1();
if (visible && has_child_grid() && !visited.contains(get_child_grid())) {
visited.add(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());
else
if (childs==null) {
Log.e(LOG_TAG, " Picto " + this.get_translation() + " with empty grid " + get_child_grid() + " is invisible?" + (!visible));
visible=false;
}else {
for (Picto child : childs) {
visible = !child.is_invisible(visited);
if (visible) break;
}
}
}
return !visible;
}
......
......@@ -37,7 +37,7 @@ import java.util.concurrent.TimeUnit;
public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
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 final Vector<iNetServiceStatus> listeners;
......@@ -160,7 +160,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
return;
}
long now = new Date().getTime();
if ( (now < nextServerPing)) return;
if (now < nextServerPing || !!updated) return;
nextServerPing=now+serverPingTimming;
PCBcontext.getRestapiWrapper().ask(ping_session, new RestapiWrapper.iRestapiListener() {
......@@ -193,7 +193,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
PCBcontext.getRestapiWrapper().setToken(result.getString(TAG_TOKEN));
} 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
// Comprobar si hay usuario offline, para hacer login transparente
......@@ -223,6 +223,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
@Override
public void error(RestapiWrapper.HTTPException e) {
Log.e(LOG_TAG,"Error when asking:"+e.getMessage());
setOffline(e);
}
});
......@@ -272,6 +273,7 @@ public class NetService implements Runnable, RestapiWrapper.iSilentLogin {
@Override
public void error(RestapiWrapper.HTTPException e) {
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 {
public void setOffline(Exception e) {
this.updated=false;
PCBcontext.getRoom().exit();
Log.e(LOG_TAG, "PCB offline because exception happens: " + e.getMessage());
notifyStatus();
}
......
......@@ -33,6 +33,8 @@ public class Room {
private SailsSocketsIO socket=null;
private boolean inRoom=false;
private final Hashtable<String, Emitter.Listener> listeners;
public Room( ) {
Log.i(this.getClass().getName(), "Entering room");
listeners=new Hashtable<>();
......@@ -102,10 +104,13 @@ public class Room {
this.listeners.put(msg, listener);
}
private void listen_again() {
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.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 {
super.finalize();
Log.i(this.getClass().getName(), "Discarding room");
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();
}
......
......@@ -130,9 +130,11 @@ public final class PCBcontext {
Log.e(LOG_TAG, "Unset when transaction is active, aborting transaction");
TransactionMonitor.endTransaction(false);
}
pcbdb = null;
room = null;
vocabulary = null;
studentTalk = null;
getNetService().notifyStatus();
}
@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