sdedic commented on a change in pull request #2913:
URL: https://github.com/apache/netbeans/pull/2913#discussion_r620660670



##########
File path: 
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/LspSession.java
##########
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.lsp.server;
+
+import java.util.concurrent.Future;
+
+import org.netbeans.api.annotations.common.CheckForNull;
+import org.netbeans.modules.java.lsp.server.debugging.NbProtocolServer;
+import org.netbeans.modules.java.lsp.server.protocol.NbLspServer;
+
+import org.openide.util.Lookup;
+import org.openide.util.lookup.ProxyLookup;
+
+/**
+ * A session that provides associated LSP and DAP servers.
+ *
+ * @author martin
+ */
+public final class LspSession {
+
+    private final ProxyLookup.Controller lspServices = new 
ProxyLookup.Controller();
+    private final ProxyLookup.Controller dapServices = new 
ProxyLookup.Controller();
+    private final Lookup sessionLookup;
+
+    private volatile NbLspServer lspServer;
+    private volatile NbProtocolServer dapServer;
+
+    LspSession() {
+        sessionLookup = new ProxyLookup(
+                new ProxyLookup(lspServices),
+                new ProxyLookup(dapServices),
+                Lookup.getDefault()
+        );
+    }
+
+    /**
+     * Set the launched LSP server.
+     */
+    void setLspServer(NbLspServer lspServer) {
+        if (lspServer != null && this.lspServer != null) {
+            throw new IllegalStateException("LSP server is set already");
+        }
+        setServerLookup(lspServer, lspServices);
+        this.lspServer = lspServer;
+    }
+
+    /**
+     * Set the launched DAP server.
+     */
+    void setDapServer(NbProtocolServer dapServer) {
+        if (dapServer != null && this.dapServer != null) {
+            throw new IllegalStateException("DAP server is set already");
+        }
+        setServerLookup(dapServer, dapServices);
+        this.dapServer = dapServer;
+    }
+
+    private static void setServerLookup(ScheduledServer server, 
ProxyLookup.Controller lookupControler) {

Review comment:
       Sorry, I was not reading well the diff (I thought there's just one 
controller).

##########
File path: 
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/LspSession.java
##########
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.lsp.server;
+
+import java.util.concurrent.Future;
+
+import org.netbeans.api.annotations.common.CheckForNull;
+import org.netbeans.modules.java.lsp.server.debugging.NbProtocolServer;
+import org.netbeans.modules.java.lsp.server.protocol.NbLspServer;
+
+import org.openide.util.Lookup;
+import org.openide.util.lookup.ProxyLookup;
+
+/**
+ * A session that provides associated LSP and DAP servers.
+ *
+ * @author martin
+ */
+public final class LspSession {
+
+    private final ProxyLookup.Controller lspServices = new 
ProxyLookup.Controller();
+    private final ProxyLookup.Controller dapServices = new 
ProxyLookup.Controller();
+    private final Lookup sessionLookup;
+
+    private volatile NbLspServer lspServer;
+    private volatile NbProtocolServer dapServer;
+
+    LspSession() {
+        sessionLookup = new ProxyLookup(
+                new ProxyLookup(lspServices),
+                new ProxyLookup(dapServices),
+                Lookup.getDefault()
+        );
+    }
+
+    /**
+     * Set the launched LSP server.
+     */
+    void setLspServer(NbLspServer lspServer) {
+        if (lspServer != null && this.lspServer != null) {
+            throw new IllegalStateException("LSP server is set already");
+        }
+        setServerLookup(lspServer, lspServices);
+        this.lspServer = lspServer;
+    }
+
+    /**
+     * Set the launched DAP server.
+     */
+    void setDapServer(NbProtocolServer dapServer) {
+        if (dapServer != null && this.dapServer != null) {
+            throw new IllegalStateException("DAP server is set already");
+        }
+        setServerLookup(dapServer, dapServices);
+        this.dapServer = dapServer;
+    }
+
+    private static void setServerLookup(ScheduledServer server, 
ProxyLookup.Controller lookupControler) {

Review comment:
       Sorry, I was not reading the diff well (I thought there's just one 
controller).




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to