Skip to content

Commit

Permalink
Remove guava from eclipse-integration server
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-fleck-at committed Oct 28, 2024
1 parent 86443b2 commit 657b9a9
Showing 1 changed file with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@
********************************************************************************/
package org.eclipse.glsp.ide.editor;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import java.util.Map;

import org.eclipse.glsp.server.actions.ActionMessage;
import org.eclipse.glsp.server.protocol.GLSPClient;
import org.eclipse.glsp.server.protocol.GLSPServer;
import org.eclipse.glsp.server.session.ClientSessionManager;

import com.google.common.base.Preconditions;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.google.inject.Inject;

/**
Expand All @@ -45,10 +43,10 @@ public class IdeGLSPClient implements GLSPClient {
@Inject
protected ClientSessionManager clientSessionManager;

protected Multimap<String, GLSPClient> clientProxies;
protected Map<String, List<GLSPClient>> clientProxies;

public IdeGLSPClient() {
clientProxies = HashMultimap.create();
clientProxies = new HashMap<>();
}

/**
Expand All @@ -59,7 +57,7 @@ public IdeGLSPClient() {
* @param glspClient The GLSPClient proxy given client id). `false` otherwise.
*/
public void connect(final String clientSessionId, final GLSPClient glspClient) {
clientProxies.put(clientSessionId, glspClient);
clientProxies.computeIfAbsent(clientSessionId, id -> new ArrayList<>()).add(glspClient);
}

/**
Expand All @@ -71,7 +69,15 @@ public void connect(final String clientSessionId, final GLSPClient glspClient) {
* otherwise.
*/
public boolean disconnect(final String clientSessionId, final GLSPClient glspClient) {
return clientProxies.remove(clientSessionId, glspClient);
List<GLSPClient> clients = clientProxies.get(clientSessionId);
if (clients == null) {
return false;
}
boolean didDisconnect = clients.remove(glspClient);
if (clients.isEmpty()) {
clientProxies.remove(clientSessionId);
}
return didDisconnect;
}

/**
Expand All @@ -81,18 +87,16 @@ public boolean disconnect(final String clientSessionId, final GLSPClient glspCli
* @param glspClient The glsp client proxy that should be disconnected.
*/
public void disconnect(final GLSPClient glspClient) {
List<String> toRemove = clientProxies.entries().stream()
.filter(entry -> entry.getValue() == glspClient)
.map(Entry::getKey)
.collect(Collectors.toList());
toRemove.forEach(id -> disconnect(id, glspClient));
clientProxies.keySet().forEach(clientSessionId -> disconnect(clientSessionId, glspClient));
}

@Override
public void process(final ActionMessage message) {
Collection<GLSPClient> result = clientProxies.get(message.getClientId());
Preconditions.checkState(!result.isEmpty(),
"Could not retrieve GLSPCLient proxy for client session with id: " + message.getClientId());
if (result == null || result.isEmpty()) {
throw new IllegalArgumentException(
"Could not retrieve GLSPCLient proxy for client session with id: " + message.getClientId());
}
result.forEach(proxy -> proxy.process(message));
}

Expand Down

0 comments on commit 657b9a9

Please sign in to comment.