Skip to content

Commit

Permalink
#96 #94 Cleanup and refactor client-server communication (#73)
Browse files Browse the repository at this point in the history
* #96 #94 Cleanup and refactor client-server communication

- Refactor client-server communication into a base protocol and a jsonrpc specific implementation (#94)
- Cleanup protocol and implement (previously unused) shutdown method
- Add ClientSessionManager to track lifecycle of GLSP client connections (#96)
- Add listener-mechanism to react to lifecycle changes (used in 
DefaultModelStateProvider)
- Remove (now obsolete) GLSPClientProxyProvider
- Fix wrong version of guava in org.eclipse.glsp.graph pom.xml
- Add unique applicationId to InitializeParameters

Part of:
- eclipse-glsp/glsp/issues/94
- eclipse-glsp/glsp/issues/96

* Fix minors

* Adapt copyright headers and fix checkstyle warnings

Co-authored-by: Philip Langer <planger@eclipsesource.com>
  • Loading branch information
tortmayr and planger authored Aug 25, 2020
1 parent 37e781b commit c58cdef
Show file tree
Hide file tree
Showing 39 changed files with 422 additions and 191 deletions.
7 changes: 2 additions & 5 deletions plugins/org.eclipse.glsp.api/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,22 @@ Require-Bundle: org.eclipse.lsp4j,
org.eclipse.lsp4j.jsonrpc;bundle-version="0.7.0",
javax.websocket;bundle-version="1.0.0";visibility:=reexport,
org.eclipse.glsp.graph;bundle-version="0.7.0";visibility:=reexport,
com.google.gson,
com.google.inject;bundle-version="3.0.0";visibility:=reexport,
com.google.guava;bundle-version="21.0.0"
com.google.gson
Bundle-ClassPath: .
Export-Package: org.eclipse.glsp.api.action,
org.eclipse.glsp.api.action.kind,
org.eclipse.glsp.api.configuration,
org.eclipse.glsp.api.di,
org.eclipse.glsp.api.diagram,
org.eclipse.glsp.api.factory,
org.eclipse.glsp.api.handler,
org.eclipse.glsp.api.json,
org.eclipse.glsp.api.jsonrpc,
org.eclipse.glsp.api.labeledit,
org.eclipse.glsp.api.layout,
org.eclipse.glsp.api.markers,
org.eclipse.glsp.api.model,
org.eclipse.glsp.api.operation,
org.eclipse.glsp.api.operation.kind,
org.eclipse.glsp.api.protocol,
org.eclipse.glsp.api.provider,
org.eclipse.glsp.api.registry,
org.eclipse.glsp.api.types,
Expand Down
10 changes: 0 additions & 10 deletions plugins/org.eclipse.glsp.api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,6 @@
<artifactId>org.eclipse.lsp4j.jsonrpc</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-multibindings</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.glsp</groupId>
<artifactId>org.eclipse.glsp.graph</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2019 EclipseSource and others.
* Copyright (c) 2019-2020 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -39,6 +39,7 @@ public static class Kind {
public static final String CLEAR_MARKERS = "clearMarkers";
public static final String COMPUTED_BOUNDS = "computedBounds";
public static final String CUT_ACTION = "cut";
public static final String DISPOSE_CLIENT = "disposeClient";
public static final String EXECUTE_OPERATION = "executeOperation";
public static final String EXECUTE_SERVER_COMMAND = "executeServerCommand";
public static final String EXPORT_SVG = "exportSvg";
Expand All @@ -55,6 +56,7 @@ public static class Kind {
public static final String REQUEST_OPERATIONS = "requestOperations";
public static final String REQUEST_POPUP_MODEL = "requestPopupModel";
public static final String REQUEST_TYPE_HINTS = "requestTypeHints";
public static final String RESOLVE_NAVIGATION_TARGET = "resolveNavigationTarget";
public static final String SAVE_MODEL = "saveModel";
public static final String SELECT = "selectElement";
public static final String SELECT_ALL = "allSelected";
Expand All @@ -64,21 +66,21 @@ public static class Kind {
public static final String SET_CLIPBOARD_DATA = "setClipboardData";
public static final String SET_CONTEXT_ACTIONS = "setContextActions";
public static final String SET_DIRTY_STATE = "setDirtyState";
public static final String SET_EDIT_MODE = "setEditMode";
public static final String SET_EDIT_VALIDATION_RESULT = "setEditValidationResult";
public static final String SET_LABEL_EDIT_VALIDATION_RESULT_ACTION = "setLabelEditValidationResult";
public static final String SET_LAYERS = "setLayers";
public static final String SET_MARKERS = "setMarkers";
public static final String SET_MODEL = "setModel";
public static final String SET_NAVIGATION_TARGETS = "setNavigationTargets";
public static final String SET_POPUP_MODEL = "setPopupModel";
public static final String SET_RESOLVED_NAVIGATION_TARGET = "setResolvedNavigationTarget";
public static final String SET_TYPE_HINTS = "setTypeHints";
public static final String TRIGGER_NODE_CREATION = "triggerNodeCreation";
public static final String TRIGGER_EDGE_CREATION = "triggerEdgeCreation";
public static final String TRIGGER_NODE_CREATION = "triggerNodeCreation";
public static final String UNDO = "glspUndo";
public static final String UPDATE_MODEL = "updateModel";
public static final String VALIDATE_LABEL_EDIT_ACTION = "validateLabelEdit";
public static final String RESOLVE_NAVIGATION_TARGET = "resolveNavigationTarget";
public static final String SET_RESOLVED_NAVIGATION_TARGET = "setResolvedNavigationTarget";
public static final String SET_EDIT_MODE = "setEditMode";
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 EclipseSource and others.
/********************************************************************************
* Copyright (c) 2020 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -12,9 +12,15 @@
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
******************************************************************************/
package org.eclipse.glsp.api.jsonrpc;
********************************************************************************/
package org.eclipse.glsp.api.action.kind;

import org.eclipse.glsp.api.action.Action;

public class DisposeClientAction extends Action {

public DisposeClientAction() {
super(Action.Kind.DISPOSE_CLIENT);
}

public interface GLSPClientAware {
void connect(GLSPClient client);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 EclipseSource and others.
/********************************************************************************
* Copyright (c) 2020 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -12,17 +12,17 @@
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
******************************************************************************/
********************************************************************************/
package org.eclipse.glsp.api.jsonrpc;

/**
* A registry to associate & retrieve a {@link GLSPClient} from a
* <code>clientId</code>.
*/
public interface GLSPClientProvider {
void register(String clientId, GLSPClient client);
import org.eclipse.glsp.api.action.ActionMessage;
import org.eclipse.glsp.api.protocol.GLSPClient;
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;

GLSPClient resolve(String clientId);
public interface GLSPJsonrpcClient extends GLSPClient {

@Override
@JsonNotification("process")
void process(ActionMessage message);

void remove(String clientId);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 EclipseSource and others.
/********************************************************************************
* Copyright (c) 2020 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -12,33 +12,27 @@
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
******************************************************************************/
********************************************************************************/
package org.eclipse.glsp.api.jsonrpc;

import java.util.concurrent.CompletableFuture;

import org.eclipse.glsp.api.action.ActionMessage;
import org.eclipse.glsp.api.types.ServerStatus;
import org.eclipse.glsp.api.protocol.GLSPServer;
import org.eclipse.glsp.api.protocol.InitializeParameters;
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest;

public interface GLSPServer extends GLSPClientAware {

public interface Provider {
GLSPServer getGraphicalLanguageServer(String clientId);
}

@JsonRequest("initialize")
public interface GLSPJsonrpcServer extends GLSPServer<GLSPJsonrpcClient> {
@Override
@JsonRequest
CompletableFuture<Boolean> initialize(InitializeParameters params);

@JsonNotification("process")
@Override
@JsonNotification
void process(ActionMessage message);

@JsonRequest("shutdown")
CompletableFuture<Object> shutdown();

@JsonNotification("exit")
void exit(String clientId);

ServerStatus getStatus();
@Override
@JsonRequest
CompletableFuture<Boolean> shutdown();
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ default void addError(final String message, final Map<String, String> args) {
args.put(ERROR, message);
}

public class NullImpl implements NavigationTargetResolver {
class NullImpl implements NavigationTargetResolver {
@Override
public NavigationTargetResolution resolve(final NavigationTarget navigationTarget,
final GraphicalModelState modelState) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/********************************************************************************
* Copyright (c) 2020 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
package org.eclipse.glsp.api.protocol;

public interface ClientSessionListener {

default void clientConnected(final GLSPClient client) {
// No-op as default. This enables partial interface implementation.
}

default void sessionCreated(final String clientId, final GLSPClient client) {
// No-op as default. This enables partial interface implementation.
}

default void sessionClosed(final String clientId, final GLSPClient client) {
// No-op as default. This enables partial interface implementation.
}

default void clientDisconnected(final GLSPClient client) {
// No-op as default. This enables partial interface implementation.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/********************************************************************************
* Copyright (c) 2020 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
package org.eclipse.glsp.api.protocol;

import java.util.Optional;

public interface ClientSessionManager {

boolean connectClient(GLSPClient client);

boolean createClientSession(GLSPClient glspClient, String clientId);

boolean disposeClientSession(String clientId);

boolean disconnectClient(GLSPClient client);

boolean addListener(ClientSessionListener listener);

boolean removeListener(ClientSessionListener listener);

Optional<GLSPClient> resolve(String clientId);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 EclipseSource and others.
* Copyright (c) 2019-2020 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -13,13 +13,11 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
******************************************************************************/
package org.eclipse.glsp.api.jsonrpc;
package org.eclipse.glsp.api.protocol;

import org.eclipse.glsp.api.action.ActionMessage;
import org.eclipse.lsp4j.jsonrpc.services.JsonNotification;

public interface GLSPClient {

@JsonNotification("process")
void process(ActionMessage message);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright (c) 2019-2020 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
******************************************************************************/
package org.eclipse.glsp.api.protocol;

import java.util.concurrent.CompletableFuture;

import org.eclipse.glsp.api.action.ActionMessage;

public interface GLSPServer<T extends GLSPClient> {
CompletableFuture<Boolean> initialize(InitializeParameters params);

void process(ActionMessage message);

CompletableFuture<Boolean> shutdown();

void connect(T client);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 EclipseSource and others.
* Copyright (c) 2019-2020 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -13,7 +13,7 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
******************************************************************************/
package org.eclipse.glsp.api.jsonrpc;
package org.eclipse.glsp.api.protocol;

import java.util.NoSuchElementException;
import java.util.Optional;
Expand Down Expand Up @@ -51,7 +51,7 @@ public GLSPServerException(final String message, final Throwable throwable) {
* @return the value
* @throws GLSPServerException if value not present
*/
public static <T> T getOrThrow(Optional<T> optional, String exceptionMessage) {
public static <T> T getOrThrow(final Optional<T> optional, final String exceptionMessage) {
try {
return optional.get();
} catch (NoSuchElementException ex) {
Expand All @@ -71,7 +71,7 @@ public static <T> T getOrThrow(Optional<T> optional, String exceptionMessage) {
* @throws GLSPServerException if value not present or could not an instance of
* T
*/
public static <T> T getOrThrow(Optional<?> optional, Class<T> clazz, String exceptionMessage) {
public static <T> T getOrThrow(final Optional<?> optional, final Class<T> clazz, final String exceptionMessage) {
try {
Object toCast = optional.get();
return clazz.cast(toCast);
Expand Down
Loading

0 comments on commit c58cdef

Please sign in to comment.