|
1 | 1 | package com.navercorp.pinpoint.web.vo.tree;
|
2 | 2 |
|
3 | 3 | import com.navercorp.pinpoint.web.vo.agent.AgentAndStatus;
|
| 4 | +import com.navercorp.pinpoint.web.vo.agent.AgentInfo; |
4 | 5 | import com.navercorp.pinpoint.web.vo.agent.AgentStatusFilter;
|
| 6 | +import com.navercorp.pinpoint.web.vo.agent.AgentStatus; |
| 7 | +import com.navercorp.pinpoint.web.vo.agent.DetailedAgentAndStatus; |
| 8 | +import com.navercorp.pinpoint.web.vo.agent.DetailedAgentInfo; |
5 | 9 |
|
6 | 10 | import java.util.ArrayList;
|
7 | 11 | import java.util.Collection;
|
8 | 12 | import java.util.Comparator;
|
9 | 13 | import java.util.List;
|
10 | 14 | import java.util.Objects;
|
| 15 | +import java.util.function.Function; |
| 16 | +import java.util.function.Predicate; |
11 | 17 |
|
12 |
| -public class AgentsMapByApplication { |
| 18 | +public class AgentsMapByApplication<T> { |
13 | 19 |
|
14 |
| - private final InstancesListMap<AgentAndStatus> instancesListMap; |
| 20 | + private final InstancesListMap<T> instancesListMap; |
15 | 21 |
|
16 |
| - private AgentsMapByApplication(InstancesListMap<AgentAndStatus> instancesListMap) { |
| 22 | + private AgentsMapByApplication(InstancesListMap<T> instancesListMap) { |
17 | 23 | this.instancesListMap = Objects.requireNonNull(instancesListMap, "agentsListMap");
|
18 | 24 | }
|
19 | 25 |
|
20 |
| - public List<InstancesList<AgentAndStatus>> getAgentsListsList() { |
| 26 | + public List<InstancesList<T>> getAgentsListsList() { |
21 | 27 | return new ArrayList<>(instancesListMap.getListMap());
|
22 | 28 | }
|
23 | 29 |
|
24 |
| - public static AgentsMapByApplication newAgentsMapByApplication(AgentStatusFilter filter, |
25 |
| - Collection<AgentAndStatus> agentCollection) { |
| 30 | + public static AgentsMapByApplication<AgentAndStatus> newAgentAndStatusMap( |
| 31 | + AgentStatusFilter filter, |
| 32 | + Collection<AgentAndStatus> agentAndStatuses |
| 33 | + ) { |
| 34 | + return AgentsMapByApplication.newAgentsMapByApplication( |
| 35 | + filter, |
| 36 | + agentAndStatuses, |
| 37 | + AgentAndStatus::getAgentInfo, |
| 38 | + AgentAndStatus::getStatus, |
| 39 | + Function.identity() |
| 40 | + ); |
| 41 | + } |
| 42 | + |
| 43 | + public static AgentsMapByApplication<DetailedAgentInfo> newDetailedAgentInfoMap( |
| 44 | + AgentStatusFilter filter, |
| 45 | + Collection<DetailedAgentAndStatus> agentAndStatuses |
| 46 | + ) { |
| 47 | + return AgentsMapByApplication.newAgentsMapByApplication( |
| 48 | + filter, |
| 49 | + agentAndStatuses, |
| 50 | + DetailedAgentInfo::getAgentInfo, |
| 51 | + DetailedAgentAndStatus::getStatus, |
| 52 | + DetailedAgentAndStatus::getDetailedAgentInfo |
| 53 | + ); |
| 54 | + } |
| 55 | + |
| 56 | + public static <I, T> AgentsMapByApplication<T> newAgentsMapByApplication( |
| 57 | + AgentStatusFilter filter, |
| 58 | + Collection<I> agentCollection, |
| 59 | + Function<T, AgentInfo> agentInfoSupplier, |
| 60 | + Function<I, AgentStatus> agentStatusSupplier, |
| 61 | + Function<I, T> finisher |
| 62 | + ) { |
26 | 63 | Objects.requireNonNull(filter, "filter");
|
27 | 64 | Objects.requireNonNull(agentCollection, "agentCollection");
|
28 | 65 |
|
29 |
| - InstancesListMapBuilder<AgentAndStatus, AgentAndStatus> instancesListMapBuilder = |
30 |
| - new InstancesListMapBuilder<>( |
31 |
| - AgentsMapByApplication::byApplicationName, |
| 66 | + InstancesListMapBuilder<I, T> instancesListMapBuilder = |
| 67 | + new InstancesListMapBuilder<I, T>( |
| 68 | + agentInfoSupplier.andThen(AgentsMapByApplication::byApplicationName), |
32 | 69 | Comparator.naturalOrder(),
|
33 |
| - SortByAgentInfo.agentIdAsc(AgentAndStatus::getAgentInfo).getComparator(), |
| 70 | + SortByAgentInfo.agentIdAsc(agentInfoSupplier).getComparator(), |
34 | 71 | agentCollection
|
35 | 72 | );
|
36 | 73 |
|
37 |
| - instancesListMapBuilder.withFilter((AgentAndStatus a) -> filter.filter(a.getStatus())); |
38 |
| - return new AgentsMapByApplication(instancesListMapBuilder.build()); |
| 74 | + instancesListMapBuilder.withFilter((I x) -> filter.filter(agentStatusSupplier.apply(x))); |
| 75 | + instancesListMapBuilder.withFinisher(finisher); |
| 76 | + return new AgentsMapByApplication<T>(instancesListMapBuilder.build()); |
39 | 77 | }
|
40 | 78 |
|
41 |
| - private static String byApplicationName(AgentAndStatus agentAndStatus) { |
42 |
| - return agentAndStatus.getAgentInfo().getApplicationName(); |
| 79 | + private static String byApplicationName(AgentInfo agentInfo) { |
| 80 | + return agentInfo.getApplicationName(); |
43 | 81 | }
|
44 | 82 |
|
45 | 83 | @Override
|
|
0 commit comments