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 */
017
018package org.apache.activemq.camel.camelplugin;
019
020import org.apache.activemq.broker.Broker;
021import org.apache.activemq.broker.BrokerPlugin;
022import org.slf4j.Logger;
023import org.slf4j.LoggerFactory;
024
025/**
026 * A CamelRoutesBrokerPlugin
027 *
028 * load camel routes dynamically from a routes.xml file located in same directory as ActiveMQ.xml
029 *
030 * @org.apache.xbean.XBean element="camelRoutesBrokerPlugin"
031 *
032 */
033public class CamelRoutesBrokerPlugin implements BrokerPlugin {
034    private static Logger LOG = LoggerFactory.getLogger(CamelRoutesBrokerPlugin.class);
035    private String routesFile = "";
036    private int checkPeriod =1000;
037
038    public String getRoutesFile() {
039        return routesFile;
040    }
041
042    public void setRoutesFile(String routesFile) {
043        this.routesFile = routesFile;
044    }
045
046    public int getCheckPeriod() {
047        return checkPeriod;
048    }
049
050    public void setCheckPeriod(int checkPeriod) {
051        this.checkPeriod = checkPeriod;
052    }
053
054    /** 
055     * @param broker
056     * @return the plug-in
057     * @throws Exception
058     * @see org.apache.activemq.broker.BrokerPlugin#installPlugin(org.apache.activemq.broker.Broker)
059     */
060    public Broker installPlugin(Broker broker) throws Exception {
061        CamelRoutesBroker answer = new CamelRoutesBroker(broker);
062        answer.setCheckPeriod(getCheckPeriod());
063        answer.setRoutesFile(getRoutesFile());
064        LOG.info("Installing CamelRoutesBroker");
065        return answer;
066    }
067}