mirror of
https://github.com/apache/maven-mvnd.git
synced 2025-09-14 15:33:59 +00:00
Display the daemon id and shorten it a bit, fixes #314
This commit is contained in:

committed by
Peter Palaga

parent
3eb9d8d41b
commit
143f4f13ab
@@ -68,6 +68,10 @@ public class DaemonClientConnection implements Closeable {
|
|||||||
this.maxKeepAliveMs = parameters.keepAlive().toMillis() * parameters.maxLostKeepAlive();
|
this.maxKeepAliveMs = parameters.keepAlive().toMillis() * parameters.maxLostKeepAlive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DaemonInfo getDaemon() {
|
||||||
|
return daemon;
|
||||||
|
}
|
||||||
|
|
||||||
public void dispatch(Message message) throws DaemonException.ConnectException {
|
public void dispatch(Message message) throws DaemonException.ConnectException {
|
||||||
LOG.debug("thread {}: dispatching {}", Thread.currentThread().getId(), message.getClass());
|
LOG.debug("thread {}: dispatching {}", Thread.currentThread().getId(), message.getClass());
|
||||||
try {
|
try {
|
||||||
|
@@ -30,7 +30,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.UUID;
|
import java.util.Random;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -272,7 +272,7 @@ public class DaemonConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DaemonClientConnection startDaemon() {
|
public DaemonClientConnection startDaemon() {
|
||||||
final String daemon = UUID.randomUUID().toString();
|
final String daemon = newUid();
|
||||||
final Process process = startDaemon(daemon);
|
final Process process = startDaemon(daemon);
|
||||||
LOGGER.debug("Started Maven daemon {}", daemon);
|
LOGGER.debug("Started Maven daemon {}", daemon);
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
@@ -291,6 +291,10 @@ public class DaemonConnector {
|
|||||||
throw new DaemonException.ConnectException("Timeout waiting to connect to the Maven daemon.\n" + diag.describe());
|
throw new DaemonException.ConnectException("Timeout waiting to connect to the Maven daemon.\n" + diag.describe());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String newUid() {
|
||||||
|
return String.format("%08x", new Random().nextInt());
|
||||||
|
}
|
||||||
|
|
||||||
private Process startDaemon(String uid) {
|
private Process startDaemon(String uid) {
|
||||||
final Path mvndHome = parameters.mvndHome();
|
final Path mvndHome = parameters.mvndHome();
|
||||||
final Path workingDir = parameters.userDir();
|
final Path workingDir = parameters.userDir();
|
||||||
|
@@ -229,6 +229,7 @@ public class DefaultClient implements Client {
|
|||||||
|
|
||||||
final DaemonConnector connector = new DaemonConnector(parameters, registry);
|
final DaemonConnector connector = new DaemonConnector(parameters, registry);
|
||||||
try (DaemonClientConnection daemon = connector.connect(output)) {
|
try (DaemonClientConnection daemon = connector.connect(output)) {
|
||||||
|
output.setDaemonId(daemon.getDaemon().getUid());
|
||||||
output.setDaemonDispatch(daemon::dispatch);
|
output.setDaemonDispatch(daemon::dispatch);
|
||||||
output.setDaemonReceive(daemon::enqueue);
|
output.setDaemonReceive(daemon::enqueue);
|
||||||
|
|
||||||
|
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed 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.mvndaemon.mvnd.client;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
|
public class DaemonConnectorTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUid() {
|
||||||
|
String uid = DaemonConnector.newUid();
|
||||||
|
assertNotNull(uid);
|
||||||
|
assertEquals(8, uid.length());
|
||||||
|
}
|
||||||
|
}
|
@@ -24,6 +24,8 @@ import org.mvndaemon.mvnd.common.Message;
|
|||||||
*/
|
*/
|
||||||
public interface ClientOutput extends AutoCloseable {
|
public interface ClientOutput extends AutoCloseable {
|
||||||
|
|
||||||
|
void setDaemonId(String uid);
|
||||||
|
|
||||||
void setDaemonDispatch(Consumer<Message> sink);
|
void setDaemonDispatch(Consumer<Message> sink);
|
||||||
|
|
||||||
void setDaemonReceive(Consumer<Message> sink);
|
void setDaemonReceive(Consumer<Message> sink);
|
||||||
|
@@ -89,6 +89,7 @@ public class TerminalOutput implements ClientOutput {
|
|||||||
* Therefore, these fields do not need to be volatile
|
* Therefore, these fields do not need to be volatile
|
||||||
*/
|
*/
|
||||||
private String name;
|
private String name;
|
||||||
|
private String daemonId;
|
||||||
private int totalProjects;
|
private int totalProjects;
|
||||||
/** String format for formatting the number of projects done with padding based on {@link #totalProjects} */
|
/** String format for formatting the number of projects done with padding based on {@link #totalProjects} */
|
||||||
private String projectsDoneFomat;
|
private String projectsDoneFomat;
|
||||||
@@ -142,6 +143,11 @@ public class TerminalOutput implements ClientOutput {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDaemonId(String daemonId) {
|
||||||
|
this.daemonId = daemonId;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setDaemonDispatch(Consumer<Message> daemonDispatch) {
|
public void setDaemonDispatch(Consumer<Message> daemonDispatch) {
|
||||||
this.daemonDispatch = daemonDispatch;
|
this.daemonDispatch = daemonDispatch;
|
||||||
@@ -630,6 +636,13 @@ public class TerminalOutput implements ClientOutput {
|
|||||||
.append('%')
|
.append('%')
|
||||||
.style(AttributedStyle.DEFAULT);
|
.style(AttributedStyle.DEFAULT);
|
||||||
|
|
||||||
|
/* DaemonId */
|
||||||
|
asb
|
||||||
|
.append(" daemon: ")
|
||||||
|
.style(AttributedStyle.BOLD)
|
||||||
|
.append(daemonId)
|
||||||
|
.style(AttributedStyle.DEFAULT);
|
||||||
|
|
||||||
} else if (buildStatus != null) {
|
} else if (buildStatus != null) {
|
||||||
asb
|
asb
|
||||||
.style(AttributedStyle.BOLD)
|
.style(AttributedStyle.BOLD)
|
||||||
|
@@ -665,6 +665,9 @@ public class DaemonMavenCli {
|
|||||||
|
|
||||||
eventSpyDispatcher.onEvent(request);
|
eventSpyDispatcher.onEvent(request);
|
||||||
|
|
||||||
|
slf4jLogger.info(buffer().a("Processing build on daemon ")
|
||||||
|
.strong(Environment.MVND_UID.asString()).toString());
|
||||||
|
|
||||||
MavenExecutionResult result = maven.execute(request);
|
MavenExecutionResult result = maven.execute(request);
|
||||||
|
|
||||||
eventSpyDispatcher.onEvent(result);
|
eventSpyDispatcher.onEvent(result);
|
||||||
|
@@ -31,6 +31,10 @@ public class TestClientOutput implements ClientOutput {
|
|||||||
public void close() throws Exception {
|
public void close() throws Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDaemonId(String uid) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setDaemonDispatch(Consumer<Message> daemonDispatch) {
|
public void setDaemonDispatch(Consumer<Message> daemonDispatch) {
|
||||||
this.daemonDispatch = daemonDispatch;
|
this.daemonDispatch = daemonDispatch;
|
||||||
|
Reference in New Issue
Block a user