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.spi; 018 019import java.util.Collection; 020import java.util.concurrent.TimeUnit; 021 022import org.apache.camel.CamelContextAware; 023import org.apache.camel.Experimental; 024import org.apache.camel.Route; 025import org.apache.camel.Service; 026 027@Experimental 028public interface RouteController extends CamelContextAware, Service { 029 /** 030 * Return the list of routes controlled by this controller. 031 * 032 * @return the list of controlled routes; 033 */ 034 Collection<Route> getControlledRoutes(); 035 036 void startRoute(String routeId) throws Exception; 037 038 void stopRoute(String routeId) throws Exception; 039 040 void stopRoute(String routeId, long timeout, TimeUnit timeUnit) throws Exception; 041 042 boolean stopRoute(String routeId, long timeout, TimeUnit timeUnit, boolean abortAfterTimeout) throws Exception; 043 044 void suspendRoute(String routeId) throws Exception; 045 046 void suspendRoute(String routeId, long timeout, TimeUnit timeUnit) throws Exception; 047 048 void resumeRoute(String routeId) throws Exception; 049 050 /** 051 * Access the underlying concrete RouteController implementation. 052 * 053 * @param clazz the proprietary class or interface of the underlying concrete RouteController. 054 * @return an instance of the underlying concrete RouteController as the required type. 055 */ 056 default <T extends RouteController> T unwrap(Class<T> clazz) { 057 if (RouteController.class.isAssignableFrom(clazz)) { 058 return clazz.cast(this); 059 } 060 061 throw new IllegalArgumentException( 062 "Unable to unwrap this RouteController type (" + getClass() + ") to the required type (" + clazz + ")" 063 ); 064 } 065}