Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,18 @@ public Statistics getTotalStatistics() {
}

public Statistics getStatisticsFromStorage(String serverId) {
return getStatisticsFromStorage(serverId, null);
}

/**
* The stored current statistics of the given channels, or of every channel when
* {@code channelIds} is null or empty.
*/
public Statistics getStatisticsFromStorage(String serverId, Set<String> channelIds) {
DonkeyDao dao = donkey.getReadOnlyDaoFactory().getDao();

try {
return dao.getChannelStatistics(serverId);
return dao.getChannelStatistics(serverId, channelIds);
} finally {
dao.close();
}
Expand All @@ -106,10 +114,15 @@ public List<Ports> getPortsInUse() {
}

public Statistics getTotalStatisticsFromStorage(String serverId) {
return getTotalStatisticsFromStorage(serverId, null);
}

/** The lifetime counterpart of {@link #getStatisticsFromStorage(String, Set)}. */
public Statistics getTotalStatisticsFromStorage(String serverId, Set<String> channelIds) {
DonkeyDao dao = donkey.getReadOnlyDaoFactory().getDao();

try {
return dao.getChannelTotalStatistics(serverId);
return dao.getChannelTotalStatistics(serverId, channelIds);
} finally {
dao.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,13 @@ public interface DonkeyDao {

public Statistics getChannelStatistics(String serverId);

/** The current statistics of the given channels only. A null or empty set means every channel. */
public Statistics getChannelStatistics(String serverId, Set<String> channelIds);

public Statistics getChannelTotalStatistics(String serverId);

/** The lifetime counterpart of {@link #getChannelStatistics(String, Set)}. */
public Statistics getChannelTotalStatistics(String serverId, Set<String> channelIds);

public List<Ports> getPortsInUse();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,17 @@ public Statistics getChannelStatistics(String serverId) {
}
}

@Override
public Statistics getChannelStatistics(String serverId, Set<String> channelIds) {
DonkeyDao dao = getDelegateDao();

try {
return dao.getChannelStatistics(serverId, channelIds);
} finally {
dao.close();
}
}

@Override
public Statistics getChannelTotalStatistics(String serverId) {
DonkeyDao dao = getDelegateDao();
Expand All @@ -589,6 +600,17 @@ public Statistics getChannelTotalStatistics(String serverId) {
dao.close();
}
}

@Override
public Statistics getChannelTotalStatistics(String serverId, Set<String> channelIds) {
DonkeyDao dao = getDelegateDao();

try {
return dao.getChannelTotalStatistics(serverId, channelIds);
} finally {
dao.close();
}
}

@Override
public List<Ports> getPortsInUse() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2354,21 +2354,35 @@ public void resetAllStatistics(String channelId) {

@Override
public Statistics getChannelStatistics(String serverId) {
return getChannelStatistics(serverId, false);
return getChannelStatistics(serverId, null, false);
}

@Override
public Statistics getChannelStatistics(String serverId, Set<String> channelIds) {
return getChannelStatistics(serverId, channelIds, false);
}

@Override
public Statistics getChannelTotalStatistics(String serverId) {
return getChannelStatistics(serverId, true);
return getChannelStatistics(serverId, null, true);
}

private Statistics getChannelStatistics(String serverId, boolean total) {
Map<String, Long> channelIds = getLocalChannelIds();
@Override
public Statistics getChannelTotalStatistics(String serverId, Set<String> channelIds) {
return getChannelStatistics(serverId, channelIds, true);
}

private Statistics getChannelStatistics(String serverId, Set<String> requestedChannelIds, boolean total) {
Map<String, Long> localChannelIds = getLocalChannelIds();
String queryId = (total) ? "getChannelTotalStatistics" : "getChannelStatistics";
Statistics statistics = new Statistics(!total);
ResultSet resultSet = null;

for (String channelId : channelIds.keySet()) {
for (String channelId : localChannelIds.keySet()) {
if (CollectionUtils.isNotEmpty(requestedChannelIds) && !requestedChannelIds.contains(channelId)) {
continue;
}

PreparedStatement statement = null;
try {
statement = prepareStatement(queryId, channelId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,21 @@ public Statistics getChannelStatistics(String serverId) {
return new Statistics(false);
}

@Override
public Statistics getChannelStatistics(String serverId, Set<String> channelIds) {
return new Statistics(false);
}

@Override
public Statistics getChannelTotalStatistics(String serverId) {
return new Statistics(false);
}

@Override
public Statistics getChannelTotalStatistics(String serverId, Set<String> channelIds) {
return new Statistics(false);
}

@Override
public List<ConnectorMessage> getConnectorMessages(String channelId, long messageId, Set<Integer> metaDataIds, boolean includeContent) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,17 @@ public Statistics getChannelStatistics(String serverId) {
}
}

@Override
public Statistics getChannelStatistics(String serverId, Set<String> channelIds) {
long startTime = System.currentTimeMillis();

try {
return dao.getChannelStatistics(serverId, channelIds);
} finally {
timer.log("getChannelStatistics", System.currentTimeMillis() - startTime);
}
}

@Override
public Statistics getChannelTotalStatistics(String serverId) {
long startTime = System.currentTimeMillis();
Expand All @@ -672,6 +683,17 @@ public Statistics getChannelTotalStatistics(String serverId) {
timer.log("getChannelTotalStatistics", System.currentTimeMillis() - startTime);
}
}

@Override
public Statistics getChannelTotalStatistics(String serverId, Set<String> channelIds) {
long startTime = System.currentTimeMillis();

try {
return dao.getChannelTotalStatistics(serverId, channelIds);
} finally {
timer.log("getChannelTotalStatistics", System.currentTimeMillis() - startTime);
}
}

@Override
public List<Ports> getPortsInUse() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ public ChannelStatistics getStatistics(String channelId) {

if (CollectionUtils.isNotEmpty(channelStatisticsList)) {
channelStatistics = channelStatisticsList.get(0);

// Paranoia: verify that the channel ID matches the requested one
if (!channelId.equals(channelStatistics.getChannelId())) {
throw new IllegalStateException("Channel ID mismatch: expected " + channelId + " but got " + channelStatistics.getChannelId());
}
} else {
channelStatistics = new ChannelStatistics();
channelStatistics.setChannelId(channelId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ public static ChannelController getInstance() {

public abstract Statistics getStatisticsFromStorage(String serverId);

public abstract Statistics getStatisticsFromStorage(String serverId, Set<String> channelIds);

public abstract Statistics getTotalStatisticsFromStorage(String serverId);

public abstract Statistics getTotalStatisticsFromStorage(String serverId, Set<String> channelIds);

public abstract int getConnectorMessageCount(String channelId, String serverId, int metaDataId, Status status);

public abstract void resetStatistics(Map<String, List<Integer>> channelConnectorMap, Set<Status> statuses);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -732,11 +732,21 @@ public Statistics getStatisticsFromStorage(String serverId) {
return com.mirth.connect.donkey.server.controllers.ChannelController.getInstance().getStatisticsFromStorage(serverId);
}

@Override
public Statistics getStatisticsFromStorage(String serverId, Set<String> channelIds) {
return com.mirth.connect.donkey.server.controllers.ChannelController.getInstance().getStatisticsFromStorage(serverId, channelIds);
}

@Override
public Statistics getTotalStatisticsFromStorage(String serverId) {
return com.mirth.connect.donkey.server.controllers.ChannelController.getInstance().getTotalStatisticsFromStorage(serverId);
}

@Override
public Statistics getTotalStatisticsFromStorage(String serverId, Set<String> channelIds) {
return com.mirth.connect.donkey.server.controllers.ChannelController.getInstance().getTotalStatisticsFromStorage(serverId, channelIds);
}

@Override
public int getConnectorMessageCount(String channelId, String serverId, int metaDataId, Status status) {
return com.mirth.connect.donkey.server.controllers.ChannelController.getInstance().getConnectorMessageCount(channelId, serverId, metaDataId, status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,22 +739,27 @@ private Map<String, Channel> getDashboardChannels(Set<String> channelIds) {

synchronized (deployingChannels) {
for (Channel channel : deployingChannels) {
if (!channels.containsKey(channel.getChannelId())) {
if (requested(channelIds, channel) && !channels.containsKey(channel.getChannelId())) {
channels.put(channel.getChannelId(), channel);
}
}
}

synchronized (undeployingChannels) {
for (Channel channel : undeployingChannels) {
if (!channels.containsKey(channel.getChannelId())) {
if (requested(channelIds, channel) && !channels.containsKey(channel.getChannelId())) {
channels.put(channel.getChannelId(), channel);
}
}
}
return channels;
}

/** Whether one channel is in the set a caller asked about; an empty set means all of them. */
private boolean requested(Set<String> channelIds, Channel channel) {
return CollectionUtils.isEmpty(channelIds) || channelIds.contains(channel.getChannelId());
}

@Override
public List<DashboardStatus> getChannelStatusList(Set<String> channelIds, boolean includeUndeployed) {
List<DashboardStatus> statusList = new ArrayList<>();
Expand All @@ -778,8 +783,16 @@ public List<DashboardStatus> getChannelStatusList(Set<String> channelIds, boolea

private List<DashboardStatus> getUndeployedDashboardStatuses(Collection<com.mirth.connect.model.Channel> channelModels, Map<String, ChannelMetadata> metadataMap) {
List<DashboardStatus> statuses = new ArrayList<DashboardStatus>();
Statistics stats = channelController.getStatisticsFromStorage(configurationController.getServerId());
Statistics lifetimeStats = channelController.getTotalStatisticsFromStorage(configurationController.getServerId());
if (channelModels.isEmpty()) {
return statuses;
}

Set<String> channelIds = new HashSet<String>();
for (com.mirth.connect.model.Channel channelModel : channelModels) {
channelIds.add(channelModel.getId());
}
Statistics stats = channelController.getStatisticsFromStorage(configurationController.getServerId(), channelIds);
Statistics lifetimeStats = channelController.getTotalStatisticsFromStorage(configurationController.getServerId(), channelIds);
String serverId = configurationController.getServerId();

for (com.mirth.connect.model.Channel channelModel : channelModels) {
Expand Down Expand Up @@ -1043,7 +1056,15 @@ private List<ChannelStatistics> getDashboardChannelStatistics(Collection<Channel

private List<ChannelStatistics> getUndeployedChannelStatistics(Collection<com.mirth.connect.model.Channel> channelModels, Set<Integer> includeMetaDataIds, Set<Integer> excludeMetaDataIds) {
List<ChannelStatistics> statisticsList = new ArrayList<ChannelStatistics>();
Statistics stats = channelController.getStatisticsFromStorage(configurationController.getServerId());
if (channelModels.isEmpty()) {
return statisticsList;
}

Set<String> channelIds = new HashSet<String>();
for (com.mirth.connect.model.Channel channelModel : channelModels) {
channelIds.add(channelModel.getId());
}
Statistics stats = channelController.getStatisticsFromStorage(configurationController.getServerId(), channelIds);

String serverId = configurationController.getServerId();

Expand Down
Loading