Skip to content

Commit 173d4f4

Browse files
committed
favor DataView label definition
1 parent 79fbabb commit 173d4f4

6 files changed

Lines changed: 46 additions & 6 deletions

File tree

src/main/java/act/app/CliContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public String command() {
7272
}
7373

7474
public List<String> arguments() {
75-
return parser.;
75+
return parser.arguments();
7676
}
7777

7878
@Override

src/main/java/act/app/CliServer.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class CliServer extends AppServiceBase<CliServer> implements Runnable {
2727
private ConcurrentMap<Integer, CliSession> sessions = new ConcurrentHashMap<Integer, CliSession>();
2828
private int port;
2929
private ServerSocket serverSocket;
30+
private Thread monitorThread;
3031

3132
CliServer(App app) {
3233
super(app);
@@ -67,6 +68,9 @@ public void run() {
6768
}
6869

6970
void stop() {
71+
if (!running()) {
72+
return;
73+
}
7074
running.set(false);
7175
try {
7276
serverSocket.close();
@@ -75,6 +79,10 @@ void stop() {
7579
} finally {
7680
serverSocket = null;
7781
}
82+
if (null != monitorThread) {
83+
monitorThread.interrupt();
84+
monitorThread = null;
85+
}
7886
}
7987

8088
void start() {
@@ -90,6 +98,7 @@ void start() {
9098
executor.submit(new Runnable() {
9199
@Override
92100
public void run() {
101+
monitorThread = Thread.currentThread();
93102
int expiration = app().config().cliSessionExpiration();
94103
while (running()) {
95104
List<CliSession> toBeRemoved = C.newList();
@@ -105,7 +114,12 @@ public void run() {
105114
try {
106115
Thread.sleep(60 * 1000);
107116
} catch (InterruptedException e) {
108-
// ignore
117+
return;
118+
}
119+
try {
120+
app().detectChanges();
121+
} catch (RequestRefreshClassLoader refreshRequest) {
122+
app().refresh();
109123
}
110124
}
111125
}

src/main/java/act/app/CliSession.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class CliSession extends DestroyableBase implements Runnable {
2828
private Socket socket;
2929
private long ts;
3030
private boolean exit;
31+
private Thread runningThread;
3132

3233
CliSession(Socket socket, CliServer server) {
3334
this.socket = $.NPE(socket);
@@ -60,14 +61,16 @@ protected void releaseResources() {
6061

6162
@Override
6263
public void run() {
64+
runningThread = Thread.currentThread();
6365
try {
6466
final BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
6567
final PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
6668

6769
out.println(Banner.banner(Act.VERSION));
70+
String user = username();
6871

6972
while (!exit) {
70-
out.print("act[" + id + "]>");
73+
out.print("act[" + user + "]>");
7174
out.flush();
7275
final String line = reader.readLine();
7376
if (exit) {
@@ -118,9 +121,24 @@ public void run() {
118121
}
119122
}
120123

124+
private String username() {
125+
String user = System.getProperty("user.name");
126+
if (S.blank(user)) {
127+
user = System.getenv("USER");
128+
if (S.blank(user)) {
129+
user = System.getenv("USERNAME");
130+
if (S.blank(user)) {
131+
user = "anonymous";
132+
}
133+
}
134+
}
135+
return user;
136+
}
137+
121138
void stop() {
122139
exit = true;
123140
IO.close(socket);
141+
runningThread.interrupt();
124142
}
125143

126144
}

src/main/java/act/cli/ascii_table/impl/CollectionASCIITableAware.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public CollectionASCIITableAware(List<T> objList, List<String> properties, List<
100100
}
101101

102102
private Object getProperty(Osgl.T2<? extends Osgl.Function<String, Serializable>, ? extends Osgl.Func2<String, Serializable, ?>> evaluatorCache, Class<?> dataClazz, T obj, String property) {
103-
return $.eval(evaluatorCache, obj, property);
103+
return $.getProperty(evaluatorCache, obj, property);
104104
}
105105

106106
private Method getMethod(Class<?> dataClazz, String methodName) {

src/main/java/act/handler/builtin/cli/CliHandlerProxy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ private void onResult(Object result, CliContext context) {
7070
return;
7171
}
7272
DataView.MetaInfo dataView = meta.dataViewInfo();
73+
List<String> outputs = dataView.outputFields();
7374
if (null != dataView) {
74-
List<String> labelList = dataView.outputFields();
7575
List dataList;
7676
if (result instanceof Iterable) {
7777
dataList = C.list((Iterable) result);
7878
} else {
7979
dataList = C.listOf(result);
8080
}
81-
context.printTable(new CollectionASCIITableAware(dataList, labelList, C.list()));
81+
context.printTable(new CollectionASCIITableAware(dataList, dataView.outputFields(), dataView.labels()));
8282
} else {
8383
context.println(result.toString());
8484
}

src/main/java/act/util/DataView.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ public List<String> outputFields() {
104104
return C.list(outputs);
105105
}
106106

107+
public List<String> labels() {
108+
List<String> retList = C.newList();
109+
for (String f : outputs) {
110+
retList.add(label(f));
111+
}
112+
return retList;
113+
}
114+
107115
public Set<String> excludedFields() {
108116
return C.set(excluded);
109117
}

0 commit comments

Comments
 (0)