Hi All, I am getting an IllegalStateException::kernel does not exist, when I am trying to lookup for a component. Here is the scenario of what I am trying to do: I am using Merlin in a embedded way. There are components which I have developed and some of them are having dependencies amongst each other. Their xinfo files have the correct dependencies defined.
The part of embedding is as follows : ClassLoader classloader = Framework.class.getClassLoader(); File repository = new File( getMavenHome(), "repository" ); File basedir = getBaseDirectory(); Map criteria = null; org.apache.avalon.repository.provider.Factory factory = null; try { Artifact artifact = DefaultBuilder.createImplementationArtifact( classloader, getMerlinHome(), basedir, MERLIN_PROPERTIES, IMPLEMENTATION_KEY ); InitialContextFactory icFactory = new DefaultInitialContextFactory( "merlin", basedir ); icFactory.setCacheDirectory( repository ); InitialContext context = icFactory.createInitialContext(); Builder builder = new DefaultBuilder( context, artifact ); m_classloader = builder.getClassLoader(); factory = builder.getFactory(); criteria = factory.createDefaultCriteria(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } if (singleton == null) { singleton = new Framework(); } else { singleton.getLogger().debug( "Framework Already Initialized - Attempt Ignored"); } try { m_kernel = factory.create( criteria ); m_shutdown = m_kernel.getClass().getMethod( "shutdown", new Class[0] ); Method method = m_kernel.getClass().getMethod( "getModel", new Class[0] ); m_root = method.invoke( m_kernel, new Object[0] ); m_locate = m_root.getClass().getMethod( "getModel", new Class[]{ String.class } ); Class modelClass = m_classloader.loadClass( DEPLOYMENT_MODEL_CLASSNAME ); m_resolve = modelClass.getMethod( "resolve", new Class[0] ); initialized = true; Normally we try to look up the dependent components using the service manager in the service() method. But in the case of embeddding Merlin, I do not want to use the service() method to look up for the dependent components. Due to some design constraints, I am doing a lookup in the configure() method itself without using the service manager since I am havng my own manager class. Now here comes the problem: When Merlin is embedded, the factory.create(Map) method instantiates the container and then commissions all the components in the container. While trying to do so, it also reads the configure method of each component (got to know when I ran with debug option as true). Remember that uptill now, my kernel has not been initialized (it is in the process of initializing). In my component's configure() method, I look up for the dependent components, In my getComponent method, I try to invoke the compoennt by using reflection. as shown below: public Component getComponent(String path ) throws ComponentNotFoundException { AbstractObject abstractObject; try { abstractObject = resolve(path); } catch (Exception e) { // TODO Auto-generated catch block throw new ComponentNotFoundException(getLogger(), path,"Exception in getting Component .Exception is "+e); } return (Component)Proxy.newProxyInstance(Component.class.getClassLoader(), abstractObject.getclasses(),new InvocationHandlerImpl(abstractObject.getObj())); } public AbstractObject resolve( String path ) throws Exception { if( null == m_kernel ) throw new IllegalStateException( "kernel does not exist" ); try { Object model = m_locate.invoke( m_root, new Object[]{ path } ); Class objClass = model.getClass(); Method method = objClass.getMethod("getServices", null); ServiceDescriptor[] serviceDescriptors = (ServiceDescriptor[])method.invoke(model,new Object[0]); Class[] classes = new Class[serviceDescriptors.length+1]; classes[serviceDescriptors.length] = Component.class; for(int i = 0 ; i < serviceDescriptors.length ; i++ ){ classes[i] = Class.forName(serviceDescriptors[i].getReference().getClassname()); } //()model Object obj = m_resolve.invoke( model, new Object[0] ); return new AbstractObject(obj,classes); //return (Component)Proxy.newProxyInstance(Component.class.getClassLoader(), classes,new ComponentImpl(obj)); } catch( InvocationTargetException ite ) { Throwable cause = ite.getTargetException(); final String error = ExceptionHelper.packException( cause, true ); throw new Exception( error ); } catch( Throwable e ) { final String error = ExceptionHelper.packException( e, true ); throw new Exception( error ); } } As you notice, in the very first step the kewrnel is checked for null and since it has not been initalized uptill now, it throws an IllegalStateException. Infact other objects, such as m_root and methods m_locate are all unitialized as well. Thus the operation has entered in a loop i.e. while trying to initialize the kernel, somewhere down the line in some component's configure method, it is trying to use the uninitialzed kernel. I want to know whether the way I am using for resolving the component is ok or needs to be changed. Whether there is any other way where I can initialize the empty kernel completely and then commission all the components to it. I tried to reproduce this error for Normal Merlin conditions (not embedding). I passed the service Manager into the component's contructor directly and then used the service manager in the configure() method to lookup the components and it worked. So what should we do during the embedding scenario for this to work ? Please provide some pointers on this regard Regards, Harvinder --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]