org.sapia.ubik.ioc.spring
Class NamingServiceBean

java.lang.Object
  extended by org.sapia.ubik.ioc.spring.NamingServiceBean
All Implemented Interfaces:
NamingService, JndiDiscoListener, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean

public class NamingServiceBean
extends java.lang.Object
implements NamingService, JndiDiscoListener, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean

This singleton bean acts as a bridge to the Ubik JNDI server. It is internally used by the BeanExporterPostProcessor and BeanImporterPostProcessor to respectively bind and lookup remote services.

This bean robustly discovers Ubik JNDI servers that appear in the domain if none are present at initialization time. The bound services are thus cached until a JNDI server is available.

Author:
yduchesne

Constructor Summary
NamingServiceBean()
           
 
Method Summary
 void afterPropertiesSet()
           
 void bind(java.lang.String name, java.lang.Object o)
          Binds the given object to the remote Ubik JNDI provider to which this instance corresponds.
 void destroy()
           
protected  DiscoveryHelper getDiscoHelper(EventChannel channel)
           
protected  DiscoveryHelper getDiscoHelper(java.lang.String domain, java.lang.String mcastHost, int mcastPort)
           
 EventChannel getEventChannel()
           
protected  javax.naming.InitialContext getInitialContext(java.lang.String domain, java.lang.String host, int port)
           
 java.lang.Object lookup(java.lang.String name)
          Looks up the object under the given name.
 void onJndiDiscovered(javax.naming.Context context)
           
 void register(ServiceDiscoListener listener)
          Registers the given listener with this instance.
 void setDomain(java.lang.String domain)
           
 NamingServiceBean setJndiHost(java.lang.String host)
           
 NamingServiceBean setJndiPort(int port)
           
 void setMulticastAddress(java.lang.String addr)
           
 void setMulticastPort(int port)
           
 void unregister(ServiceDiscoListener listener)
          Unregisters the given listener from this instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NamingServiceBean

public NamingServiceBean()
Method Detail

setJndiHost

public NamingServiceBean setJndiHost(java.lang.String host)
Parameters:
host - the host of the remote Ubik JNDI server.

setJndiPort

public NamingServiceBean setJndiPort(int port)
Parameters:
port - the port of the remote Ubik JNDI server.

setDomain

public void setDomain(java.lang.String domain)
Parameters:
domain - the domain of the remote Ubik JNDI server.

setMulticastAddress

public void setMulticastAddress(java.lang.String addr)
Parameters:
addr - the multicast address to use for discovering remote JNDI servers.

setMulticastPort

public void setMulticastPort(int port)
Parameters:
port - the multicast port to use for discovering remote JNDI servers.

getEventChannel

public EventChannel getEventChannel()

bind

public void bind(java.lang.String name,
                 java.lang.Object o)
          throws javax.naming.NamingException
Description copied from interface: NamingService
Binds the given object to the remote Ubik JNDI provider to which this instance corresponds.

Specified by:
bind in interface NamingService
Parameters:
name - the name under which to bind the object.
o - the object to bind.
Throws:
javax.naming.NamingException

lookup

public java.lang.Object lookup(java.lang.String name)
                        throws javax.naming.NamingException,
                               javax.naming.NameNotFoundException
Description copied from interface: NamingService
Looks up the object under the given name.

Specified by:
lookup in interface NamingService
Parameters:
name - the name of the remote object to lookup.
Throws:
javax.naming.NamingException
javax.naming.NameNotFoundException

register

public void register(ServiceDiscoListener listener)
Description copied from interface: NamingService
Registers the given listener with this instance.

Specified by:
register in interface NamingService
Parameters:
listener - a ServiceDiscoListener.

unregister

public void unregister(ServiceDiscoListener listener)
Description copied from interface: NamingService
Unregisters the given listener from this instance.

Specified by:
unregister in interface NamingService
Parameters:
listener - a ServiceDiscoListener.

destroy

public void destroy()
             throws java.lang.Exception
Specified by:
destroy in interface org.springframework.beans.factory.DisposableBean
Throws:
java.lang.Exception

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.Exception
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
java.lang.Exception

onJndiDiscovered

public void onJndiDiscovered(javax.naming.Context context)
Specified by:
onJndiDiscovered in interface JndiDiscoListener

getDiscoHelper

protected DiscoveryHelper getDiscoHelper(java.lang.String domain,
                                         java.lang.String mcastHost,
                                         int mcastPort)
                                  throws java.io.IOException
Throws:
java.io.IOException

getDiscoHelper

protected DiscoveryHelper getDiscoHelper(EventChannel channel)
                                  throws java.io.IOException
Throws:
java.io.IOException

getInitialContext

protected javax.naming.InitialContext getInitialContext(java.lang.String domain,
                                                        java.lang.String host,
                                                        int port)
                                                 throws javax.naming.NamingException
Throws:
javax.naming.NamingException


Copyright © 2010 Sapia OSS. All Rights Reserved.