You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hivemind.apache.org by "Strutynski, Oliver" <ol...@sdm-research.de> on 2004/09/08 16:04:48 UTC

Service implementing multiple interfaces

While rewriting parts of an application to make use of Hivemind I 
encountered a problem with a class implementing two interfacess. I 
realized that writing
   <service-point id="id" interface="i1, i2">
does not work and thus combined both interfaces into a new interface. 
Now I have the following interface:

public interface PConnectionPoolDataSource extends 
javax.sql.ConnectionPoolDataSource, javax.sql.DataSource {
}

and a class implementing that interface.

In my hivemodule file I define a service point:

<service-point id="PersistenceConnectionPoolDataSource" 
interface="com.sdm.quasar.persistence.datasource.PConnectionPoolDataSource">
      <invoke-factory service-id="hivemind.BuilderFactory">
          <construct 
class="com.sdm.quasar.persistence.datasource.PersistenceConnectionPoolDataSource">
              <string>jdbc:mysql://localhost/test</string>
              <int>10</int>
              <int>5</int>
          </construct>
      </invoke-factory>
</service-point>

When auto-wiring this service to another one, Hivemind crashes with
"Error at file:/Z:/workspace/qpersistence/bin/META-INF/hivemodule.xml, 
line 52, column 94: Unable to autowire property 
PConnectionPoolDataSource of service 
com.sdm.quasar.persistence.Configuration: Attempt to redefine method 
java.io.PrintWriter getLogWriter() throws java.sql.SQLException of class 
$SingletonProxy_fede57f89e_6." (complete trace below).

The problem seems to be, that both javax.sql.ConnectionPoolDataSource 
and javax.sql.DataSource define the same method "java.io.PrintWriter 
getLogWriter() throws java.sql.SQLException" and Hivemind seems to try 
to add that method to the proxy twice. Any way to work around this? I am 
using Hivemind 1.0-beta2.

Thanks for any help

Oliver Strutynski


 + + + complete trace + + +
org.apache.hivemind.ApplicationRuntimeException: Attempt to redefine 
method java.io.PrintWriter getLogWriter() throws java.sql.SQLException 
of class $SingletonProxy_fede57f89e_6.
    at 
org.apache.hivemind.impl.servicemodel.SingletonServiceModel.createSingletonProxy(SingletonServiceModel.java:114)
    at 
org.apache.hivemind.impl.servicemodel.SingletonServiceModel.getService(SingletonServiceModel.java:58)
    at 
org.apache.hivemind.impl.ServicePointImpl.getService(ServicePointImpl.java:168)
    at 
org.apache.hivemind.impl.ServicePointImpl.getService(ServicePointImpl.java:181)
    at 
org.apache.hivemind.impl.RegistryImpl.getService(RegistryImpl.java:163)
    at org.apache.hivemind.impl.ModuleImpl.getService(ModuleImpl.java:65)
    at 
org.apache.hivemind.service.impl.BuilderFactoryLogic.autowireProperty(BuilderFactoryLogic.java:301)
    at 
org.apache.hivemind.service.impl.BuilderFactoryLogic.autowireServices(BuilderFactoryLogic.java:275)
    at 
org.apache.hivemind.service.impl.BuilderFactoryLogic.setProperties(BuilderFactoryLogic.java:220)
    at 
org.apache.hivemind.service.impl.BuilderFactoryLogic.createService(BuilderFactoryLogic.java:70)
    at 
org.apache.hivemind.service.impl.BuilderFactory.createCoreServiceImplementation(BuilderFactory.java:65)
    at 
org.apache.hivemind.impl.InvokeFactoryServiceConstructor.constructCoreServiceImplementation(InvokeFactoryServiceConstructor.java:81)
    at 
org.apache.hivemind.impl.servicemodel.AbstractServiceModelImpl.constructCoreServiceImplementation(AbstractServiceModelImpl.java:100)
    at 
org.apache.hivemind.impl.servicemodel.AbstractServiceModelImpl.constructNewServiceImplementation(AbstractServiceModelImpl.java:148)
    at 
org.apache.hivemind.impl.servicemodel.AbstractServiceModelImpl.constructServiceImplementation(AbstractServiceModelImpl.java:130)
    at 
org.apache.hivemind.impl.servicemodel.SingletonServiceModel.getActualServiceImplementation(SingletonServiceModel.java:69)
    at $InnerProxy_fede57f73f_5._service($InnerProxy_fede57f73f_5.java)
    at $InnerProxy_fede57f73f_5.setup($InnerProxy_fede57f73f_5.java)
    at $SingletonProxy_fede57f6c7_4.setup($SingletonProxy_fede57f6c7_4.java)
    at 
