回答編集履歴

1

ログ表示関係修正

2021/11/21 05:13

投稿

jimbe
jimbe

スコア13209

test CHANGED
@@ -12,6 +12,10 @@
12
12
 
13
13
 
14
14
 
15
+ import java.time.LocalDateTime;
16
+
17
+ import java.time.format.DateTimeFormatter;
18
+
15
19
  import java.util.HashMap;
16
20
 
17
21
  import java.util.Map;
@@ -140,13 +144,17 @@
140
144
 
141
145
  }
142
146
 
147
+ public String getTextWithCode() {
148
+
149
+ return (code<=0?"":code+" ")+text;
150
+
151
+ }
152
+
143
153
  @Override
144
154
 
145
155
  public String toString() {
146
156
 
147
- return (code<=0?"":code+" ")+text;
148
-
149
- //return "src='"+src+"', dst='"+dst+"', code="+code+", text='"+text+"'";
157
+ return "src='"+src+"', dst='"+dst+"', code="+code+", text='"+text+"'";
150
158
 
151
159
  }
152
160
 
@@ -232,9 +240,9 @@
232
240
 
233
241
  public void send(Message msg) throws InterruptedException {
234
242
 
235
- if(!msg.src.equals(name) && !msg.dst.equals(name)) {
243
+ if(!msg.src.equals(name) && !msg.dst.equals(name)) { //Proxy[から|へ]は表示しない
236
-
244
+
237
- System.out.println(msg.src + " send: " + msg);
245
+ printLog(msg.src + " send: " + msg.getTextWithCode());
238
246
 
239
247
  }
240
248
 
@@ -244,9 +252,23 @@
244
252
 
245
253
 
246
254
 
247
- public Message recv(String src) throws InterruptedException {
255
+ public Message recv(String name) throws InterruptedException {
248
-
256
+
249
- return getQueue(src).readMessage();
257
+ Message msg = getQueue(name).readMessage();
258
+
259
+ printLog(name + " recv: " + msg.getTextWithCode());
260
+
261
+ return msg;
262
+
263
+ }
264
+
265
+
266
+
267
+ private void printLog(String log) {
268
+
269
+ String time = DateTimeFormatter.ofPattern("HH:mm:ss ").format(LocalDateTime.now());
270
+
271
+ System.out.println(time + log);
250
272
 
251
273
  }
252
274
 
@@ -280,15 +302,15 @@
280
302
 
281
303
  Thread.sleep(1000);
282
304
 
283
- System.out.println(name + " recv: " + proxy.recv(name));
305
+ proxy.recv(name); //Trying?
284
306
 
285
307
  Thread.sleep(1000);
286
308
 
287
- System.out.println(name + " recv: " + proxy.recv(name));
309
+ proxy.recv(name); //Ringing?
288
310
 
289
311
  Thread.sleep(5000);
290
312
 
291
- System.out.println(name + " recv: " + proxy.recv(name));
313
+ proxy.recv(name); //OK?
292
314
 
293
315
 
294
316
 
@@ -330,17 +352,15 @@
330
352
 
331
353
  Thread.sleep(1000);
332
354
 
333
- Message recv = proxy.recv(name);
355
+ Message recvMsg = proxy.recv(name); //INVITE?
334
-
335
- System.out.println(name + " recv: " + recv);
336
356
 
337
357
  Thread.sleep(1000);
338
358
 
339
- proxy.send(new Message(name, recv.src, 180, "Ringing"));
359
+ proxy.send(new Message(name, recvMsg.src, 180, "Ringing"));
340
360
 
341
361
  Thread.sleep(3000);
342
362
 
343
- proxy.send(new Message(name, recv.src, 200, "OK"));
363
+ proxy.send(new Message(name, recvMsg.src, 200, "OK"));
344
364
 
345
365
 
346
366
 
@@ -388,18 +408,18 @@
388
408
 
389
409
  ```plain
390
410
 
391
- Aさん send: INVITE
411
+ 14:11:47 Aさん send: INVITE
392
-
412
+
393
- Bさん recv: INVITE
413
+ 14:11:48 Bさん recv: INVITE
394
-
414
+
395
- Aさん recv: 100 Trying
415
+ 14:11:48 Aさん recv: 100 Trying
396
-
416
+
397
- Bさん send: 180 Ringing
417
+ 14:11:49 Bさん send: 180 Ringing
398
-
418
+
399
- Aさん recv: 180 Ringing
419
+ 14:11:49 Aさん recv: 180 Ringing
400
-
420
+
401
- Bさん send: 200 OK
421
+ 14:11:52 Bさん send: 200 OK
402
-
422
+
403
- Aさん recv: 200 OK
423
+ 14:11:54 Aさん recv: 200 OK
404
424
 
405
425
  ```