michael-o commented on a change in pull request #105:
URL: https://github.com/apache/maven-resolver/pull/105#discussion_r626037936



##########
File path: 
maven-resolver-synccontext-simple/src/main/java/org/eclipse/aether/named/simple/SimpleSyncContextFactory.java
##########
@@ -0,0 +1,368 @@
+package org.eclipse.aether.named.simple;
+
+/*
+ * 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.
+ */
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.EOFException;
+import java.io.File;
+import java.io.IOException;
+import java.io.InterruptedIOException;
+import java.io.RandomAccessFile;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.nio.channels.FileLock;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Random;
+import java.util.TreeSet;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ForkJoinPool;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Stream;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.SyncContext;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.metadata.Metadata;
+import org.eclipse.aether.spi.synccontext.SyncContextFactory;
+
+@Named
+@Singleton
+public class SimpleSyncContextFactory implements SyncContextFactory {
+
+    public static final String REQUEST_CONTEXT = "request-context";
+    public static final String REQUEST_ACQUIRE = "request-acquire";
+    public static final String REQUEST_CLOSE = "request-close";
+    public static final String RESPONSE_CONTEXT = "response-context";
+    public static final String RESPONSE_ACQUIRE = "response-acquire";
+    public static final String RESPONSE_CLOSE = "response-close";
+
+    Socket socket;
+    DataOutputStream output;
+    DataInputStream input;
+    Thread receiver;
+    AtomicInteger requestId = new AtomicInteger();
+    Map<Integer, CompletableFuture<List<String>>> responses = new 
ConcurrentHashMap<>();
+
+    @Override
+    public SyncContext newInstance(RepositorySystemSession session, boolean 
shared) {
+        return new SimpleSyncContext(session, shared);
+    }
+
+    synchronized Socket ensureInitialized() throws IOException {
+        if (socket == null) {
+            socket = createClient();
+            input = new DataInputStream(socket.getInputStream());
+            output = new DataOutputStream(socket.getOutputStream());
+            receiver = new Thread(this::receive);
+            receiver.setDaemon(true);
+            receiver.start();
+        }
+        return socket;
+    }
+
+    synchronized Socket createClient() throws IOException {
+        Path registryFile = Paths.get(System.getProperty("user.home"))
+                .resolve(".m2/sync.bin").toAbsolutePath().normalize();

Review comment:
       Yes, this sounds reasonable to me, .e.g, `resolver-synccontext-ipc.lock` 
or similar.




-- 
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:
us...@infra.apache.org


Reply via email to