001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.impl.ha; 018 019import java.util.Collection; 020import java.util.Collections; 021import java.util.HashSet; 022import java.util.Set; 023 024import org.apache.camel.CamelContext; 025import org.apache.camel.model.RouteDefinition; 026import org.apache.camel.util.ObjectHelper; 027 028public final class ClusteredRouteFilters { 029 private ClusteredRouteFilters() { 030 } 031 032 public static final class IsAutoStartup implements ClusteredRouteFilter { 033 @Override 034 public boolean test(CamelContext camelContext, String routeId, RouteDefinition route) { 035 try { 036 return route.isAutoStartup(camelContext); 037 } catch (Exception e) { 038 throw ObjectHelper.wrapRuntimeCamelException(e); 039 } 040 } 041 } 042 043 public static final class BlackList implements ClusteredRouteFilter { 044 private final Set<String> names; 045 046 public BlackList(String name) { 047 this(Collections.singletonList(name)); 048 } 049 050 public BlackList(Collection<String> names) { 051 this.names = new HashSet<>(names); 052 } 053 054 @Override 055 public boolean test(CamelContext camelContext, String routeId, RouteDefinition route) { 056 return !names.contains(routeId); 057 } 058 } 059}