use of net.dempsy.ClusterInformation in project Dempsy by Dempsy.
the class ApplicationState method apply.
public ApplicationState apply(final ApplicationState.Update update, final TransportManager tmanager, final NodeStatsCollector statsCollector, final RoutingStrategyManager manager) {
// apply toDelete first.
final Set<NodeAddress> toDelete = update.toDelete;
if (toDelete.size() > 0) {
// just clear all senders.
for (final NodeAddress a : toDelete) {
final Sender s = senders.get(a);
if (s != null)
s.stop();
}
}
final Map<NodeAddress, NodeInformation> newCurrent = new HashMap<>();
// the one's to carry over.
final Set<NodeInformation> leaveAlone = update.leaveAlone;
for (final NodeInformation cur : leaveAlone) {
newCurrent.put(cur.nodeAddress, cur);
}
// add new senders
final Set<NodeInformation> toAdd = update.toAdd;
for (final NodeInformation cur : toAdd) {
newCurrent.put(cur.nodeAddress, cur);
}
// now flush out the remaining caches.
// collapse all clusterInfos
final Set<ClusterInformation> allCis = new HashSet<>();
newCurrent.values().forEach(ni -> allCis.addAll(ni.clusterInfoByClusterId.values()));
final Map<String, RoutingStrategy.Router> newOutboundByClusterName = new HashMap<>();
final Map<String, Set<String>> cnByType = new HashMap<>();
final Set<String> knownClusterOutbounds = new HashSet<>(outboundByClusterName_.keySet());
for (final ClusterInformation ci : allCis) {
final String clusterName = ci.clusterId.clusterName;
final RoutingStrategy.Router ob = outboundByClusterName_.get(clusterName);
knownClusterOutbounds.remove(clusterName);
if (ob != null)
newOutboundByClusterName.put(clusterName, ob);
else {
final RoutingStrategy.Factory obfactory = manager.getAssociatedInstance(ci.routingStrategyTypeId);
final RoutingStrategy.Router nob = obfactory.getStrategy(ci.clusterId);
newOutboundByClusterName.put(clusterName, nob);
}
// add all of the message types handled.
ci.messageTypesHandled.forEach(mt -> {
Set<String> entry = cnByType.get(mt);
if (entry == null) {
entry = new HashSet<>();
cnByType.put(mt, entry);
}
entry.add(clusterName);
});
}
return new ApplicationState(newOutboundByClusterName, cnByType, newCurrent, tmanager, thisNode);
}
use of net.dempsy.ClusterInformation in project Dempsy by Dempsy.
the class ApplicationState method apply.
public ApplicationState apply(final ApplicationState.Update update, final TransportManager tmanager, final NodeStatsCollector statsCollector, final RoutingStrategyManager manager, final String thisNodeId) {
// apply toDelete first.
final Set<NodeAddress> toDelete = update.toDelete;
final boolean infoEnabled = LOGGER_SESSION.isInfoEnabled();
if (toDelete.size() > 0) {
// just clear all senders.
if (infoEnabled)
LOGGER_SESSION.info("[{}] Applying update to topology resulting in removing several destinations:", thisNodeId);
for (final NodeAddress a : toDelete) {
final Sender s = senders.remove(a);
if (infoEnabled)
LOGGER_SESSION.info("[{}] removing sender ({}) to {}", thisNodeId, s, a);
if (s != null)
s.stop();
}
}
final Map<NodeAddress, NodeInformation> newCurrent = new HashMap<>();
// the one's to carry over.
final Set<NodeInformation> leaveAlone = update.leaveAlone;
if (leaveAlone.size() > 0)
if (infoEnabled)
LOGGER_SESSION.info("[{}] Applying update to topology resulting in leaving several destinations:", thisNodeId);
for (final NodeInformation cur : leaveAlone) {
if (infoEnabled)
LOGGER_SESSION.info("[{}] leaving alone : {}", thisNodeId, Optional.ofNullable(cur).map(ni -> ni.nodeAddress).orElse(null));
newCurrent.put(cur.nodeAddress, cur);
}
// add new senders
final Set<NodeInformation> toAdd = update.toAdd;
if (toAdd.size() > 0)
if (infoEnabled)
LOGGER_SESSION.info("[{}] Applying update to topology resulting in adding several destinations:", thisNodeId);
for (final NodeInformation cur : toAdd) {
if (infoEnabled)
LOGGER_SESSION.info("[{}] adding : {}", thisNodeId, Optional.ofNullable(cur).map(ni -> ni.nodeAddress).orElse(null));
newCurrent.put(cur.nodeAddress, cur);
}
// now flush out the remaining caches.
// collapse all clusterInfos
final Set<ClusterInformation> allCis = new HashSet<>();
newCurrent.values().forEach(ni -> allCis.addAll(ni.clusterInfoByClusterId.values()));
final Map<String, RoutingStrategy.Router> newOutboundByClusterName = new HashMap<>();
final Map<String, Set<String>> cnByType = new HashMap<>();
final Set<String> knownClusterOutbounds = new HashSet<>(outboundByClusterName_.keySet());
for (final ClusterInformation ci : allCis) {
final String clusterName = ci.clusterId.clusterName;
final RoutingStrategy.Router ob = outboundByClusterName_.get(clusterName);
knownClusterOutbounds.remove(clusterName);
if (ob != null)
newOutboundByClusterName.put(clusterName, ob);
else {
final RoutingStrategy.Factory obfactory = manager.getAssociatedInstance(ci.routingStrategyTypeId);
final RoutingStrategy.Router nob = obfactory.getStrategy(ci.clusterId);
newOutboundByClusterName.put(clusterName, nob);
}
// add all of the message types handled.
ci.messageTypesHandled.forEach(mt -> {
Set<String> entry = cnByType.get(mt);
if (entry == null) {
entry = new HashSet<>();
cnByType.put(mt, entry);
}
entry.add(clusterName);
});
}
return new ApplicationState(newOutboundByClusterName, cnByType, newCurrent, tmanager, thisNode, senders);
}
Aggregations