Skip to content

Commit

Permalink
#448 Implement dispatching of actions on next model-update (#141)
Browse files Browse the repository at this point in the history
* #448 Implement dispatching of actions on next model-update

and update `WorkflowLayoutEngine` to dispatch a `CenterAction` after the next model update.
Fixes eclipse-glsp/glsp#448

* Address review feedback

* Update jetty-bundles version

Verson 4.14 no longer exists in p2 repository. Update to new 4.44 Version
  • Loading branch information
tortmayr authored Nov 4, 2021
1 parent 742be5d commit 388cfe6
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 16 deletions.
14 changes: 7 additions & 7 deletions plugins/org.eclipse.glsp.server.websocket/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ Bundle-Vendor: Eclipse GLSP
Automatic-Module-Name: com.eclipsesource.glps.server.websocket
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: javax.websocket;bundle-version="1.0.0";visibility:=reexport,
org.eclipse.jetty.server;bundle-version="9.4.14";visibility:=reexport,
org.eclipse.jetty.servlet;bundle-version="9.4.14";visibility:=reexport,
org.eclipse.jetty.util;bundle-version="9.4.14";visibility:=reexport,
org.eclipse.jetty.websocket.javax.websocket;bundle-version="9.4.14";visibility:=reexport,
org.eclipse.jetty.websocket.javax.websocket.server;bundle-version="9.4.14";visibility:=reexport,
org.eclipse.jetty.server;bundle-version="9.4.44";visibility:=reexport,
org.eclipse.jetty.servlet;bundle-version="9.4.44";visibility:=reexport,
org.eclipse.jetty.util;bundle-version="9.4.44";visibility:=reexport,
org.eclipse.jetty.websocket.javax.websocket;bundle-version="9.4.44";visibility:=reexport,
org.eclipse.jetty.websocket.javax.websocket.server;bundle-version="9.4.44";visibility:=reexport,
org.eclipse.glsp.server;bundle-version="0.9.0",
org.eclipse.lsp4j.websocket;bundle-version="0.9.0",
org.eclipse.jetty.webapp;bundle-version="9.4.14";visibility:=reexport,
org.eclipse.jetty.websocket.api;bundle-version="9.4.14";visibility:=reexport,
org.eclipse.jetty.webapp;bundle-version="9.4.44";visibility:=reexport,
org.eclipse.jetty.websocket.api;bundle-version="9.4.44";visibility:=reexport,
com.google.gson,
org.eclipse.lsp4j,
org.eclipse.lsp4j.jsonrpc
Expand Down
2 changes: 1 addition & 1 deletion plugins/org.eclipse.glsp.server.websocket/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>javax-websocket-server-impl</artifactId>
<version>9.4.14.v20181114</version>
<version>9.4.44.v20210927</version>
</dependency>
<dependency>
<groupId>org.eclipse.lsp4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.stream.Collectors;

import org.eclipse.glsp.server.disposable.IDisposable;
import org.eclipse.glsp.server.features.core.model.UpdateModelAction;

