You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hivemind.apache.org by Catalin Grigoroscuta <c....@moodmedia.ro> on 2005/07/22 10:58:22 UTC

Using Hivemind in an existing application

Hello,

I'm working on a (quite large) application, split in several modules, 
and I want to start managing inter-modules dependencies using Hivemind 
(sort of like Eclipse plugin extension mechanism).
It seems like Hivemind configuration-point and service mechanism is 
exactly what I need (although I would need module lifecycle, but is not 
such important as I already have built a mechanism for that).

I want to add hivemind little by little, without major changes in the 
application - in other words, I need an on-the-fly migration, not a 
stop-and-change-everything one. The non-intrusiveness principle of 
Hivemind is great in this aspect.

However, here are the first issues I ran into:

1. I have something similar to services, implemented as singletons. I 
want to change those to hivemind services with singletons model, but 
this should be transparent for the rest of the application - i.e. if 
other parts of the code use this as a normal singleton, it should work.
The problem is in telling Hivemind to get the service implementation 
using the singleton getter method (called getInstance). Hivemind seems 
to always want to instantiate the class itself using a constructor, or 
my constructor is private and must remain so.
What I would need is a way to specify in <invoke-factory> to use the 
static method (getInstance) of the class to instantiate it instead of 
the constructor.

2. Same problem with configuration points: I have main configuration 
classes implemented as singletons, but there is no way in <rules> 
section to put on the stack an object created by a static method of a 
class instead of an object created using constructor.

3. A problem with <set-configuration>: the setter method is expected to 
receive a List object. This is correct for configuration points with 
0..n cardinality, but there are some issues with configuration points 
with occurs=1.
In the (future) service class, I already have a method 
setConfiguration(Configuration), which is called now by hand. If I want 
to make that class a service, and Configuration a configuration point, I 
would have to change the method signature setConfiguration(List), and 
the list would always have one element. But this will make the service 
class look quite ugly, and I think it's also against the 
non-intrusiveness principle of Hivemind.

These are all the (major) problems I ran into.
Could somebody tell me if there are Hivemind issues indeed, or if I am 
using Hivemind in the wrong way? And maybe there are some workarounds...

Thank you,
Catalin

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


Re: Using Hivemind in an existing application

Posted by Knut Wannheden <kn...@gmail.com>.
Catalin,

On 7/22/05, Catalin Grigoroscuta <c....@moodmedia.ro> wrote:
> 
> I'm working on a (quite large) application, split in several modules,
> and I want to start managing inter-modules dependencies using Hivemind
> (sort of like Eclipse plugin extension mechanism).
> It seems like Hivemind configuration-point and service mechanism is
> exactly what I need (although I would need module lifecycle, but is not
> such important as I already have built a mechanism for that).
> 

As you've correctly noticed HiveMind doesn't define and manage a
lifecycle for modules. This in turn means that if you want to add /
remove / update a module you will have to recreate the HiveMind
Registry. I just thought you should be aware of that, in case you not
already were :-)

> I want to add hivemind little by little, without major changes in the
> application - in other words, I need an on-the-fly migration, not a
> stop-and-change-everything one. The non-intrusiveness principle of
> Hivemind is great in this aspect.
> 
> However, here are the first issues I ran into:
> 
> 1. I have something similar to services, implemented as singletons. I
> want to change those to hivemind services with singletons model, but
> this should be transparent for the rest of the application - i.e. if
> other parts of the code use this as a normal singleton, it should work.
> The problem is in telling Hivemind to get the service implementation
> using the singleton getter method (called getInstance). Hivemind seems
> to always want to instantiate the class itself using a constructor, or
> my constructor is private and must remain so.
> What I would need is a way to specify in <invoke-factory> to use the
> static method (getInstance) of the class to instantiate it instead of
> the constructor.
> 

You could of course implement your own service implementation factory.
It is currently although still somewhat cumbersome to implement a
factory which should extend the features of BuilderFactory. We are
looking into simplifying this. If your factory OTOH doesn't require
many features (e.g. no autowiring) then it's a simple task.

