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