@Override ChannelHandler channel(String channelName) { String name = nameOf(channelName); String dataSource = sourceOf(channelName); return dataSources.get(dataSource).channel(name); }
private Map<String, ReadRecipe> splitRecipe(ReadRecipe readRecipe) { Map<String, ReadRecipe> splitRecipe = new HashMap<String, ReadRecipe>(); // Iterate through the recipe to understand how to distribute // the calls Map<String, Collection<ChannelReadRecipe>> routingRecipes = new HashMap<String, Collection<ChannelReadRecipe>>(); for (ChannelReadRecipe channelRecipe : readRecipe.getChannelReadRecipes()) { String name = nameOf(channelRecipe.getChannelName()); String dataSource = sourceOf(channelRecipe.getChannelName()); if (dataSource == null) throw new IllegalArgumentException("Channel " + name + " uses the default data source but one was never set."); // Add recipe for the target dataSource if (routingRecipes.get(dataSource) == null) { routingRecipes.put(dataSource, new HashSet<ChannelReadRecipe>()); } routingRecipes.get(dataSource).add(new ChannelReadRecipe(name, channelRecipe.getReadSubscription())); } // Create the recipes for (Entry<String, Collection<ChannelReadRecipe>> entry : routingRecipes.entrySet()) { splitRecipe.put(entry.getKey(), new ReadRecipe(entry.getValue())); } return splitRecipe; }
private Map<String, WriteRecipe> splitRecipe(WriteRecipe writeRecipe) { // Chop the recipe along different data sources Map<String, Collection<ChannelWriteRecipe>> recipes = new HashMap<String, Collection<ChannelWriteRecipe>>(); for (ChannelWriteRecipe channelWriteRecipe : writeRecipe.getChannelWriteRecipes()) { String channelName = nameOf(channelWriteRecipe.getChannelName()); String dataSource = sourceOf(channelWriteRecipe.getChannelName()); Collection<ChannelWriteRecipe> channelWriteRecipes = recipes.get(dataSource); if (channelWriteRecipes == null) { channelWriteRecipes = new ArrayList<ChannelWriteRecipe>(); recipes.put(dataSource, channelWriteRecipes); } channelWriteRecipes.add(new ChannelWriteRecipe(channelName, channelWriteRecipe.getWriteSubscription())); } Map<String, WriteRecipe> splitRecipes = new HashMap<String, WriteRecipe>(); for (Map.Entry<String, Collection<ChannelWriteRecipe>> en : recipes.entrySet()) { String dataSource = en.getKey(); Collection<ChannelWriteRecipe> val = en.getValue(); WriteRecipe newWriteRecipe = new WriteRecipe(val); splitRecipes.put(dataSource, newWriteRecipe); } return splitRecipes; }