ProgramixGenericLib v5.0.1

com.programix.da2
Class DAExchange

java.lang.Object
  extended by com.programix.da2.DAExchange

public class DAExchange
extends Object

Used to exchange GenericDA's among friends. The share(Class, GenericDA) method is called to offer up a DA for others to use. The getDA(Class, long) method is called to search for a DA previously shared and/or to wait for it to be shared (the msTimeout value is use to limit the amount of time that can be spent waiting).

This class can be used as a way to have several DA implementations attempt to be simultaneously simultaneously initialized—even if some DA implementations depend on other DA implementations (as long as there isn't a circular dependence!)

Author:
Paul Hyde

Constructor Summary
DAExchange()
           
 
Method Summary
 DASource createDASourceView()
          Creates a lightweight view of the DAExchange as a DASource.
<T extends GenericDA>
T
getDA(Class<T> daInterfaceType, long msTimeout)
          Returns a DA of the specified daInterfaceType potentially waiting for it to become available.
 void share(Class<? extends GenericDA> daInterfaceType, GenericDA daImplementation)
          Called to share the specified DA type and implementation.
 void shutdown()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DAExchange

public DAExchange()
Method Detail

share

public void share(Class<? extends GenericDA> daInterfaceType,
                  GenericDA daImplementation)
           throws DAException
Called to share the specified DA type and implementation.

Parameters:
daInterfaceType - the DA interface type to offer up for sharing.
daImplementation - the implementation of the specified interface type.
Throws:
DAException

getDA

public <T extends GenericDA> T getDA(Class<T> daInterfaceType,
                                     long msTimeout)
                          throws NotYetAvailableDAException,
                                 DAException
Returns a DA of the specified daInterfaceType potentially waiting for it to become available.

Parameters:
daInterfaceType - the DA type to search for (or wait for).
msTimeout - the maximum number of milliseconds to wait for the DA to become available.
Returns:
the requested DA implementation
Throws:
NotYetAvailableDAException - if the requested DA is still not available after waiting for the specified timeout. Calling this method again might be successful.
DAException - if something else goes wrong.

shutdown

public void shutdown()

createDASourceView

public DASource createDASourceView()
                            throws ShutdownDAException
Creates a lightweight view of the DAExchange as a DASource. Calling shutdown() on this DASource will also shutdown the DAExchange.

Throws:
ShutdownDAException - if this has already been shutdown

ProgramixGenericLib v5.0.1

Copyright © 2001-2009 Programix Incorporated. All rights reserved. ProgramixGenericLib is free and is OSI Certified Open Source Software under the BSD license.