mirror of
https://github.com/apache/maven-mvnd.git
synced 2025-09-12 22:19:11 +00:00
Merge pull request #437 from gnodet/i434
Add a system property to configure the idle timeout on the ipc sync s…
This commit is contained in:
@@ -132,6 +132,10 @@ public class IpcClient {
|
|||||||
}
|
}
|
||||||
args.add("-cp");
|
args.add("-cp");
|
||||||
args.add(classpath);
|
args.add(classpath);
|
||||||
|
String timeout = System.getProperty(IpcServer.IDLE_TIMEOUT_PROP);
|
||||||
|
if (timeout != null) {
|
||||||
|
args.add("-D" + IpcServer.IDLE_TIMEOUT_PROP + "=" + timeout);
|
||||||
|
}
|
||||||
args.add(IpcServer.class.getName());
|
args.add(IpcServer.class.getName());
|
||||||
args.add(Integer.toString(tmpport));
|
args.add(Integer.toString(tmpport));
|
||||||
args.add(Integer.toString(rand));
|
args.add(Integer.toString(rand));
|
||||||
|
@@ -46,6 +46,8 @@ import static org.mvndaemon.mvnd.sync.IpcMessages.RESPONSE_CONTEXT;
|
|||||||
*/
|
*/
|
||||||
public class IpcServer {
|
public class IpcServer {
|
||||||
|
|
||||||
|
public static final String IDLE_TIMEOUT_PROP = "ipcsync.idle.timeout";
|
||||||
|
|
||||||
static final long IDLE_TIMEOUT = TimeUnit.SECONDS.toNanos(60);
|
static final long IDLE_TIMEOUT = TimeUnit.SECONDS.toNanos(60);
|
||||||
|
|
||||||
private final ServerSocket serverSocket;
|
private final ServerSocket serverSocket;
|
||||||
@@ -53,13 +55,24 @@ public class IpcServer {
|
|||||||
private final AtomicInteger counter = new AtomicInteger();
|
private final AtomicInteger counter = new AtomicInteger();
|
||||||
private final Map<String, Lock> locks = new ConcurrentHashMap<>();
|
private final Map<String, Lock> locks = new ConcurrentHashMap<>();
|
||||||
private final Map<String, Context> contexts = new ConcurrentHashMap<>();
|
private final Map<String, Context> contexts = new ConcurrentHashMap<>();
|
||||||
|
private final long idleTimeout;
|
||||||
private volatile long lastUsed;
|
private volatile long lastUsed;
|
||||||
private volatile boolean closing;
|
private volatile boolean closing;
|
||||||
|
|
||||||
public IpcServer() throws IOException {
|
public IpcServer() throws IOException {
|
||||||
serverSocket = new ServerSocket();
|
serverSocket = new ServerSocket();
|
||||||
serverSocket.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
|
serverSocket.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
|
||||||
|
long timeout = IDLE_TIMEOUT;
|
||||||
|
String str = System.getProperty(IDLE_TIMEOUT_PROP);
|
||||||
|
if (str != null) {
|
||||||
|
try {
|
||||||
|
long dur = Long.parseLong(str);
|
||||||
|
timeout = TimeUnit.SECONDS.toNanos(dur);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
error("Property " + IDLE_TIMEOUT_PROP + " specified with invalid value: " + str, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
idleTimeout = timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
@@ -77,8 +90,7 @@ public class IpcServer {
|
|||||||
sun.misc.Signal.handle(new sun.misc.Signal("TSTP"), sun.misc.SignalHandler.SIG_IGN);
|
sun.misc.Signal.handle(new sun.misc.Signal("TSTP"), sun.misc.SignalHandler.SIG_IGN);
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
System.err.println("Unable to ignore INT and TSTP signals");
|
error("Unable to ignore INT and TSTP signals", t);
|
||||||
t.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int tmpPort = Integer.parseInt(args[0]);
|
int tmpPort = Integer.parseInt(args[0]);
|
||||||
@@ -251,7 +263,7 @@ public class IpcServer {
|
|||||||
private void expirationCheck() {
|
private void expirationCheck() {
|
||||||
while (true) {
|
while (true) {
|
||||||
long current = System.nanoTime();
|
long current = System.nanoTime();
|
||||||
if (current - lastUsed > IDLE_TIMEOUT) {
|
if (current - lastUsed > idleTimeout) {
|
||||||
close();
|
close();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -25,10 +25,22 @@ import org.eclipse.aether.impl.SyncContextFactory;
|
|||||||
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
|
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
|
||||||
import org.eclipse.aether.repository.LocalRepository;
|
import org.eclipse.aether.repository.LocalRepository;
|
||||||
import org.eclipse.aether.repository.LocalRepositoryManager;
|
import org.eclipse.aether.repository.LocalRepositoryManager;
|
||||||
|
import org.junit.jupiter.api.AfterAll;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class IpcSyncContextTest {
|
public class IpcSyncContextTest {
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
static void setup() {
|
||||||
|
System.setProperty(IpcServer.IDLE_TIMEOUT_PROP, "5");
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterAll
|
||||||
|
static void tearDown() {
|
||||||
|
System.clearProperty(IpcServer.IDLE_TIMEOUT_PROP);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testContextSimple() throws Exception {
|
public void testContextSimple() throws Exception {
|
||||||
SyncContextFactory factory = new IpcSyncContextFactory();
|
SyncContextFactory factory = new IpcSyncContextFactory();
|
||||||
|
Reference in New Issue
Block a user