public interface ActionDispatcher extends IDisposable {

Expand All @@ -45,4 +46,13 @@ public interface ActionDispatcher extends IDisposable {
default List<CompletableFuture<Void>> dispatchAll(final List<Action> actions) {
return actions.stream().map(action -> dispatch(action)).collect(Collectors.toList());
}

/**
* Processes all given actions, by dispatching them to the corresponding handlers, after the next model update.
* The given actions are queued until the next model update cycle has been completed i.e. an
* {@link UpdateModelAction} has been dispatched and processed by this action dispatcher.
*
* @param actions The actions that should be dispatched after the next model update
*/
void dispatchAfterNextUpdate(Action... actions);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
******************************************************************************/
package org.eclipse.glsp.server.actions;

import java.util.ArrayList;
import java.util.List;

public class SelectAction extends Action {
Expand All @@ -25,11 +26,15 @@ public class SelectAction extends Action {
private List<String> deselectedElementsIDs;

public SelectAction() {
super(ID);
this(new ArrayList<>());
}

public SelectAction(final List<String> selectedElementsIDs) {
this(selectedElementsIDs, new ArrayList<>());
}

public SelectAction(final List<String> selectedElementsIDs, final List<String> deselectedElementsIDs) {
this();
super(ID);
this.selectedElementsIDs = selectedElementsIDs;
this.deselectedElementsIDs = deselectedElementsIDs;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.eclipse.glsp.server.internal.actions;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand All @@ -35,6 +36,7 @@
import org.eclipse.glsp.server.actions.ResponseAction;
import org.eclipse.glsp.server.di.ClientId;
import org.eclipse.glsp.server.disposable.Disposable;
import org.eclipse.glsp.server.features.core.model.UpdateModelAction;
import org.eclipse.glsp.server.protocol.GLSPClient;
import org.eclipse.glsp.server.utils.FutureUtil;

Expand Down Expand Up @@ -67,6 +69,8 @@ public class DefaultActionDispatcher extends Disposable implements ActionDispatc

protected final BlockingQueue<Action> actionsQueue = new ArrayBlockingQueue<>(100, true);

protected List<Action> postUpdateQueue = new ArrayList<>();

// Results will be placed in the map when the action dispatcher receives a new action (From arbitrary threads),
// and will be removed from the dispatcher's thread.
protected final Map<Action, CompletableFuture<Void>> results = Collections.synchronizedMap(new HashMap<>());
Expand Down Expand Up @@ -100,6 +104,11 @@ public CompletableFuture<Void> dispatch(final Action action) {
return result;
}

@Override
public void dispatchAfterNextUpdate(final Action... actions) {
postUpdateQueue.addAll(Arrays.asList(actions));
}

protected void addToQueue(final Action action) {
if (Thread.currentThread() == this.thread) {
LOG.error("Actions shouldn't be added to the actions queue from the dispatcher thread!");
Expand Down Expand Up @@ -183,10 +192,20 @@ protected List<CompletableFuture<Void>> runAction(final Action action) {
.map(response -> ResponseAction.respond(action, response))
.collect(Collectors.toList());
results.addAll(dispatchAll(responses));
if (action instanceof UpdateModelAction) {
results.add(dispatchPostUpdateQueue());
}
}
return results;
}

protected CompletableFuture<Void> dispatchPostUpdateQueue() {
ArrayList<Action> toDispatch = new ArrayList<>(postUpdateQueue);
postUpdateQueue.clear();
dispatchAll(toDispatch);
return CompletableFuture.completedFuture(null);
}

protected final void checkThread() {
if (Thread.currentThread() != thread) {
throw new IllegalStateException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
********************************************************************************/
package org.eclipse.glsp.server.operations.gmodel;

import java.util.List;
import java.util.Map;
import java.util.Optional;

Expand All @@ -25,9 +26,11 @@
import org.eclipse.glsp.graph.GNode;
import org.eclipse.glsp.graph.GPoint;
import org.eclipse.glsp.graph.util.GraphUtil;
import org.eclipse.glsp.server.actions.ActionDispatcher;
import org.eclipse.glsp.server.actions.SelectAction;
import org.eclipse.glsp.server.model.GModelState;
import org.eclipse.glsp.server.operations.CreateNodeOperation;
import org.eclipse.glsp.server.operations.AbstractCreateOperationHandler;
import org.eclipse.glsp.server.operations.CreateNodeOperation;
import org.eclipse.glsp.server.utils.GeometryUtil;

import com.google.inject.Inject;
Expand All @@ -37,6 +40,9 @@ public abstract class CreateNodeOperationHandler extends AbstractCreateOperation
@Inject
protected GModelState modelState;

@Inject
protected ActionDispatcher actionDispatcher;

public CreateNodeOperationHandler(final String elementTypeId) {
super(elementTypeId);
}
Expand All @@ -53,6 +59,7 @@ public void executeOperation(final CreateNodeOperation operation) {
Optional<GPoint> relativeLocation = getRelativeLocation(operation, absoluteLocation, container);
GModelElement element = createNode(relativeLocation, operation.getArgs());
container.get().getChildren().add(element);
actionDispatcher.dispatchAfterNextUpdate(new SelectAction(), new SelectAction(List.of(element.getId())));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions targetplatforms/r2021-03.target
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde?>
<!-- generated with https://github.com/eclipse-cbi/targetplatform-dsl -->
<target name="2021-03 - Release" sequenceNumber="1628018980">
<target name="2021-03 - Release" sequenceNumber="1636038432">
<locations>
<location includeMode="planner" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="false" type="InstallableUnit">
<unit id="org.eclipse.equinox.p2.discovery.feature.feature.group" version="1.2.800.v20200916-1234"/>
Expand All @@ -22,8 +22,8 @@
<repository location="https://download.eclipse.org/tools/orbit/downloads/drops/R20210602031627/repository/"/>
</location>
<location includeMode="planner" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="false" type="InstallableUnit">
<unit id="org.eclipse.jetty.bundles.f.feature.group" version="9.4.14.v20181113"/>
<repository location="https://download.eclipse.org/jetty/updates/jetty-bundles-9.x/9.4.14.v20181113/"/>
<unit id="org.eclipse.jetty.bundles.f.feature.group" version="9.4.44.v20210927"/>
<repository location="https://download.eclipse.org/jetty/updates/jetty-bundles-9.x/9.4.44.v20210927/"/>
</location>
<location includeMode="planner" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="false" type="InstallableUnit">
<unit id="org.eclipse.elk.core" version="0.7.1"/>
Expand Down
4 changes: 2 additions & 2 deletions targetplatforms/r2021-03.tpd
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ location "https://download.eclipse.org/tools/orbit/downloads/drops/R202106020316
org.junit.jupiter.api [5.7.1,5.7.2)
}

location "https://download.eclipse.org/jetty/updates/jetty-bundles-9.x/9.4.14.v20181113/" {
org.eclipse.jetty.bundles.f.feature.group
location "https://download.eclipse.org/jetty/updates/jetty-bundles-9.x/9.4.44.v20210927/" {
org.eclipse.jetty.bundles.f.feature.group
}

location "https://download.eclipse.org/elk/updates/releases/0.7.1/" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ public CompletableFuture<Void> dispatch(final Action action) {
dispatchedActions.add(action);
return CompletableFuture.completedFuture(null);
}

@Override
public void dispatchAfterNextUpdate(final Action... actions) {}
}

class MockClientSessionManager implements ClientSessionManager {
Expand Down

0 comments on commit 388cfe6

Please sign in to comment.