Session control fixes

This commit is contained in:
crschnick 2024-04-19 10:05:05 +00:00
parent 385068a3de
commit e04c63d36f
2 changed files with 12 additions and 12 deletions

View file

@ -20,7 +20,7 @@ public interface SingletonSessionStoreProvider extends DataStoreProvider {
return Bindings.createBooleanBinding(
() -> {
SingletonSessionStore<?> s = wrapper.getEntry().getStore().asNeeded();
return s.isEnabled() != s.isRunning();
return s.isSessionEnabled() != s.isSessionRunning();
},
wrapper.getCache());
}
@ -31,16 +31,16 @@ public interface SingletonSessionStoreProvider extends DataStoreProvider {
return StoreEntryComp.create(sec.getWrapper(), t, preferLarge);
}
default Comp<?> createToggleComp(StoreSection sec) {
default StoreToggleComp createToggleComp(StoreSection sec) {
var enabled = new SimpleBooleanProperty();
sec.getWrapper().getCache().subscribe((newValue) -> {
SingletonSessionStore<?> s = sec.getWrapper().getEntry().getStore().asNeeded();
enabled.set(s.isEnabled());
enabled.set(s.isSessionEnabled());
});
var t = new StoreToggleComp(null, sec, enabled, aBoolean -> {
SingletonSessionStore<?> s = sec.getWrapper().getEntry().getStore().asNeeded();
if (s.isEnabled() != aBoolean) {
if (s.isSessionEnabled() != aBoolean) {
ThreadHelper.runFailableAsync(() -> {
if (aBoolean) {
s.startSessionIfNeeded();
@ -57,11 +57,11 @@ public interface SingletonSessionStoreProvider extends DataStoreProvider {
return new SystemStateComp(Bindings.createObjectBinding(
() -> {
SingletonSessionStore<?> s = w.getEntry().getStore().asNeeded();
if (!s.isEnabled()) {
if (!s.isSessionEnabled()) {
return SystemStateComp.State.OTHER;
}
return s.isRunning() ? SystemStateComp.State.SUCCESS : SystemStateComp.State.FAILURE;
return s.isSessionRunning() ? SystemStateComp.State.SUCCESS : SystemStateComp.State.FAILURE;
},
w.getCache()));
}

View file

@ -17,20 +17,20 @@ public interface SingletonSessionStore<T extends SingletonSessionStore.Session>
stopSessionIfNeeded();
}
default void setEnabled(boolean value) {
default void setSessionEnabled(boolean value) {
setCache("sessionEnabled", value);
}
default boolean isRunning() {
default boolean isSessionRunning() {
return getCache("sessionRunning", Boolean.class, false);
}
default boolean isEnabled() {
default boolean isSessionEnabled() {
return getCache("sessionEnabled", Boolean.class, false);
}
default void onSessionUpdate(boolean active) {
setEnabled(active);
setSessionEnabled(active);
setCache("sessionRunning", active);
}
@ -46,7 +46,7 @@ public interface SingletonSessionStore<T extends SingletonSessionStore.Session>
default void startSessionIfNeeded() throws Exception {
synchronized (this) {
var s = getSession();
setEnabled(true);
setSessionEnabled(true);
if (s != null) {
if (s.isRunning()) {
return;
@ -66,7 +66,7 @@ public interface SingletonSessionStore<T extends SingletonSessionStore.Session>
default void stopSessionIfNeeded() throws Exception {
synchronized (this) {
var ex = getSession();
setEnabled(false);
setSessionEnabled(false);
if (ex != null) {
ex.stop();
setCache("session", null);