/*
* gather connections related to the targetUuid requested
*/
@Override
public void createSession(SourceHandler sourceHandler, Class<? extends TargetHandler> targetHandler, String targetUuid) {
ChannelGroup group = new DefaultChannelGroup();
HashSet<String> uuids = new HashSet<>();
boolean breakOnMatch = targetUuid != null && !targetUuid.isEmpty();
int sessionID = nextSession.incrementAndGet();
synchronized (connectedChannels) {
for (ChannelState state : connectedChannels) {
if (
(targetUuid == MeshyConstants.LINK_ALL) ||
(targetUuid == MeshyConstants.LINK_NAMED && state.getRemoteAddress() != null) ||
(state.getName() != null && targetUuid.equals(state.getName()))
) {
/* prevent dups if >1 connection to the same host */
if (state.getName() != null && !uuids.add(state.getName())) {
continue;
}
group.add(state.getChannel());
/* add channel callback path to source */
state.addSourceHandler(sessionID, sourceHandler);
if (breakOnMatch) {
break;
}