I have a use case, where I require a fast startup time for camel and wish
to avoid classpath scanning.
I use the Main class however it appears that its not possible to obtain a
ProducerTemplate template = getCamelTemplate();
before calling the run method. (it produces an ArrayOutOfBounds exception -
I could file a bug for that if you like)

What I did was to extend Main (see code fragment below) and add a callback
called from the afterStart() method, so that user code can access the
context, and TypeConverterRegistry (as before that it is not initialized).

Is there a better way to do it?

If not and the developers think its a good idea, I would like to contribute
the code for a future release.


Thanks

Andy


import org.apache.camel.main.Main;

public class ServiceManager extends Main {


        public static void main(String[] args) throws Exception {
            ServiceManager example = new ServiceManager();
            example.boot();
        }

        public void boot() throws Exception {
//cut

         setAfterStartCallback(new Callable<Void>(){
                public Void call() throws Exception
                {
                        ProducerTemplate template = getCamelTemplate();

                        fileMonitor.setProducer(template);

                       /*
                       List<CamelContext> contexts=getCamelContexts();
                       System.out.println(contexts);
                       CamelContext context=contexts.get(0);
                       TypeConverterRegistry converterRegistry =
context.getTypeConverterRegistry();
                       TypeConverter converter =
converterRegistry.lookup(String[].class, String.class);
                       System.out.println("Converter "+converter);

                       TypeConverter converter2 =
converterRegistry.lookup(List.class, String.class);
                       System.out.println("Converter "+converter2);

                       */
                       return null;
                }
            });
//code cut
     System.out.println("Starting Camel. Use ctrl + c to terminate the
JVM.\n");
            run();
        }

        private Callable<Void> afterStartCallback;

        @Override
        protected void afterStart() throws Exception {

            if (afterStartCallback!=null) afterStartCallback.call();
        }

        public Callable<Void> getAfterStartCallback() {
            return afterStartCallback;
        }

        public void setAfterStartCallback(Callable<Void>
afterStartCallback) {
            this.afterStartCallback = afterStartCallback;
        }
}

-- 



Andrew Bailey
Cel - 312 866 95 56

http://www.apps4u.co
Chat Skype: apps4u
Twitter @apps4uco

Reply via email to