Skip to content

Commit 4bace95

Browse files
committed
Working channelName in the CLI, client UI not updating
Signed-off-by: Nico Piel <[email protected]>
1 parent 98dde20 commit 4bace95

File tree

7 files changed

+79
-11
lines changed

7 files changed

+79
-11
lines changed

client/src/com/mirth/connect/plugins/serverlog/ServerLogPanel.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
public class ServerLogPanel extends javax.swing.JPanel {
4040

4141
private static final String ID_COLUMN_HEADER = "Id";
42+
private static final String CHANNEL_COLUMN_HEADER = "Channel";
4243
private static final String LOG_INFO_COLUMN_HEADER = "Log Information";
4344
private JPopupMenu rightclickPopup;
4445
private static final int PAUSED = 0;
@@ -112,7 +113,7 @@ public void mouseClicked(java.awt.event.MouseEvent evt) {
112113
if (evt.getClickCount() >= 2) {
113114
// synchronizing this to prevent ArrayIndexOutOfBoundsException since the server log table is constantly being redrawn.
114115
synchronized (this) {
115-
new ViewServerLogContentDialog(parent, String.valueOf(logTable.getModel().getValueAt(logTable.convertRowIndexToModel(logTable.getSelectedRow()), 1)));
116+
new ViewServerLogContentDialog(parent, String.valueOf(logTable.getModel().getValueAt(logTable.convertRowIndexToModel(logTable.getSelectedRow()), 2)));
116117
}
117118
}
118119
}
@@ -185,24 +186,24 @@ public synchronized void updateTable(LinkedList<ServerLogItem> serverLogs) {
185186

186187
for (ServerLogItem item : serverLogs) {
187188
if (serverId == null || serverId.equals(item.getServerId())) {
188-
dataList.add(new Object[] { item.getId(), item });
189+
dataList.add(new Object[] { item.getId(), item.getChannelName(), item });
189190
}
190191
}
191192

192193
tableData = dataList.toArray(new Object[dataList.size()][]);
193194
} else {
194-
tableData = new Object[0][2];
195+
tableData = new Object[0][3];
195196
}
196197

197198
if (logTable != null) {
198199
RefreshTableModel model = (RefreshTableModel) logTable.getModel();
199200
model.refreshDataVector(tableData);
200201
} else {
201202
logTable = new MirthTable();
202-
logTable.setModel(new RefreshTableModel(tableData, new String[] { ID_COLUMN_HEADER,
203+
logTable.setModel(new RefreshTableModel(tableData, new String[] { ID_COLUMN_HEADER, CHANNEL_COLUMN_HEADER,
203204
LOG_INFO_COLUMN_HEADER }) {
204205

205-
boolean[] canEdit = new boolean[] { false, false };
206+
boolean[] canEdit = new boolean[] { false, false, false };
206207

207208
public boolean isCellEditable(int rowIndex, int columnIndex) {
208209
return canEdit[columnIndex];

donkey/src/main/java/com/mirth/connect/donkey/server/channel/Channel.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.apache.commons.lang3.exception.ExceptionUtils;
4141
import org.apache.logging.log4j.LogManager;
4242
import org.apache.logging.log4j.Logger;
43+
import org.apache.logging.log4j.ThreadContext;
4344

4445
import com.mirth.connect.donkey.model.DonkeyException;
4546
import com.mirth.connect.donkey.model.channel.DebugOptions;
@@ -1271,6 +1272,9 @@ protected DispatchResult dispatchRawMessage(RawMessage rawMessage, boolean batch
12711272
} else {
12721273
currentThread.setName("Channel Dispatch Thread on " + name + " (" + channelId + ") < " + originalThreadName);
12731274
}
1275+
1276+
ThreadContext.put("channelId", channelId);
1277+
ThreadContext.put("channelName", name);
12741278

12751279
DonkeyDao dao = null;
12761280
boolean commitSuccess = false;
@@ -1386,6 +1390,8 @@ protected DispatchResult dispatchRawMessage(RawMessage rawMessage, boolean batch
13861390
dispatchThreads.remove(currentThread);
13871391
}
13881392
currentThread.setName(originalThreadName);
1393+
ThreadContext.remove("channelId");
1394+
ThreadContext.remove("channelName");
13891395
}
13901396
}
13911397

@@ -1934,11 +1940,16 @@ public void processUnfinishedMessages() throws Exception {
19341940
@Override
19351941
public void run() {
19361942
try {
1943+
ThreadContext.put("channelId", channelId);
1944+
ThreadContext.put("channelName", name);
19371945
do {
19381946
processSourceQueue(Constants.SOURCE_QUEUE_POLL_TIMEOUT_MILLIS);
19391947
} while (isActive() && !stopSourceQueue);
19401948
} catch (InterruptedException e) {
19411949
Thread.currentThread().interrupt();
1950+
} finally {
1951+
ThreadContext.remove("channelId");
1952+
ThreadContext.remove("channelName");
19421953
}
19431954
}
19441955

donkey/src/main/java/com/mirth/connect/donkey/server/channel/DestinationChain.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.apache.commons.lang3.StringUtils;
1919
import org.apache.logging.log4j.LogManager;
2020
import org.apache.logging.log4j.Logger;
21+
import org.apache.logging.log4j.ThreadContext;
2122

2223
import com.mirth.connect.donkey.model.message.ConnectorMessage;
2324
import com.mirth.connect.donkey.model.message.ContentType;
@@ -61,8 +62,20 @@ public List<ConnectorMessage> call() throws InterruptedException {
6162
String originalThreadName = Thread.currentThread().getName();
6263
try {
6364
Thread.currentThread().setName(name + " < " + originalThreadName);
65+
String channelId = chainProvider.getChannelId();
66+
String channelName = null;
67+
if (!chainProvider.getDestinationConnectors().isEmpty()) {
68+
channelName = chainProvider.getDestinationConnectors().values().iterator().next().getChannel().getName();
69+
}
70+
71+
ThreadContext.put("channelId", channelId);
72+
if (channelName != null) {
73+
ThreadContext.put("channelName", channelName);
74+
}
6475
return doCall();
6576
} finally {
77+
ThreadContext.remove("channelId");
78+
ThreadContext.remove("channelName");
6679
Thread.currentThread().setName(originalThreadName);
6780
}
6881
}
@@ -210,4 +223,4 @@ private List<ConnectorMessage> doCall() throws InterruptedException {
210223

211224
return messages;
212225
}
213-
}
226+
}

donkey/src/main/java/com/mirth/connect/donkey/server/channel/DestinationConnector.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.commons.lang3.exception.ExceptionUtils;
2525
import org.apache.logging.log4j.LogManager;
2626
import org.apache.logging.log4j.Logger;
27+
import org.apache.logging.log4j.ThreadContext;
2728

2829
import com.mirth.connect.donkey.model.DonkeyException;
2930
import com.mirth.connect.donkey.model.channel.ConnectorProperties;
@@ -613,6 +614,10 @@ public void processPendingConnectorMessage(DonkeyDao dao, ConnectorMessage messa
613614

614615
@Override
615616
public void run() {
617+
// Add channel info to ThreadContext
618+
ThreadContext.put("channelId", getChannelId());
619+
ThreadContext.put("channelName", channel.getName());
620+
616621
DonkeyDao dao = null;
617622
boolean commitSuccess = false;
618623
Serializer serializer = channel.getSerializer();
@@ -892,6 +897,9 @@ public void run() {
892897
}
893898
}
894899
} while ((getCurrentState() == DeployedState.STARTED || getCurrentState() == DeployedState.STARTING) && !stopQueue.get());
900+
901+
ThreadContext.remove("channelId");
902+
ThreadContext.remove("channelName");
895903
}
896904

897905
private Response handleSend(ConnectorProperties connectorProperties, ConnectorMessage message) throws InterruptedException {

server/src/com/mirth/connect/plugins/serverlog/ArrayAppender.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ public void append(LogEvent logEvent) {
3636
return;
3737
}
3838

39+
String channelId = null;
40+
String channelName = null;
41+
if (logEvent.getContextMap() != null) {
42+
if (logEvent.getContextMap().containsKey("channelId")) {
43+
channelId = logEvent.getContextMap().get("channelId");
44+
}
45+
if (logEvent.getContextMap().containsKey("channelName")) {
46+
channelName = logEvent.getContextMap().get("channelName");
47+
}
48+
}
49+
3950
String level = String.valueOf(logEvent.getLevel());
4051
Date date = new Date(logEvent.getTimeMillis());
4152
String threadName = logEvent.getThreadName();
@@ -61,6 +72,6 @@ public void append(LogEvent logEvent) {
6172
throwableInformation = logText.toString();
6273
}
6374

64-
serverLogProvider.newServerLogReceived(level, date, threadName, category, lineNumber, message, throwableInformation);
75+
serverLogProvider.newServerLogReceived(channelId, channelName, level, date, threadName, category, lineNumber, message, throwableInformation);
6576
}
6677
}

server/src/com/mirth/connect/plugins/serverlog/ServerLogItem.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,31 @@ public class ServerLogItem implements Serializable {
2121

2222
private String serverId;
2323
private Long id;
24+
private String channelId;
2425
private String level;
2526
private Date date;
2627
private String threadName;
2728
private String category;
2829
private String lineNumber;
2930
private String message;
3031
private String throwableInformation;
32+
private String channelName;
3133

3234
public ServerLogItem() {}
3335

3436
public ServerLogItem(String message) {
35-
this(null, null, null, null, null, null, null, message, null);
37+
this(null, null, null, null, null, null, null, null, null, message, null);
3638
}
37-
39+
3840
public ServerLogItem(String serverId, Long id, String level, Date date, String threadName, String category, String lineNumber, String message, String throwableInformation) {
41+
this(serverId, id, null, null, level, date, threadName, category, lineNumber, message, throwableInformation);
42+
}
43+
44+
public ServerLogItem(String serverId, Long id, String channelId, String channelName, String level, Date date, String threadName, String category, String lineNumber, String message, String throwableInformation) {
3945
this.serverId = serverId;
4046
this.id = id;
47+
this.channelId = channelId;
48+
this.channelName = channelName;
4149
this.level = level;
4250
this.date = date;
4351
this.threadName = threadName;
@@ -62,6 +70,14 @@ public Long getId() {
6270
public void setId(Long id) {
6371
this.id = id;
6472
}
73+
74+
public String getChannelId() {
75+
return channelId;
76+
}
77+
78+
public void setChannelId(String channelId) {
79+
this.channelId = channelId;
80+
}
6581

6682
public String getLevel() {
6783
return level;
@@ -118,6 +134,14 @@ public String getThrowableInformation() {
118134
public void setThrowableInformation(String throwableInformation) {
119135
this.throwableInformation = throwableInformation;
120136
}
137+
138+
public String getChannelName() {
139+
return channelName;
140+
}
141+
142+
public void setChannelName(String channelName) {
143+
this.channelName = channelName;
144+
}
121145

122146
@Override
123147
public String toString() {

server/src/com/mirth/connect/plugins/serverlog/ServerLogProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ public void init(Properties properties) {
5555
initialize();
5656
}
5757

58-
public synchronized void newServerLogReceived(String level, Date date, String threadName, String category, String lineNumber, String message, String throwableInformation) {
58+
public synchronized void newServerLogReceived(String channelId, String channelName, String level, Date date, String threadName, String category, String lineNumber, String message, String throwableInformation) {
5959
if (logController != null) {
60-
logController.addLogItem(new ServerLogItem(serverId, logId, level, date, threadName, category, lineNumber, message, throwableInformation));
60+
logController.addLogItem(new ServerLogItem(serverId, logId, channelId, channelName, level, date, threadName, category, lineNumber, message, throwableInformation));
6161
logId++;
6262
}
6363
}

0 commit comments

Comments
 (0)