I’m trying to figure out how to concatenate two Netty pipelines into one. It seems like it should be straightforward enough. Something like:
List<String> namesOfSecond = second.getNames();
for (String name : namesOfSecond) {
ChannelHandler handler = second.get(name);
first.addLast("Second-" + name, handler);
}
But the javadoc for getNames() just says “Returns the List of the handler names.” It doesn’t say what order the list is in, if even in any particular order at all. For the above code to work properly, the list of names would have to be in the order of the list of handlers corresponding to those names in the pipeline. Is it? Is it guaranteed?
There’s also a toMap() function, which “Converts this pipeline into an ordered Map whose keys are handler names and whose values are handlers.” That seems a little better, I guess, as it explicitly says that the map is ordered. It doesn’t, however, say what it’s ordered by.
I am guessing that these functions return things in the “obvious” and “correct” order — i.e. pipeline order (as opposed to, say, ordering lexically by name) — but the documentation does not make this explicit, and so I would like to make sure. Does anyone know?
Thanks in advance.
Your guess is correct. The two mechanisms iterates over the installed handlers (or handler contexts, to be precise) from first to last, in the first case constructing a list and in the second case a LinkedHashMap.