com.sdm.quasartutorials.persistence.common.Configuration.<init>(Configuration.java:84)
    at 
com.sdm.quasartutorials.persistence.createobjects.demo.CreateObjectsDemo.main(CreateObjectsDemo.java:32)

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org


Re: Service implementing multiple interfaces

Posted by Howard Lewis Ship <hl...@gmail.com>.
Beat you to it!

http://nagoya.apache.org/jira/browse/HIVEMIND-52


On Wed, 8 Sep 2004 12:34:49 -0400, Howard Lewis Ship <hl...@gmail.com> wrote:
> Thanks for the bug and the fix (which needs to be applied in a couple
> of different places). If you could add a JIRA bug, that would be
> great!
> 
> 
> 
> 
> On Wed, 08 Sep 2004 17:31:15 +0200, Strutynski, Oliver
> <ol...@sdm-research.de> wrote:
> > For now I have worked around this by adding  some code to
> > ProxyBuilder.addServiceMethods that avoids that methods are being added
> > twice. Not sure if this is a good patch, as addServiceMethods should
> > probably check, if these methods are really defined in different
> > interfaces. But works for now. Code below.
> >
> > This issue is related to issue 39
> > (http://issues.apache.org/jira/browse/HIVEMIND-39). Here combining two
> > interfaces into one was suggested as a way to write a service that has
> > multiple interfaces, but the fact that two interfaces ARE ALLOWED to
> > have similar methods was not taken into account.
> >
> > My new ProxyBuilder.addServiceMethods():
> >
> >     public void addServiceMethods(String indirection)
> >     {
> >         // use a local map to remember all method signatures
> >         java.util.Map methodMap = new java.util.HashMap();
> >         BodyBuilder builder = new BodyBuilder();
> >         boolean toString = false;
> >
> >         Method[] methods = _serviceInterface.getMethods();
> >         for (int i = 0; i < methods.length; i++)
> >         {
> >             Method m = methods[i];
> >
> >             builder.clear();
> >             builder.begin();
> >             builder.add("return ($r) ");
> >             builder.add(indirection);
> >             builder.add(".");
> >             builder.add(m.getName());
> >             builder.addln("($$);");
> >             builder.end();
> >             // only add new methods, ignore ones with signatures that
> > have already been added to proxy.
> >             if (!methodMap.containsKey(new MethodSignature(m))) {
> >               methodMap.put(new MethodSignature(m), null);
> >               _classFab.addMethod(Modifier.PUBLIC, new
> > MethodSignature(m), builder.toString());
> >             }
> >             toString |= ClassFabUtils.isToString(m);
> >         }
> >
> >         if (!toString)
> >             ClassFabUtils.addToStringMethod(
> >                 _classFab,
> >                 "<"
> >                     + _type
> >                     + " for "
> >                     + _point.getExtensionPointId()
> >                     + "("
> >                     + _serviceInterface.getName()
> >                     + ")>");
> >
> >
> >     }
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: hivemind-user-help@jakarta.apache.org
> >
> >
> 
> 
> --
> Howard M. Lewis Ship
> Independent J2EE / Open-Source Java Consultant
> Creator, Jakarta Tapestry
> Creator, Jakarta HiveMind
> http://howardlewisship.com
> 



-- 
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Jakarta Tapestry
Creator, Jakarta HiveMind
http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org


RE: Service implementing multiple interfaces

Posted by James Carman <ja...@carmanconsulting.com>.
We should create a test case for this, also.  I could create one, I believe
and submit a formal patch later on tonight.  And, I think the implementation
could short circuit a bit earlier..

Method m = methods[i];
if((!methodMap.containsKey(new MethodSignature(m)))
{
  builder.clear();
  builder.begin();
  builder.add("return ($r) "); 
  ...
}

-----Original Message-----
From: Howard Lewis Ship [mailto:hlship@gmail.com] 
Sent: Wednesday, September 08, 2004 12:35 PM
To: hivemind-user@jakarta.apache.org
Subject: Re: Service implementing multiple interfaces

Thanks for the bug and the fix (which needs to be applied in a couple
of different places). If you could add a JIRA bug, that would be
great!


On Wed, 08 Sep 2004 17:31:15 +0200, Strutynski, Oliver
<ol...@sdm-research.de> wrote:
> For now I have worked around this by adding  some code to
> ProxyBuilder.addServiceMethods that avoids that methods are being added
> twice. Not sure if this is a good patch, as addServiceMethods should
> probably check, if these methods are really defined in different
> interfaces. But works for now. Code below.
> 
> This issue is related to issue 39
> (http://issues.apache.org/jira/browse/HIVEMIND-39). Here combining two
> interfaces into one was suggested as a way to write a service that has
> multiple interfaces, but the fact that two interfaces ARE ALLOWED to
> have similar methods was not taken into account.
> 
> My new ProxyBuilder.addServiceMethods():
> 
>     public void addServiceMethods(String indirection)
>     {
>         // use a local map to remember all method signatures
>         java.util.Map methodMap = new java.util.HashMap();
>         BodyBuilder builder = new BodyBuilder();
>         boolean toString = false;
> 
>         Method[] methods = _serviceInterface.getMethods();
>         for (int i = 0; i < methods.length; i++)
>         {
>             Method m = methods[i];
> 
>             builder.clear();
>             builder.begin();
>             builder.add("return ($r) ");
>             builder.add(indirection);
>             builder.add(".");
>             builder.add(m.getName());
>             builder.addln("($$);");
>             builder.end();
>             // only add new methods, ignore ones with signatures that
> have already been added to proxy.
>             if (!methodMap.containsKey(new MethodSignature(m))) {
>               methodMap.put(new MethodSignature(m), null);
>               _classFab.addMethod(Modifier.PUBLIC, new
> MethodSignature(m), builder.toString());
>             }
>             toString |= ClassFabUtils.isToString(m);
>         }
> 
>         if (!toString)
>             ClassFabUtils.addToStringMethod(
>                 _classFab,
>                 "<"
>                     + _type
>                     + " for "
>                     + _point.getExtensionPointId()
>                     + "("
>                     + _serviceInterface.getName()
>                     + ")>");
> 
> 
>     }
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: hivemind-user-help@jakarta.apache.org
> 
> 



-- 
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Jakarta Tapestry
Creator, Jakarta HiveMind
http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org


Re: Service implementing multiple interfaces

Posted by Howard Lewis Ship <hl...@gmail.com>.
Thanks for the bug and the fix (which needs to be applied in a couple
of different places). If you could add a JIRA bug, that would be
great!


On Wed, 08 Sep 2004 17:31:15 +0200, Strutynski, Oliver
<ol...@sdm-research.de> wrote:
> For now I have worked around this by adding  some code to
> ProxyBuilder.addServiceMethods that avoids that methods are being added
> twice. Not sure if this is a good patch, as addServiceMethods should
> probably check, if these methods are really defined in different
> interfaces. But works for now. Code below.
> 
> This issue is related to issue 39
> (http://issues.apache.org/jira/browse/HIVEMIND-39). Here combining two
> interfaces into one was suggested as a way to write a service that has
> multiple interfaces, but the fact that two interfaces ARE ALLOWED to
> have similar methods was not taken into account.
> 
> My new ProxyBuilder.addServiceMethods():
> 
>     public void addServiceMethods(String indirection)
>     {
>         // use a local map to remember all method signatures
>         java.util.Map methodMap = new java.util.HashMap();
>         BodyBuilder builder = new BodyBuilder();
>         boolean toString = false;
> 
>         Method[] methods = _serviceInterface.getMethods();
>         for (int i = 0; i < methods.length; i++)
>         {
>             Method m = methods[i];
> 
>             builder.clear();
>             builder.begin();
>             builder.add("return ($r) ");
>             builder.add(indirection);
>             builder.add(".");
>             builder.add(m.getName());
>             builder.addln("($$);");
>             builder.end();
>             // only add new methods, ignore ones with signatures that
> have already been added to proxy.
>             if (!methodMap.containsKey(new MethodSignature(m))) {
>               methodMap.put(new MethodSignature(m), null);
>               _classFab.addMethod(Modifier.PUBLIC, new
> MethodSignature(m), builder.toString());
>             }
>             toString |= ClassFabUtils.isToString(m);
>         }
> 
>         if (!toString)
>             ClassFabUtils.addToStringMethod(
>                 _classFab,
>                 "<"
>                     + _type
>                     + " for "
>                     + _point.getExtensionPointId()
>                     + "("
>                     + _serviceInterface.getName()
>                     + ")>");
> 
> 
>     }
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: hivemind-user-help@jakarta.apache.org
> 
> 



-- 
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Jakarta Tapestry
Creator, Jakarta HiveMind
http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org