mirror of
https://github.com/apache/maven-mvnd.git
synced 2025-09-10 04:59:54 +00:00
Fix display showing more projects than the ones actually active
This commit is contained in:
@@ -23,6 +23,7 @@ import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.io.UTFDataFormatException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -108,6 +109,51 @@ public abstract class Message {
|
||||
|
||||
final long timestamp = System.nanoTime();
|
||||
|
||||
public static Comparator<Message> getMessageComparator() {
|
||||
return Comparator.comparingInt(Message::getClassOrder).thenComparingLong(Message::timestamp);
|
||||
}
|
||||
|
||||
public static int getClassOrder(Message m) {
|
||||
switch (m.getType()) {
|
||||
case KEEP_ALIVE:
|
||||
case BUILD_REQUEST:
|
||||
return 0;
|
||||
case BUILD_STARTED:
|
||||
return 1;
|
||||
case PROMPT:
|
||||
case PROMPT_RESPONSE:
|
||||
case DISPLAY:
|
||||
return 2;
|
||||
case PROJECT_STARTED:
|
||||
return 3;
|
||||
case MOJO_STARTED:
|
||||
return 4;
|
||||
case TRANSFER_INITIATED:
|
||||
case TRANSFER_STARTED:
|
||||
return 40;
|
||||
case TRANSFER_PROGRESSED:
|
||||
return 41;
|
||||
case TRANSFER_CORRUPTED:
|
||||
case TRANSFER_SUCCEEDED:
|
||||
case TRANSFER_FAILED:
|
||||
return 42;
|
||||
case PROJECT_LOG_MESSAGE:
|
||||
return 50;
|
||||
case BUILD_LOG_MESSAGE:
|
||||
return 51;
|
||||
case PROJECT_STOPPED:
|
||||
return 95;
|
||||
case BUILD_FINISHED:
|
||||
return 96;
|
||||
case BUILD_EXCEPTION:
|
||||
return 97;
|
||||
case STOP:
|
||||
return 99;
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected message type " + m.getType() + ": " + m);
|
||||
}
|
||||
}
|
||||
|
||||
public long timestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
@@ -355,8 +355,10 @@ public class TerminalOutput implements ClientOutput {
|
||||
}
|
||||
case Message.PROJECT_LOG_MESSAGE: {
|
||||
final ProjectEvent bm = (ProjectEvent) entry;
|
||||
final Project prj = projects.computeIfAbsent(bm.getProjectId(), Project::new);
|
||||
if (noBuffering || dumb) {
|
||||
final Project prj = projects.get(bm.getProjectId());
|
||||
if (prj == null) {
|
||||
log.accept(bm.getMessage());
|
||||
} else if (noBuffering || dumb) {
|
||||
String msg;
|
||||
if (maxThreads > 1) {
|
||||
msg = String.format("[%s] %s", bm.getProjectId(), bm.getMessage());
|
||||
|
@@ -24,7 +24,6 @@ import java.nio.channels.SocketChannel;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@@ -429,8 +428,7 @@ public class Server implements AutoCloseable, Runnable {
|
||||
|
||||
private void handle(DaemonConnection connection, BuildRequest buildRequest) {
|
||||
updateState(Busy);
|
||||
final BlockingQueue<Message> sendQueue = new PriorityBlockingQueue<>(64,
|
||||
Comparator.comparingInt(this::getClassOrder).thenComparingLong(Message::timestamp));
|
||||
final BlockingQueue<Message> sendQueue = new PriorityBlockingQueue<>(64, Message.getMessageComparator());
|
||||
final BlockingQueue<Message> recvQueue = new LinkedBlockingDeque<>();
|
||||
final BuildEventListener buildEventListener = new ClientDispatcher(sendQueue);
|
||||
try (ProjectBuildLogAppender logAppender = new ProjectBuildLogAppender(buildEventListener)) {
|
||||
@@ -558,48 +556,6 @@ public class Server implements AutoCloseable, Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
int getClassOrder(Message m) {
|
||||
switch (m.getType()) {
|
||||
case Message.BUILD_REQUEST:
|
||||
return 0;
|
||||
case Message.BUILD_STARTED:
|
||||
return 1;
|
||||
case Message.PROMPT:
|
||||
case Message.PROMPT_RESPONSE:
|
||||
case Message.DISPLAY:
|
||||
return 2;
|
||||
case Message.PROJECT_STARTED:
|
||||
return 3;
|
||||
case Message.MOJO_STARTED:
|
||||
return 4;
|
||||
case Message.TRANSFER_INITIATED:
|
||||
case Message.TRANSFER_STARTED:
|
||||
return 40;
|
||||
case Message.TRANSFER_PROGRESSED:
|
||||
return 41;
|
||||
case Message.TRANSFER_CORRUPTED:
|
||||
case Message.TRANSFER_SUCCEEDED:
|
||||
case Message.TRANSFER_FAILED:
|
||||
return 42;
|
||||
case Message.PROJECT_LOG_MESSAGE:
|
||||
return 50;
|
||||
case Message.BUILD_LOG_MESSAGE:
|
||||
return 51;
|
||||
case Message.PROJECT_STOPPED:
|
||||
return 95;
|
||||
case Message.BUILD_FINISHED:
|
||||
return 96;
|
||||
case Message.BUILD_EXCEPTION:
|
||||
return 97;
|
||||
case Message.STOP:
|
||||
return 99;
|
||||
case Message.KEEP_ALIVE:
|
||||
return 100;
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected message type " + m.getType() + ": " + m);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateState(DaemonState state) {
|
||||
if (getState() != state) {
|
||||
LOGGER.info("Updating state to: " + state);
|
||||
|
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2021 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.daemon;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mvndaemon.mvnd.common.Message;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class ServerTest {
|
||||
|
||||
@Test
|
||||
void testMessageOrdering() {
|
||||
BlockingQueue<Message> messages = new PriorityBlockingQueue<>(64, Message.getMessageComparator());
|
||||
messages.addAll(Arrays.asList(
|
||||
Message.projectStopped("projectId"),
|
||||
Message.projectStarted("projectId"),
|
||||
Message.log("projectId", "message"))
|
||||
);
|
||||
|
||||
assertEquals(Message.PROJECT_STARTED, messages.remove().getType());
|
||||
assertEquals(Message.PROJECT_LOG_MESSAGE, messages.remove().getType());
|
||||
assertEquals(Message.PROJECT_STOPPED, messages.remove().getType());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user