Another option you have is to make the HiveMind Registry statically
available and have the various getInstance() methods delegate to that.

> 2. Same problem with configuration points: I have main configuration
> classes implemented as singletons, but there is no way in <rules>
> section to put on the stack an object created by a static method of a
> class instead of an object created using constructor.
> 

Using <custom> you can use your custom rules. Or again, your singleton
accessors could delegate to the HiveMind Registry...

> 3. A problem with <set-configuration>: the setter method is expected to
> receive a List object. This is correct for configuration points with
> 0..n cardinality, but there are some issues with configuration points
> with occurs=1.
> In the (future) service class, I already have a method
> setConfiguration(Configuration), which is called now by hand. If I want
> to make that class a service, and Configuration a configuration point, I
> would have to change the method signature setConfiguration(List), and
> the list would always have one element. But this will make the service
> class look quite ugly, and I think it's also against the
> non-intrusiveness principle of Hivemind.
> 

You're the second person to ask about this in the last few days. This
is definitely on our TODO list.

Regards,

--knut

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


RE: Using Hivemind in an existing application

Posted by James Carman <ja...@carmanconsulting.com>.
The idea Knut proposed was that you come up with a single place to ask for
your HiveMind registry...

public class HiveMindRegistry
{
  private static final Regisry instance =
RegistryBuilder.constructDefaultRegistry();

  public static Registry getInstance()
  {   
    return instance;
  }
}

Then, in your singleton service's getInstance() method:

public static MyService 
{
  public static MyService getInstance()
  {
    return ( MyService
)HiveMindRegistry.getInstance().getService(MyService.class);
  }
}

Of course, in a real dependency injection-oriented system, you'd just
declare setters for the MyService and HiveMind would inject it for you
rather than looking up the singleton using a getInstance() method.  But,
Catalin said that she wanted to gradually migrate to HiveMind, so I guess
that's not possible.


-----Original Message-----
From: karthik.nar [mailto:karthik.nar@gmail.com] 
Sent: Friday, October 13, 2006 3:20 AM
To: user@hivemind.apache.org
Subject: Re: Using Hivemind in an existing application


catalin,

were you able to figure a way to use a static method in point#2 below?

2. In point two, I meant some sort of <create-object> that uses a static 
getInstance method instead of calling the constructor.

i have a requirement where i want to pass a new instance of an apache
commons Log object from the Logger in the 
    <invoke-factory>
      <construct class=blah>
         <set-object property="log"
value="instance:@org.apache.log4j.Logger@getLog()" />
      </construct>
    </invoke-factory>


I've not be able to figure out how to do it!

        <set-object property="log"
value="instance:@org.apache.log4j.Logger@getLog()" />

or

        <set-object property="log"
value="instance:org.apache.log4j.Logger.getLog()" />

or anything else?!



-- 
View this message in context:
http://www.nabble.com/Using-Hivemind-in-an-existing-application-tf165498.htm
l#a6790990
Sent from the Hivemind - User mailing list archive at Nabble.com.



Re: Using Hivemind in an existing application

Posted by "karthik.nar" <ka...@gmail.com>.
catalin,

were you able to figure a way to use a static method in point#2 below?

2. In point two, I meant some sort of <create-object> that uses a static 
getInstance method instead of calling the constructor.

i have a requirement where i want to pass a new instance of an apache
commons Log object from the Logger in the 
    <invoke-factory>
      <construct class=blah>
         <set-object property="log"
value="instance:@org.apache.log4j.Logger@getLog()" />
      </construct>
    </invoke-factory>


I've not be able to figure out how to do it!

        <set-object property="log"
value="instance:@org.apache.log4j.Logger@getLog()" />

or

        <set-object property="log"
value="instance:org.apache.log4j.Logger.getLog()" />

or anything else?!



-- 
View this message in context: http://www.nabble.com/Using-Hivemind-in-an-existing-application-tf165498.html#a6790990
Sent from the Hivemind - User mailing list archive at Nabble.com.