mirror of
https://github.com/apache/maven-mvnd.git
synced 2026-01-13 07:04:14 +08:00
@@ -63,7 +63,7 @@ public class DaemonCompatibilitySpec {
|
||||
final StringBuilder sb = new StringBuilder("Wanted: ");
|
||||
appendFields(sb);
|
||||
sb.append("\nActual: ");
|
||||
context.appendNonKeyFields(sb).append("uid=").append(context.getUid()).append('\n');
|
||||
context.appendNonKeyFields(sb).append("id=").append(context.getId()).append('\n');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import static org.mvndaemon.mvnd.common.DaemonState.Idle;
|
||||
*/
|
||||
public class DaemonInfo {
|
||||
|
||||
private final String uid;
|
||||
private final String id;
|
||||
private final String javaHome;
|
||||
private final String mvndHome;
|
||||
private final int pid;
|
||||
@@ -37,11 +37,11 @@ public class DaemonInfo {
|
||||
private final long lastIdle;
|
||||
private final long lastBusy;
|
||||
|
||||
public DaemonInfo(String uid, String javaHome, String mavenHome,
|
||||
public DaemonInfo(String id, String javaHome, String mavenHome,
|
||||
int pid, int address,
|
||||
String locale, List<String> options,
|
||||
DaemonState state, long lastIdle, long lastBusy) {
|
||||
this.uid = uid;
|
||||
this.id = id;
|
||||
this.javaHome = javaHome;
|
||||
this.mvndHome = mavenHome;
|
||||
this.pid = pid;
|
||||
@@ -53,8 +53,8 @@ public class DaemonInfo {
|
||||
this.lastBusy = lastBusy;
|
||||
}
|
||||
|
||||
public String getUid() {
|
||||
return uid;
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getJavaHome() {
|
||||
@@ -105,13 +105,13 @@ public class DaemonInfo {
|
||||
li = lastIdle;
|
||||
lb = lastBusy;
|
||||
}
|
||||
return new DaemonInfo(uid, javaHome, mvndHome, pid, address,
|
||||
return new DaemonInfo(id, javaHome, mvndHome, pid, address,
|
||||
locale, options, state, li, lb);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("DaemonInfo{uid=").append(uid);
|
||||
final StringBuilder sb = new StringBuilder("DaemonInfo{id=").append(id);
|
||||
appendNonKeyFields(sb);
|
||||
return sb.append('}').toString();
|
||||
}
|
||||
|
||||
@@ -92,9 +92,9 @@ public class DaemonRegistry implements AutoCloseable {
|
||||
return registryFile;
|
||||
}
|
||||
|
||||
public DaemonInfo get(String uid) {
|
||||
public DaemonInfo get(String daemonId) {
|
||||
read();
|
||||
return infosMap.get(uid);
|
||||
return infosMap.get(daemonId);
|
||||
}
|
||||
|
||||
public List<DaemonInfo> getAll() {
|
||||
@@ -122,13 +122,13 @@ public class DaemonRegistry implements AutoCloseable {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void remove(final String uid) {
|
||||
update(() -> infosMap.remove(uid));
|
||||
public void remove(final String daemonId) {
|
||||
update(() -> infosMap.remove(daemonId));
|
||||
}
|
||||
|
||||
public void markState(final String uid, final DaemonState state) {
|
||||
LOGGER.debug("Marking busy by uid: {}", uid);
|
||||
update(() -> infosMap.computeIfPresent(uid, (id, di) -> di.withState(state)));
|
||||
public void markState(final String daemonId, final DaemonState state) {
|
||||
LOGGER.debug("Marking busy by id: {}", daemonId);
|
||||
update(() -> infosMap.computeIfPresent(daemonId, (id, di) -> di.withState(state)));
|
||||
}
|
||||
|
||||
public void storeStopEvent(final DaemonStopEvent stopEvent) {
|
||||
@@ -148,7 +148,7 @@ public class DaemonRegistry implements AutoCloseable {
|
||||
|
||||
public void store(final DaemonInfo info) {
|
||||
LOGGER.debug("Storing daemon {}", info);
|
||||
update(() -> infosMap.put(info.getUid(), info));
|
||||
update(() -> infosMap.put(info.getId(), info));
|
||||
}
|
||||
|
||||
public static int getProcessId() {
|
||||
@@ -176,7 +176,7 @@ public class DaemonRegistry implements AutoCloseable {
|
||||
infosMap.clear();
|
||||
int nb = buffer.getInt();
|
||||
for (int i = 0; i < nb; i++) {
|
||||
String uid = readString();
|
||||
String daemonId = readString();
|
||||
String javaHome = readString();
|
||||
String mavenHome = readString();
|
||||
int pid = buffer.getInt();
|
||||
@@ -190,19 +190,19 @@ public class DaemonRegistry implements AutoCloseable {
|
||||
DaemonState state = DaemonState.values()[buffer.get()];
|
||||
long lastIdle = buffer.getLong();
|
||||
long lastBusy = buffer.getLong();
|
||||
DaemonInfo di = new DaemonInfo(uid, javaHome, mavenHome, pid, address, locale, opts, state,
|
||||
DaemonInfo di = new DaemonInfo(daemonId, javaHome, mavenHome, pid, address, locale, opts, state,
|
||||
lastIdle, lastBusy);
|
||||
infosMap.putIfAbsent(di.getUid(), di);
|
||||
infosMap.putIfAbsent(di.getId(), di);
|
||||
}
|
||||
stopEvents.clear();
|
||||
nb = buffer.getInt();
|
||||
for (int i = 0; i < nb; i++) {
|
||||
String uid = readString();
|
||||
String daemonId = readString();
|
||||
long date = buffer.getLong();
|
||||
int ord = buffer.get();
|
||||
DaemonExpirationStatus des = ord >= 0 ? DaemonExpirationStatus.values()[ord] : null;
|
||||
String reason = readString();
|
||||
DaemonStopEvent se = new DaemonStopEvent(uid, date, des, reason);
|
||||
DaemonStopEvent se = new DaemonStopEvent(daemonId, date, des, reason);
|
||||
stopEvents.add(se);
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ public class DaemonRegistry implements AutoCloseable {
|
||||
BufferCaster.cast(buffer).position((int) 0);
|
||||
buffer.putInt(infosMap.size());
|
||||
for (DaemonInfo di : infosMap.values()) {
|
||||
writeString(di.getUid());
|
||||
writeString(di.getId());
|
||||
writeString(di.getJavaHome());
|
||||
writeString(di.getMvndHome());
|
||||
buffer.putInt(di.getPid());
|
||||
@@ -227,7 +227,7 @@ public class DaemonRegistry implements AutoCloseable {
|
||||
}
|
||||
buffer.putInt(stopEvents.size());
|
||||
for (DaemonStopEvent dse : stopEvents) {
|
||||
writeString(dse.getUid());
|
||||
writeString(dse.getDaemonId());
|
||||
buffer.putLong(dse.getTimestamp());
|
||||
buffer.put((byte) (dse.getStatus() == null ? -1 : dse.getStatus().ordinal()));
|
||||
writeString(dse.getReason());
|
||||
|
||||
@@ -29,20 +29,20 @@ import java.util.Objects;
|
||||
*/
|
||||
public class DaemonStopEvent implements Serializable {
|
||||
|
||||
private final String uid;
|
||||
private final String daemonId;
|
||||
private final long timestamp;
|
||||
private final DaemonExpirationStatus status;
|
||||
private final String reason;
|
||||
|
||||
public DaemonStopEvent(String uid, long timestamp, DaemonExpirationStatus status, String reason) {
|
||||
this.uid = uid;
|
||||
public DaemonStopEvent(String daemonId, long timestamp, DaemonExpirationStatus status, String reason) {
|
||||
this.daemonId = daemonId;
|
||||
this.timestamp = timestamp;
|
||||
this.status = status;
|
||||
this.reason = reason != null ? reason : "";
|
||||
}
|
||||
|
||||
public String getUid() {
|
||||
return uid;
|
||||
public String getDaemonId() {
|
||||
return daemonId;
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
@@ -64,7 +64,7 @@ public class DaemonStopEvent implements Serializable {
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
DaemonStopEvent that = (DaemonStopEvent) o;
|
||||
return Objects.equals(uid, that.uid)
|
||||
return Objects.equals(daemonId, that.daemonId)
|
||||
&& timestamp == that.timestamp
|
||||
&& status == that.status
|
||||
&& Objects.equals(reason, that.reason);
|
||||
@@ -72,13 +72,13 @@ public class DaemonStopEvent implements Serializable {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(timestamp, uid, status, reason);
|
||||
return Objects.hash(timestamp, daemonId, status, reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DaemonStopEvent{"
|
||||
+ "uid=" + uid
|
||||
+ "daemonId=" + daemonId
|
||||
+ ", timestamp=" + DateFormat.getDateTimeInstance().format(new Date(timestamp))
|
||||
+ ", status=" + status
|
||||
+ ", reason=" + reason
|
||||
|
||||
@@ -185,7 +185,7 @@ public enum Environment {
|
||||
/**
|
||||
* An ID for a newly started daemon
|
||||
*/
|
||||
MVND_UID("mvnd.uid", null, null, OptionType.STRING, Flags.INTERNAL),
|
||||
MVND_ID("mvnd.id", null, null, OptionType.STRING, Flags.INTERNAL),
|
||||
/**
|
||||
* Internal option to specify the maven extension classpath
|
||||
*/
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.mvndaemon.mvnd.common.Message;
|
||||
*/
|
||||
public interface ClientOutput extends AutoCloseable {
|
||||
|
||||
void setDaemonId(String uid);
|
||||
void setDaemonId(String daemonId);
|
||||
|
||||
void setDaemonDispatch(Consumer<Message> sink);
|
||||
|
||||
|
||||
@@ -609,6 +609,13 @@ public class TerminalOutput implements ClientOutput {
|
||||
asb.append(name);
|
||||
asb.style(AttributedStyle.DEFAULT);
|
||||
|
||||
/* Daemon ID */
|
||||
asb
|
||||
.append(" daemon: ")
|
||||
.style(AttributedStyle.BOLD)
|
||||
.append(daemonId)
|
||||
.style(AttributedStyle.DEFAULT);
|
||||
|
||||
/* Threads */
|
||||
asb
|
||||
.append(" threads used/hidden/max: ")
|
||||
@@ -636,13 +643,6 @@ public class TerminalOutput implements ClientOutput {
|
||||
.append('%')
|
||||
.style(AttributedStyle.DEFAULT);
|
||||
|
||||
/* DaemonId */
|
||||
asb
|
||||
.append(" daemon: ")
|
||||
.style(AttributedStyle.BOLD)
|
||||
.append(daemonId)
|
||||
.style(AttributedStyle.DEFAULT);
|
||||
|
||||
} else if (buildStatus != null) {
|
||||
asb
|
||||
.style(AttributedStyle.BOLD)
|
||||
|
||||
@@ -40,7 +40,7 @@ public class DaemonRegistryTest {
|
||||
|
||||
byte[] token = new byte[16];
|
||||
new Random().nextBytes(token);
|
||||
reg1.store(new DaemonInfo("the-uid", "/java/home/",
|
||||
reg1.store(new DaemonInfo("12345678", "/java/home/",
|
||||
"/data/reg/", 0x12345678, 7502,
|
||||
Locale.getDefault().toLanguageTag(), Arrays.asList("-Xmx"),
|
||||
DaemonState.Idle, System.currentTimeMillis(), System.currentTimeMillis()));
|
||||
|
||||
Reference in New Issue
Block a user