You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Jim Alateras <ji...@comware.com.au> on 2003/11/19 13:04:37 UTC

[merlin] merlin + datasources

I was wondering whether anyone can advice me on how to correctly
configure the datasource component within merlin. This is what I have
tried but I get an exception when I execute the block.

1. In the block.xml I use the include directive 

<container name="pep">
	:
	:
  <include name="jdbc-manager"
id="cornerstone-datasources:cornerstone-datasources-impl" version="1.0"
/>

</container>

2. In the config.xml I have the following

<targets>
  <target path="/pep/jdbc-manager/manager">
    <configuration>
      <data-sources>
        <data-source name="maindb"
class="org.apache.avalon.excalibur.datasource.JdbcDataSource">
          <pool-controller min="5" max="10" />
          <driver>org.gjt.mm.mysql.Driver</driver>
          <dburl>jdbc:mysql:/localhost/test</dburl>
          <user>mysql</user>
          <password>mysql</password>
          <auto-commit>true</auto-commit>
        </data-source>
      </data-sources>
    </configuration>
  </target>
   :
   :
</targets>

3. In one of my other services, I try to use the datasource like this

        DataSourceComponent ds =
(DataSourceComponent)_dsSelector.select("maindb");

But when this service executes I get the following error

java.lang.NullPointerException
        at
org.apache.avalon.activation.appliance.impl.DefaultBlock$BlockInvocation
Handler.invoke(DefaultBlock.java:996)
        at $Proxy3.select(Unknown Source)
        at
com.choreoworks.pep.loader.PEPLoader.testDataSource(PEPLoader.java:359)
        at
com.choreoworks.pep.loader.PEPLoader.start(PEPLoader.java:184)
        at
org.apache.avalon.activation.appliance.impl.DefaultAppliance.applyStart(
DefaultAppliance.java:998)
        at
org.apache.avalon.activation.appliance.impl.DefaultAppliance.access$1400
(DefaultAppliance.java:112)
        at
org.apache.avalon.activation.appliance.impl.DefaultAppliance$StandardFac
tory.newInstance(DefaultAppliance.java:1294)
        at
org.apache.avalon.activation.lifestyle.impl.SingletonLifestyleHandler.re
freshReference(SingletonLifestyleHandler.java:138
)
        at
org.apache.avalon.activation.lifestyle.impl.SingletonLifestyleHandler.re
solve(SingletonLifestyleHandler.java:88)
        at
org.apache.avalon.activation.appliance.impl.DefaultAppliance.resolve(Def
aultAppliance.java:566)
        at
org.apache.avalon.activation.appliance.impl.DefaultAppliance.deploy(Defa
ultAppliance.java:508)
        at
org.apache.avalon.activation.appliance.impl.DefaultBlock.deploy(DefaultB
lock.java:623)
        at
org.apache.avalon.activation.appliance.impl.BlockThread.run(BlockThread.
java:111)


Can anyone see any problems with my usage?

Has anyone used excalibur-datasource/cornerstone-datasources within
merlin?


cheers
</jima>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org


RE: [merlin] merlin + datasources

Posted by Jim Alateras <ji...@comware.com.au>.
I have been able to use the test case to test the DataSourceSelector
component in isolation and that call to select works but in the context
of my application I still get an error.

I have dug a little further and have found that the NPE comes from
CompositeBlock.invoke..as indicated by the stack trace below.

java.lang.NullPointerException
        at
org.apache.avalon.activation.appliance.impl.CompositeBlock$BlockInvocati
onHandler.invoke(CompositeBlock.java:274)
        at $Proxy3.select(Unknown Source)
        at
com.choreoworks.pep.loader.PEPLoader.testDataSource(PEPLoader.java:367)
        at
com.choreoworks.pep.loader.PEPLoader.access$000(PEPLoader.java:85)
        at
com.choreoworks.pep.loader.PEPLoader$1.run(PEPLoader.java:186)

The line numbers will not match what is in CVS because I have further
instrumented the code. Basically 'service' is null after the call to
model.getExportDirective hence the call to service.getPath throws the
NPE.

            ServiceDirective service = 
              model.getExportDirective( method.getDeclaringClass() );

            String path = service.getPath();

It seems that if, in my block.xml file, I replace the "include"
directive with the corresponding "resource" and "component" elements
everything works dandy. 

i.e. this doesn't work for me

     <include name="jdbc-manager"
id="cornerstone-datasources:cornerstone-datasources-impl" version="1.0"
/>

but this does work for me (with the associated resources)

     <component name="jdbc-manager"
class="org.apache.avalon.cornerstone.blocks.datasources.DefaultDataSourc
eSelector" activation="true" />

