hivemind-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tom Davies <>
Subject Newbie questions
Date Tue, 09 Nov 2004 05:07:58 GMT

I've just started playing with creating my first HiveMind services, to
create JDO persistence managers and what I have ended up with is shown

My questions are:

1. I'd like to avoid the pattern where my service implementation looks like:

  create a Foo using a third-party factory

Foo get()
  return the Foo

I'd rather have a service who's type is Foo, but Foo may be a concrete
type (e.g. I'd like a properties service, but Properties is concrete)
or may be a third-party interface which needs a bit of code to
instantiate (i.e. more than just passing some parameters to a
constructor) -- PersistenceManagerFactory is an example of this.

Can I get rid of the 'get()' above?

2. Can I parameterise services? In this example I need three services
for each data source. It would be nice if I could declare the
PersistenceManagerFactory and PersistenceManager services once, and
have the declarations of the various PM services pass them parameters.

Or maybe I don't need todo these things -- I'm still getting to grips
with the HiveMind philosophy.


<?xml version="1.0"?>
<module id="" version="1.0.0">
    <!-- create a persistence manager factory using the properties
file name passed to the constructor -->
			<construct class="">
    <!-- create a persistence manager using the PM factory service above.
         Implement Discardable to close the PM appropriately -->
	<service-point id="PersistenceManager"
		<invoke-factory model="threaded">
			<construct class="">
    <!-- make the persistence manager easier to get by exposing the
         property of the PM service above as a service in its own right -->
	<service-point id="PM" interface="javax.jdo.PersistenceManager">
		<invoke-factory service-id="hivemind.lib.ServicePropertyFactory">
			<construct service-id="PersistenceManager" property="persistenceManager"/> 

public class PersistenceManagerServiceImpl implements
        PersistenceManagerService, Discardable {
    public void threadDidDiscardService() {
        _pm = null;

    private PersistenceManager _pm;

    public PersistenceManagerServiceImpl(
            PersistenceManagerFactoryService pmFactoryService) {
        _pm = pmFactoryService.get().getPersistenceManager();

    public PersistenceManager getPersistenceManager() {
        return _pm;

public class PersistenceManagerFactoryServiceImpl implements
        PersistenceManagerFactoryService {

    private PersistenceManagerFactory pmf = null;

    public PersistenceManagerFactoryServiceImpl(String propertiesFile) {
        Properties props = new Properties();
        InputStream propertyRes = Persistence.class.getClassLoader()
        try {
        } catch (IOException ioe) {
            throw new RuntimeException("error loading properties '"
                    + propertiesFile + "'", ioe);
        pmf = JDOHelper.getPersistenceManagerFactory(props);

    public PersistenceManagerFactory get() {
        return pmf;


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message