Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,31 @@ public class IpcClient {
static final boolean IS_WINDOWS =
System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("win");

volatile boolean initialized;
Path lockPath;
Path logPath;
Path syncPath;
SocketChannel socket;
DataOutputStream output;
DataInputStream input;
Thread receiver;
AtomicInteger requestId = new AtomicInteger();
Map<Integer, CompletableFuture<List<String>>> responses = new ConcurrentHashMap<>();
protected volatile boolean initialized;
protected final Path lockPath;
protected final Path logPath;
protected final Path syncPath;
protected final boolean noFork;

protected SocketChannel socket;
protected DataOutputStream output;
protected DataInputStream input;
protected Thread receiver;

protected final AtomicInteger requestId = new AtomicInteger();
protected final Map<Integer, CompletableFuture<List<String>>> responses = new ConcurrentHashMap<>();

IpcClient(Path lockPath, Path logPath, Path syncPath) {
this.lockPath = lockPath;
this.logPath = logPath;
this.syncPath = syncPath;
this.noFork = Boolean.parseBoolean(
System.getProperty(IpcServer.SYSTEM_PROP_NO_FORK, Boolean.toString(IpcServer.DEFAULT_NO_FORK)));
}

void ensureInitialized() throws IOException {
if (!initialized) {
// caller must block on this method
synchronized (this) {
if (!initialized) {
socket = createClient();
Expand Down Expand Up @@ -152,8 +158,6 @@ SocketChannel createClient() throws IOException {
Path logFile = logPath.resolve("resolver-ipcsync-" + rand + ".log");
List<String> args = new ArrayList<>();
if (noNative) {
boolean noFork = Boolean.parseBoolean(System.getProperty(
IpcServer.SYSTEM_PROP_NO_FORK, Boolean.toString(IpcServer.DEFAULT_NO_FORK)));
if (noFork) {
IpcServer server = IpcServer.runServer(family, tmpaddr, rand);
close = server::close;
Expand Down Expand Up @@ -326,6 +330,9 @@ List<String> send(List<String> request, long time, TimeUnit unit) throws Timeout
}

void close() {
if (noFork) {
stopServer();
}
close(new IOException("Closing"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class IpcServer {
*/
public static final String SYSTEM_PROP_IDLE_TIMEOUT = "aether.named.ipc.idleTimeout";

public static final int DEFAULT_IDLE_TIMEOUT = 60;
public static final int DEFAULT_IDLE_TIMEOUT = 300;

/**
* IPC socket family to use.
Expand Down Expand Up @@ -359,7 +359,7 @@ private void client(SocketChannel socket) {
c = clients.size();
}
if (!closing) {
info("%d clients left", c);
info("%d clients remained", c);
}
}
}
Expand All @@ -372,7 +372,7 @@ private void expirationCheck() {
while (true) {
long current = System.nanoTime();
long left = (lastUsed + idleTimeout) - current;
if (left < 0) {
if (clients.isEmpty() && left < 0) {
info("IpcServer expired, closing");
close();
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.eclipse.aether.named.ipc;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;

public class IpcAdapterNoForkIT extends NamedLockFactoryAdapterTestSupport {
@BeforeAll
static void createNamedLockFactory() {
// the goal if this IT to prove it works when noFork=true and IpcClient will clean up server
// needed in cases like in Maven, when there is no direct access to IpcNamedLockFactory
// to override doShutdown method like in IpcAdapterIT
System.setProperty(IpcServer.SYSTEM_PROP_NO_FORK, Boolean.TRUE.toString());
System.setProperty(IpcServer.SYSTEM_PROP_DEBUG, Boolean.TRUE.toString());
setNamedLockFactory(new IpcNamedLockFactory());
}

@AfterAll
static void cleanup() {
System.clearProperty(IpcServer.SYSTEM_PROP_NO_FORK);
}
}