Commit d4683f4a authored by Yusuke Iwaki's avatar Yusuke Iwaki

fix issue realm#close() is called dupplicately

parent 68e85070
...@@ -123,13 +123,6 @@ public class MainActivity extends AbstractAuthedActivity { ...@@ -123,13 +123,6 @@ public class MainActivity extends AbstractAuthedActivity {
} }
} }
@Override protected void onResume() {
super.onResume();
if (sessionObserver != null) {
sessionObserver.keepalive();
}
}
@Override protected void onDestroy() { @Override protected void onDestroy() {
if (sessionObserver != null) { if (sessionObserver != null) {
sessionObserver.unsub(); sessionObserver.unsub();
......
...@@ -49,7 +49,6 @@ public class InputHostnameFragment extends AbstractServerConfigFragment { ...@@ -49,7 +49,6 @@ public class InputHostnameFragment extends AbstractServerConfigFragment {
@Override public void onResume() { @Override public void onResume() {
super.onResume(); super.onResume();
serverConfigObserver.keepalive();
} }
@Override public void onDestroyView() { @Override public void onDestroyView() {
......
...@@ -9,11 +9,6 @@ public interface Registerable { ...@@ -9,11 +9,6 @@ public interface Registerable {
*/ */
void register(); void register();
/**
* keepalive.
*/
void keepalive();
/** /**
* unregister. * unregister.
*/ */
......
...@@ -88,7 +88,7 @@ public class RocketChatService extends Service { ...@@ -88,7 +88,7 @@ public class RocketChatService extends Service {
} }
return null; return null;
}).onSuccessTask(task -> { }).onSuccessTask(task -> {
connectionRequiredServerConfigObserver.keepalive(); connectionRequiredServerConfigObserver.sub();
return null; return null;
}); });
return START_STICKY; return START_STICKY;
...@@ -133,6 +133,13 @@ public class RocketChatService extends Service { ...@@ -133,6 +133,13 @@ public class RocketChatService extends Service {
} }
} }
@Override public void onDestroy() {
if (connectionRequiredServerConfigObserver != null) {
connectionRequiredServerConfigObserver.unsub();
}
super.onDestroy();
}
@Nullable @Nullable
@Override @Override
public IBinder onBind(Intent intent) { public IBinder onBind(Intent intent) {
......
...@@ -134,8 +134,6 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -134,8 +134,6 @@ public class RocketChatWebSocketThread extends HandlerThread {
} }
return null; return null;
}); });
} else {
new Handler(getLooper()).post(this::keepaliveListeners);
} }
} }
...@@ -227,17 +225,6 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -227,17 +225,6 @@ public class RocketChatWebSocketThread extends HandlerThread {
} }
} }
//@DebugLog
private void keepaliveListeners() {
if (!listenersRegistered) {
return;
}
for (Registerable registerable : listeners) {
registerable.keepalive();
}
}
@DebugLog @DebugLog
private void unregisterListeners() { private void unregisterListeners() {
if (!listenersRegistered) { if (!listenersRegistered) {
......
...@@ -139,10 +139,6 @@ abstract class AbstractDDPDocEventSubscriber implements Registerable { ...@@ -139,10 +139,6 @@ abstract class AbstractDDPDocEventSubscriber implements Registerable {
} }
} }
@Override public void keepalive() {
}
@Override public void unregister() { @Override public void unregister() {
if (rxSubscription != null) { if (rxSubscription != null) {
rxSubscription.unsubscribe(); rxSubscription.unsubscribe();
......
...@@ -27,10 +27,6 @@ abstract class AbstractModelObserver<T extends RealmObject> ...@@ -27,10 +27,6 @@ abstract class AbstractModelObserver<T extends RealmObject>
observer.sub(); observer.sub();
} }
@Override public void keepalive() {
observer.keepalive();
}
@Override public void unregister() { @Override public void unregister() {
observer.unsub(); observer.unsub();
} }
......
...@@ -4,7 +4,6 @@ import io.realm.Realm; ...@@ -4,7 +4,6 @@ import io.realm.Realm;
import io.realm.RealmChangeListener; import io.realm.RealmChangeListener;
import io.realm.RealmObject; import io.realm.RealmObject;
import io.realm.RealmResults; import io.realm.RealmResults;
import timber.log.Timber;
abstract class AbstractRealmResultsObserver<T extends RealmObject> { abstract class AbstractRealmResultsObserver<T extends RealmObject> {
protected Realm realm; protected Realm realm;
...@@ -31,26 +30,16 @@ abstract class AbstractRealmResultsObserver<T extends RealmObject> { ...@@ -31,26 +30,16 @@ abstract class AbstractRealmResultsObserver<T extends RealmObject> {
results.addChangeListener(listener); results.addChangeListener(listener);
} }
public void keepalive() {
if (realm == null || realm.isClosed() || !results.isValid()) {
unsub();
sub();
}
}
public void unsub() { public void unsub() {
try { if (realm != null) {
if (results != null) { if (results != null) {
if (results.isValid()) { if (results.isValid()) {
results.removeChangeListener(listener); results.removeChangeListener(listener);
} }
results = null; results = null;
} }
if (realm != null && !realm.isClosed()) { realm.close();
realm.close(); realm = null;
}
} catch (IllegalStateException exception) {
Timber.w(exception, "failed to unsub. ignore.");
} }
} }
......
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 to comment