Claus, thanks for the reply. Ok I tried that, however, if in the bootstrap code in main just before calling run() I place
List<CamelContext> contexts=getCamelContexts(); System.out.println(contexts); // [] CamelContext context=contexts.get(0); //IndexOutOfBoundsException: Index: 0, Size: 0 context.getManagementStrategy().addEventNotifier(new MyLoggingSentEventNotifer()); //as in http://camel.apache.org/eventnotifier-to-log-details-about-all-sent-exchanges.html run(); It produces [] Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 Is this a bug or am I doing something wrong? On Fri, Apr 5, 2013 at 9:24 AM, Claus Ibsen <claus.ib...@gmail.com> wrote: > Hi > > Yeah we could add some methods to the Main class you can override to > have callbacks after start | before stop etc. > But you can also just use the event notifier api in Camel for that. > > > > On Wed, Apr 3, 2013 at 4:17 PM, Andrew Bailey <andrew.bai...@apps4u.co> > wrote: > > 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 > > > > -- > Claus Ibsen > ----------------- > Red Hat, Inc. > FuseSource is now part of Red Hat > Email: cib...@redhat.com > Web: http://fusesource.com > Twitter: davsclaus > Blog: http://davsclaus.com > Author of Camel in Action: http://www.manning.com/ibsen > -- Andrew Bailey Cel - 312 866 95 56 http://www.apps4u.co Chat Skype: apps4u Twitter @apps4uco