Furthermore it seems that I am getting the same problem with components
that are imported through the "include" directive (i.e. thread manager,
socket manage etc). When a call through a proxy is made it fails, as
indicated in the stack trace above.

In summary I can work around the problem by removing all "include"
directives from my block.xml and replacing them with the equivalent xml
fragments. I hope this all makes sense ;-).

Finally, I was wondering whether anyone else has experienced a similar
problem. 

cheers
</jima>

> -----Original Message-----
> From: Stephen McConnell [mailto:mcconnell@apache.org]
> Sent: Friday, November 21, 2003 9:46 PM
> To: Avalon Developers List
> Subject: Re: [merlin] merlin + datasources
> 
> 
> 
> Jim Alateras wrote:
> 
> >>>But when this service executes I get the following error
> >>>
> >>>java.lang.NullPointerException
> >>>
> >>>
> >>>
> >>Umm .. this is a worry - you should not be getting a NPE.
> >>
> >>Any chance you could throw together a testcase?
> >>
> >>
> >>
> >How should I package the test case. Do you want a jar + config +
source
> >so you can execute the block that will show the error
> >
> 
> Jim:
> 
> I took a more careful look at the stack trace that you initially
> posted.  The NPE is being thrown under the select operation - so the
bug
> is down in the DefaultDataSourceSelector.  I've just update the
> cornerstone datasources-impl project to include an empty test case.
You
> should be able to use this to establish the NPE condition by modifying
> the config.xml and invoking selection under the test case.
> 
> Stephen.
> 
> >
> >cheers
> ></jima>
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
> >For additional commands, e-mail: dev-help@avalon.apache.org
> >
> >
> >
> >
> 
> --
> 
> Stephen J. McConnell
> mailto:mcconnell@apache.org
> 
> |------------------------------------------------|
> | Magic by Merlin                                |
> | Production by Avalon                           |
> |                                                |
> | http://avalon.apache.org/merlin                |
> | http://dpml.net/                               |
> |------------------------------------------------|
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
> For additional commands, e-mail: dev-help@avalon.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org


RE: [merlin] merlin + datasources

Posted by Jim Alateras <ji...@comware.com.au>.
> Jim Alateras wrote:
> 
> >>>But when this service executes I get the following error
> >>>
> >>>java.lang.NullPointerException
> >>>
> >>>
> >>>
> >>Umm .. this is a worry - you should not be getting a NPE.
> >>
> >>Any chance you could throw together a testcase?
> >>
> >>
> >>
> >How should I package the test case. Do you want a jar + config +
source
> >so you can execute the block that will show the error
> >
> 
> Jim:
> 
> I took a more careful look at the stack trace that you initially
> posted.  The NPE is being thrown under the select operation - so the
bug
> is down in the DefaultDataSourceSelector.  I've just update th
> cornerstone datasources-impl project to include an empty test case.
You
> should be able to use this to establish the NPE condition by modifying
> the config.xml and invoking selection under the test case.

great. I'll give it a go today


cheers
</jima>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org


Re: [merlin] merlin + datasources

Posted by Stephen McConnell <mc...@apache.org>.

Jim Alateras wrote:

>>>But when this service executes I get the following error
>>>
>>>java.lang.NullPointerException
>>>
>>>      
>>>
>>Umm .. this is a worry - you should not be getting a NPE.
>>
>>Any chance you could throw together a testcase?
>>
>>    
>>
>How should I package the test case. Do you want a jar + config + source
>so you can execute the block that will show the error
>

Jim:

I took a more careful look at the stack trace that you initially 
posted.  The NPE is being thrown under the select operation - so the bug 
is down in the DefaultDataSourceSelector.  I've just update the 
cornerstone datasources-impl project to include an empty test case.  You 
should be able to use this to establish the NPE condition by modifying 
the config.xml and invoking selection under the test case.

Stephen.

>
>cheers
></jima>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
>For additional commands, e-mail: dev-help@avalon.apache.org
>
>
>  
>

-- 

Stephen J. McConnell
mailto:mcconnell@apache.org

|------------------------------------------------|
| Magic by Merlin                                |
| Production by Avalon                           |
|                                                |
| http://avalon.apache.org/merlin                |
| http://dpml.net/                               |
|------------------------------------------------|





---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org


RE: [merlin] merlin + datasources

Posted by Jim Alateras <ji...@comware.com.au>.
> 
> >
> >But when this service executes I get the following error
> >
> >java.lang.NullPointerException
> >
> 
> Umm .. this is a worry - you should not be getting a NPE.
> 
> Any chance you could throw together a testcase?
> 
How should I package the test case. Do you want a jar + config + source
so you can execute the block that will show the error

