J Aaron Farr wrote:

Hello.

As best as I can tell there are a couple of different conventions for naming
your services:

1. Interface Names

The service is named after the java interface which defines it's contract:

 MyService myservice = (MyService) m_manager.lookup("org.proj.MyService");
or
 MyService myservice = (MyService)
m_manager.lookup(MyService.class.getName());

(where m_manager = ServiceManager instance)

2. ROLE Names

Similiar to above, but the name itself is defined by a static ROLE variable:

  public interface MyService {
     public static String ROLE = MyService.class.getName();
  }

MyService myservice = (MyService) m_manager.lookup(MyService.ROLE);

3. Descriptive String Names

  Some "arbitrary" descriptive string which is defined in a meta-info or roles
file. I've seen this in Merlin and in EOB (in examples):

MyService myservice = (MyService) m_manager.lookup( "MyService" );


Is there a best practice?



Yep - option (3).


You know I was going to say that didn't you!

:-)

It seems to me that (1) is the most commonly used, though I've used the ROLE
method quite a bit myself.  (3) doesn't look like a good idea, or is there a
reasonable use case for it?


When you have multiple service that have the same service interface but represent different roles to the target component you can take on of two approaches - explicitly assigning a name to the role (Merlin/Phoenix style) or use a selector (Fortress/ECM) style. The benefits of the assigned name approach is that you can do complete assembly prior to deployment - in fact you can do complete assembly as a step in a development test phase (without instantiating any components).



Did I miss any? Also if I recall, there was a question about why we use Strings at all instead of Class objects.


I personally prefer role names because I can use a name that is meaningful relative to the component that is acquiring a service. For example, I may have a component that has two dependencies where both refer to a common KeyStore service. The share the same interface so I cannot use KeyStore.class.getName() or KeyStore.ROLE.


But I can use something even better:

 public void service( ServiceManager manager )
 {
     KeyStore trusted = manager.lookup( "trusted" );
     KeyStore credentials = manager.lookup( "credentials" );
 }

This also significantly improved the readability of the code because the keys are in context.

Cheers, Steve.

--

Stephen J. McConnell
mailto:[EMAIL PROTECTED]
http://www.osm.net

Sent via James running under Merlin as an NT service.
http://avalon.apache.org/sandbox/merlin




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to