Skip to content

Commit

Permalink
gs-reactor: Do not share tag tree between webSockets
Browse files Browse the repository at this point in the history
Otherwise, when an annotation is modified in a webSocket, the modification is
sent to the tag tree immediately, so it is seen by other webSockets even if it
has not been flushed yet.
  • Loading branch information
fducroquet committed Jan 31, 2017
1 parent 48fdc40 commit b49ed23
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
Expand Up @@ -18,6 +18,7 @@
import org.genericsystem.kernel.Cache;
import org.genericsystem.reactor.HtmlDomNode;
import org.genericsystem.reactor.HtmlDomNode.RootHtmlDomNode;
import org.genericsystem.reactor.RootTag;
import org.genericsystem.reactor.appserver.WebAppsConfig.SimpleWebAppConfig;
import org.genericsystem.reactor.gscomponents.RootTagImpl;

Expand Down Expand Up @@ -83,6 +84,7 @@ private static class DomNodeVerticle extends AbstractVerticle {
private Cache cache;
private ServerWebSocket socket;
private PersistentApplication application;
private RootTag tagTree;
private RootHtmlDomNode rootHtmlDomNode;

DomNodeVerticle(Cache cache, ServerWebSocket socket, PersistentApplication application) {
Expand All @@ -94,7 +96,18 @@ private static class DomNodeVerticle extends AbstractVerticle {
@Override
public void start(Future<Void> startFuture) {
GSVertx.vertx().getVertx().executeBlocking(future -> {
RootHtmlDomNode result = cache.safeSupply(() -> application.init(s -> socket.writeFinalTextFrame(s)));
try {
tagTree = (RootTag) application.getApplicationClass().newInstance().initTree();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | SecurityException e) {
try {
cache.start();
tagTree = (RootTag) application.getApplicationClass().getConstructor(Root.class).newInstance(application.getEngine()).initTree();
cache.flush();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | SecurityException | InvocationTargetException | NoSuchMethodException ex) {
throw new IllegalStateException(ex);
}
}
RootHtmlDomNode result = cache.safeSupply(() -> application.init(s -> socket.writeFinalTextFrame(s), tagTree));
future.complete(result);
}, res -> {
if (res.succeeded())
Expand Down
Expand Up @@ -15,7 +15,6 @@
public class PersistentApplication {

private final Class<? extends RootTag> htmlAppClass;
private RootTag tagTree;
private final Root engine;
private final Class<Context> modelClass;
private final String rootId;
Expand All @@ -40,17 +39,6 @@ public PersistentApplication(Class<? extends RootTag> htmlAppClass, Class<Contex
cache.safeConsum(unused -> runner.run(getEngine()));
log.info("Script has run");
}
try {
tagTree = (RootTag) getApplicationClass().newInstance().initTree();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | SecurityException e) {
try {
engine.newCache().start();
tagTree = (RootTag) getApplicationClass().getConstructor(Root.class).newInstance(engine).initTree();
engine.getCurrentCache().flush();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | SecurityException | InvocationTargetException | NoSuchMethodException ex) {
throw new IllegalStateException(ex);
}
}
}

public String getRootId() {
Expand All @@ -77,7 +65,7 @@ public void setIndexHtml(String indexHtml) {
this.indexHtml = indexHtml;
}

public RootHtmlDomNode init(Sender send) {
public RootHtmlDomNode init(Sender send, RootTag tagTree) {
try {
return tagTree.init(modelClass.getConstructor(Root.class).newInstance(engine), rootId, send);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
Expand Down

0 comments on commit b49ed23

Please sign in to comment.