/** * Builds the recipe. * <p> * To finish building the recipe, one needs to specify where to send errors * and where to send the connection status changes. * * @param exceptionWriteFunction where exception should be routed * @param connectionCollector where connection status should be routed * @return a new WriteRecipe */ public WriteRecipe build(WriteFunction<Exception> exceptionWriteFunction, ConnectionCollector connectionCollector) { Set<ChannelWriteRecipe> recipes = new HashSet<>(); for (Map.Entry<String, Collection<WriteCache<?>>> entry : caches.entrySet()) { String channelName = entry.getKey(); Collection<WriteCache<?>> valueCaches = entry.getValue(); for (WriteCache<?> valueCache : valueCaches) { recipes.add(new ChannelWriteRecipe(channelName, new ChannelHandlerWriteSubscription(valueCache, exceptionWriteFunction, connectionCollector.addChannel(channelName)))); } } return new WriteRecipe(recipes); }