cheers
</jima>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org


RE: [merlin] merlin + datasources

Posted by Jim Alateras <ji...@comware.com.au>.
> >
> >3. In one of my other services, I try to use the datasource like this
> >
> >        DataSourceComponent ds =
> >(DataSourceComponent)_dsSelector.select("maindb");
> >
> 
> First off - your attempting to narrow to a component implementation
> instread of the service it exposes. I would have assumed that you
would
> resolve the DataSourceSelector service from the service manager, then
> incoke select on the returned selector.

I believe that I am already doing that

    /**
     * Servicing of the component by the container during which service 
     * dependencies declared under the component can be resolved using
the 
     * supplied service manager.
     *
     * @avalon.dependency type="com.choreoworks.sap.logger.Logger"
key="logger" 
     * @avalon.dependency
type="com.choreoworks.sap.uuid.spi.UUIDGenerator:1.0"
key="uuid-generator" 
     * @avalon.dependency
type="com.choreoworks.sap.scheduler.spi.JobScheduler:1.0"
key="job-scheduler" 
     * @avalon.dependency
type="com.choreoworks.sap.queue.spi.QueueManager:1.0"
key="queue-manager" 
     * @avalon.dependency
type="org.apache.avalon.cornerstone.services.threads.ThreadManager:1.0"
key="thread-manager" 
     * @avalon.dependency
type="org.apache.avalon.cornerstone.services.sockets.SocketManager:1.0"
key="socket-manager" 
     * @avalon.dependency
type="org.apache.avalon.cornerstone.services.datasources.DataSourceSelec
tor:1.0" key="data-source-selector" 
     *
     * @param manager - the service manager
     * @throws ServiceException
     */
    public void service(final ServiceManager manager)
    throws ServiceException {
        _scheduler = (JobScheduler)manager.lookup("job-scheduler");
        _uuidGenerator =
(UUIDGenerator)manager.lookup("uuid-generator");
        _queueManager = (QueueManager)manager.lookup("queue-manager");
        _socketManager =
(SocketManager)manager.lookup("socket-manager");
        _threadManager =
(ThreadManager)manager.lookup("thread-manager");
        _dsSelector =
(DataSourceSelector)manager.lookup("data-source-selector");
    }
> 
> >
> >But when this service executes I get the following error
> >
> >java.lang.NullPointerException
> >
> 
> Umm .. this is a worry - you should not be getting a NPE.
> 
> Any chance you could throw together a testcase?
> 

Yep I can do something over the next couple of days. 


cheers
</jima>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org


Re: [merlin] merlin + datasources

Posted by Stephen McConnell <mc...@apache.org>.

Jim Alateras wrote:

>I was wondering whether anyone can advice me on how to correctly
>configure the datasource component within merlin. This is what I have
>tried but I get an exception when I execute the block.
>
>1. In the block.xml I use the include directive 
>
><container name="pep">
>	:
>	:
>  <include name="jdbc-manager"
>id="cornerstone-datasources:cornerstone-datasources-impl" version="1.0"
>/>
>
></container>
>

OK - so the result of the above is that the container you have defined 
is exposing itself as a DataSourceSelector service.

>
>2. In the config.xml I have the following
>
><targets>
>  <target path="/pep/jdbc-manager/manager">
>    <configuration>
>      <data-sources>
>        <data-source name="maindb"
>class="org.apache.avalon.excalibur.datasource.JdbcDataSource">
>          <pool-controller min="5" max="10" />
>          <driver>org.gjt.mm.mysql.Driver</driver>
>          <dburl>jdbc:mysql:/localhost/test</dburl>
>          <user>mysql</user>
>          <password>mysql</password>
>          <auto-commit>true</auto-commit>
>        </data-source>
>      </data-sources>
>    </configuration>
>  </target>
>   :
>   :
></targets>
>
>3. In one of my other services, I try to use the datasource like this
>
>        DataSourceComponent ds =
>(DataSourceComponent)_dsSelector.select("maindb");
>

First off - your attempting to narrow to a component implementation 
instread of the service it exposes. I would have assumed that you would 
resolve the DataSourceSelector service from the service manager, then 
incoke select on the returned selector.

>
>But when this service executes I get the following error
>
>java.lang.NullPointerException
>

Umm .. this is a worry - you should not be getting a NPE.

Any chance you could throw together a testcase?

Stephen.

-- 

Stephen J. McConnell
mailto:mcconnell@apache.org

|------------------------------------------------|
| Magic by Merlin                                |
| Production by Avalon                           |
|                                                |
| http://avalon.apache.org/merlin                |
| http://dpml.net/                               |
|------------------------------------------------|





---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org