You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2002/04/05 09:02:34 UTC

cvs commit: jakarta-avalon-apps/enterprise/time/src/java/org/apache/time DefaultTIO.java DefaultTimerEventHandler.java DefaultTimerEventService.java DefaultUTO.java Initializer.java TimeProvider.java TimeProvider.xinfo DefaultTimeService.java

mcconnell    02/04/04 23:02:34

  Modified:    enterprise/time build.properties build.xml
               enterprise/time/src/java/org/apache/time DefaultTIO.java
                        DefaultTimerEventHandler.java
                        DefaultTimerEventService.java DefaultUTO.java
                        Initializer.java TimeProvider.java
                        TimeProvider.xinfo
  Removed:     enterprise/time/src/java/org/apache/time
                        DefaultTimeService.java
  Log:
  rationalization of service dependecies
  
  Revision  Changes    Path
  1.2       +2 -0      jakarta-avalon-apps/enterprise/time/build.properties
  
  Index: build.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/enterprise/time/build.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- build.properties	8 Mar 2002 05:55:06 -0000	1.1
  +++ build.properties	5 Apr 2002 07:02:34 -0000	1.2
  @@ -3,6 +3,8 @@
   # The pss.properties file is read in by the build.xml file.  
   #
   
  +project.title=Apache Time Service
  +
   MAJOR=2
   MINOR=0
   MICRO=0
  
  
  
  1.5       +7 -3      jakarta-avalon-apps/enterprise/time/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/enterprise/time/build.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- build.xml	14 Mar 2002 10:15:23 -0000	1.4
  +++ build.xml	5 Apr 2002 07:02:34 -0000	1.5
  @@ -14,7 +14,7 @@
         Description
         -----------
   
  -      CORBA Time Service.
  +      ${project.title}
   
         Main Targets:
         -------------
  @@ -209,11 +209,11 @@
          </fileset>
       </copy>
       <javadoc destdir="${javadoc.root.path}/${ant.project.name}" 
  -	doctitle="&lt;h1&gt;OMG Time Service 1.0&lt;/h1&gt;" 
  +	doctitle="&lt;h1&gt;${project.title} ${VERSION}&lt;/h1&gt;" 
         noindex="false" author="false" 
         use="true"
         overview="${overview.html}"
  -	windowtitle="Apache Time Service" 
  +	windowtitle="${project.title}" 
         bottom="&lt;a href='{@docRoot}/LICENSE.HTML'/&gt;License, Disclaimer and due credits.&lt;/a&gt;"
         additionalparam="-breakiterator -J-Xmx128m"
         packagenames="org.*" 
  @@ -273,6 +273,10 @@
         </fileset>
   
         <fileset dir="${orb.lib.path}">
  +         <include name="*.jar"/>
  +      </fileset>
  +
  +      <fileset dir="${orb.dist.path}">
            <include name="*.jar"/>
         </fileset>
   
  
  
  
  1.2       +18 -22    jakarta-avalon-apps/enterprise/time/src/java/org/apache/time/DefaultTIO.java
  
  Index: DefaultTIO.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/enterprise/time/src/java/org/apache/time/DefaultTIO.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultTIO.java	8 Mar 2002 05:55:06 -0000	1.1
  +++ DefaultTIO.java	5 Apr 2002 07:02:34 -0000	1.2
  @@ -17,23 +17,19 @@
    */
   public class DefaultTIO extends TIOPOA
   {
  -    ORB m_orb;
       IntervalT m_interval;
   
  -    public DefaultTIO(ORB orb)
  +    public DefaultTIO()
       {
  -        m_orb = orb;
       }
   
  -    public DefaultTIO(ORB orb, IntervalT intervalt)
  +    public DefaultTIO(IntervalT intervalt)
       {
  -        m_orb = orb;
           m_interval = intervalt;
       }
   
  -    public DefaultTIO(ORB orb, long l, long l1)
  +    public DefaultTIO(long l, long l1)
       {
  -        m_orb = orb;
           m_interval = new IntervalT(l, l1);
       }
   
  @@ -53,28 +49,28 @@
           }
           if(l - l1 < m_interval.lower_bound && l + l1 > m_interval.upper_bound)
           {
  -            tioholder.value = _this(m_orb);
  +            tioholder.value = _this(this._orb());
               return OverlapType.OTContained;
           }
           if(l - l1 > m_interval.lower_bound && l - l1 < m_interval.upper_bound)
           {
               long l2 = l - l1;
               long l4 = m_interval.upper_bound;
  -            DefaultTIO tioimpl1 = new DefaultTIO(m_orb, l2, l4);
  -            tioholder.value = tioimpl1._this(m_orb);
  +            DefaultTIO tioimpl1 = new DefaultTIO( l2, l4);
  +            tioholder.value = tioimpl1._this(this._orb());
               return OverlapType.OTOverlap;
           }
           if(l + l1 > m_interval.lower_bound && l + l1 < m_interval.upper_bound)
           {
               long l3 = m_interval.lower_bound;
               long l5 = l + l1;
  -            DefaultTIO tioimpl2 = new DefaultTIO(m_orb, l3, l5);
  -            tioholder.value = tioimpl2._this(m_orb);
  +            DefaultTIO tioimpl2 = new DefaultTIO( l3, l5);
  +            tioholder.value = tioimpl2._this(this._orb());
               return OverlapType.OTOverlap;
           } else
           {
  -            DefaultTIO tioimpl = new DefaultTIO(m_orb);
  -            tioholder.value = tioimpl._this(m_orb);
  +            DefaultTIO tioimpl = new DefaultTIO();
  +            tioholder.value = tioimpl._this(this._orb());
               return OverlapType.OTNoOverlap;
           }
       }
  @@ -91,35 +87,35 @@
           }
           if(l - l1 < m_interval.lower_bound && l + l1 > m_interval.upper_bound)
           {
  -            tioholder.value = _this(m_orb);
  +            tioholder.value = _this(this._orb());
               return OverlapType.OTContained;
           }
           if(l - l1 > m_interval.lower_bound && l - l1 < m_interval.upper_bound)
           {
               long l2 = l - l1;
               long l4 = m_interval.upper_bound;
  -            DefaultTIO tioimpl1 = new DefaultTIO(m_orb, l2, l4);
  -            tioholder.value = tioimpl1._this(m_orb);
  +            DefaultTIO tioimpl1 = new DefaultTIO( l2, l4);
  +            tioholder.value = tioimpl1._this(this._orb());
               return OverlapType.OTOverlap;
           }
           if(l + l1 > m_interval.lower_bound && l + l1 < m_interval.upper_bound)
           {
               long l3 = m_interval.lower_bound;
               long l5 = l + l1;
  -            DefaultTIO tioimpl2 = new DefaultTIO(m_orb, l3, l5);
  -            tioholder.value = tioimpl2._this(m_orb);
  +            DefaultTIO tioimpl2 = new DefaultTIO( l3, l5);
  +            tioholder.value = tioimpl2._this(this._orb());
               return OverlapType.OTOverlap;
           } else
           {
  -            DefaultTIO tioimpl = new DefaultTIO(m_orb);
  -            tioholder.value = tioimpl._this(m_orb);
  +            DefaultTIO tioimpl = new DefaultTIO();
  +            tioholder.value = tioimpl._this(this._orb());
               return OverlapType.OTNoOverlap;
           }
       }
   
       public UTO time()
       {
  -        DefaultUTO uto = new DefaultUTO( m_orb, 
  +        DefaultUTO uto = new DefaultUTO(
             (m_interval.upper_bound - m_interval.lower_bound) + m_interval.lower_bound, 
             m_interval.upper_bound - m_interval.lower_bound, 
             (short)0 );
  
  
  
  1.3       +2 -2      jakarta-avalon-apps/enterprise/time/src/java/org/apache/time/DefaultTimerEventHandler.java
  
  Index: DefaultTimerEventHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/enterprise/time/src/java/org/apache/time/DefaultTimerEventHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultTimerEventHandler.java	9 Mar 2002 04:50:20 -0000	1.2
  +++ DefaultTimerEventHandler.java	5 Apr 2002 07:02:34 -0000	1.3
  @@ -40,7 +40,7 @@
       long m_set_time;
       Thread m_thread;
   
  -    public DefaultTimerEventHandler(DefaultTimerEventService service, ORB orb, PushConsumer cosumer, long value)
  +    public DefaultTimerEventHandler(DefaultTimerEventService service, PushConsumer cosumer, long value)
       {
           m_status = null;
           m_data = null;
  @@ -49,7 +49,7 @@
           m_last_relative = 0L;
           m_thread = null;
           m_parent = service;
  -        m_orb = orb;
  +        m_orb = this._orb();
           m_event_channel = cosumer;
           m_status = EventStatus.ESTimeCleared;
           m_current_time = value;
  
  
  
  1.2       +5 -5      jakarta-avalon-apps/enterprise/time/src/java/org/apache/time/DefaultTimerEventService.java
  
  Index: DefaultTimerEventService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/enterprise/time/src/java/org/apache/time/DefaultTimerEventService.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultTimerEventService.java	8 Mar 2002 05:55:06 -0000	1.1
  +++ DefaultTimerEventService.java	5 Apr 2002 07:02:34 -0000	1.2
  @@ -25,16 +25,16 @@
       Vector m_vector;
       ORB m_orb;
   
  -    public DefaultTimerEventService(ORB orb)
  +    public DefaultTimerEventService()
       {
  -        m_orb = orb;
  +        m_orb = this._orb();
           m_vector = new Vector();
       }
   
       public TimerEventHandler register(PushConsumer consumer, Any any)
       {
           DefaultTimerEventHandler timereventhandlerimpl = new DefaultTimerEventHandler(
  -          this, m_orb, consumer, (new Date()).getTime());
  +          this, consumer, (new Date()).getTime());
           timereventhandlerimpl.set_data(any);
           m_vector.addElement(timereventhandlerimpl);
           return timereventhandlerimpl._this( m_orb );
  @@ -47,8 +47,8 @@
   
       public UTO event_time(TimerEventT timereventt)
       {
  -        DefaultUTO uto = new DefaultUTO( m_orb, timereventt.utc);
  -        return uto._this( m_orb );
  +        DefaultUTO uto = new DefaultUTO( timereventt.utc);
  +        return uto._this( this._orb() );
       }
   
   }
  
  
  
  1.2       +9 -13     jakarta-avalon-apps/enterprise/time/src/java/org/apache/time/DefaultUTO.java
  
  Index: DefaultUTO.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/enterprise/time/src/java/org/apache/time/DefaultUTO.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultUTO.java	8 Mar 2002 05:55:06 -0000	1.1
  +++ DefaultUTO.java	5 Apr 2002 07:02:34 -0000	1.2
  @@ -22,24 +22,20 @@
       private long m_uto_time;
       private long m_uto_inaccuracy;
       private short m_uto_tdf;
  -    private ORB m_orb;
   
  -    public DefaultUTO(ORB orb)
  +    public DefaultUTO()
       {
  -        m_orb = orb;
       }
   
  -    public DefaultUTO(ORB orb, UtcT utct)
  +    public DefaultUTO(UtcT utct)
       {
  -        m_orb = orb;
           m_uto_time = utct.time;
           m_uto_tdf = utct.tdf;
           m_uto_inaccuracy = (utct.inacchi << 4) + utct.inacclo;
       }
   
  -    public DefaultUTO(ORB orb, long l, long l1, short word0)
  +    public DefaultUTO(long l, long l1, short word0)
       {
  -        m_orb = orb;
           m_uto_time = l;
           m_uto_inaccuracy = l1;
           m_uto_tdf = word0;
  @@ -69,8 +65,8 @@
       public UTO absolute_time()
       {
           long l = (new Date()).getTime();
  -        DefaultUTO DefaultUTO = new DefaultUTO(m_orb, l, 0L, (short)0);
  -        return DefaultUTO._this(m_orb);
  +        DefaultUTO DefaultUTO = new DefaultUTO(l, 0L, (short)0);
  +        return DefaultUTO._this( this._orb() );
       }
   
       public TimeComparison compare_time(ComparisonType comparisontype, UTO uto)
  @@ -113,14 +109,14 @@
               l1 = m_uto_time;
               l = uto.time();
           }
  -        DefaultTIO tio = new DefaultTIO(m_orb, l, l1);
  -        return tio._this(m_orb);
  +        DefaultTIO tio = new DefaultTIO(l, l1);
  +        return tio._this( this._orb());
       }
   
       public TIO interval()
       {
  -        DefaultTIO tio = new DefaultTIO(m_orb, m_uto_time - m_uto_inaccuracy, m_uto_time + m_uto_inaccuracy);
  -        return tio._this(m_orb);
  +        DefaultTIO tio = new DefaultTIO(m_uto_time - m_uto_inaccuracy, m_uto_time + m_uto_inaccuracy);
  +        return tio._this( this._orb());
       }
   
   }
  
  
  
  1.4       +42 -19    jakarta-avalon-apps/enterprise/time/src/java/org/apache/time/Initializer.java
  
  Index: Initializer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/enterprise/time/src/java/org/apache/time/Initializer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Initializer.java	13 Mar 2002 11:02:03 -0000	1.3
  +++ Initializer.java	5 Apr 2002 07:02:34 -0000	1.4
  @@ -9,7 +9,7 @@
   import org.omg.CORBA.ORB;
   import org.omg.CORBA.Policy;
   import org.omg.CORBA.LocalObject;
  -import org.omg.PortableServer.LifespanPolicyValue;
  +import org.omg.PortableServer.POA;
   import org.omg.PortableInterceptor.ORBInitInfo;
   import org.omg.PortableInterceptor.ORBInitializer;
   
  @@ -21,7 +21,10 @@
   import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.avalon.framework.service.DefaultServiceManager;
   import org.apache.avalon.framework.activity.Disposable;
  +import org.apache.orb.POAContext;
  +import org.apache.orb.DefaultPOAContext;
   
   import org.openorb.CORBA.LoggableLocalObject;
   
  @@ -37,7 +40,7 @@
       private Configuration m_config;
       private Context m_context;
       private TimeProvider m_target;
  -    private boolean m_flag = false;
  +    private boolean m_initialized = false;
   
       //=================================================================
       // Contextualizable
  @@ -79,11 +82,16 @@
       public void pre_init( ORBInitInfo info )
       {
   
  +    }
  +  
  +    /**
  +     * Post initalization of the interceptor invoked by the
  +     * ORB in which this interceptor is installed.
  +     * @param info  
  +     */
  +    public void post_init( ORBInitInfo info ) 
  +    {
           if( getLogger().isDebugEnabled() ) getLogger().debug("Initializer" );
  -        DefaultContext context = new DefaultContext( m_context );
  -        context.put( "ORB_INIT_INFO", info );
  -        context.makeReadOnly();
  -        m_context = context;
   
           //
           // create an TimePOA
  @@ -91,28 +99,33 @@
           
           try
           {
  -            if( getLogger().isDebugEnabled() ) getLogger().debug("creating TimePOA" );
  +            POA root = (POA) info.resolve_initial_references("RootPOA");
  +            if( getLogger().isDebugEnabled() ) getLogger().debug("creating POA" );
               m_target = new TimeProvider();
               m_target.enableLogging( getLogger().getChildLogger("provider") );
  -            m_target.configure( m_config.getChild("provider") );
               m_target.contextualize( m_context );
  +            m_target.configure( m_config.getChild("provider") );
  +            DefaultServiceManager manager = new DefaultServiceManager();
  +            manager.put( POAContext.POA_KEY, new DefaultPOAContext( root, null ) );
  +            manager.makeReadOnly();
  +            m_target.service( manager );
               m_target.initialize();
  -            m_flag = true;
           }
           catch( Throwable e)
           {
               throw new CascadingRuntimeException( "Unable to instantiate embedded server.", e);
           }
  -    }
  -  
  -    /**
  -     * Post initalization of the interceptor invoked by the
  -     * ORB in which this interceptor is installed.
  -     * @param info  
  -     */
  -    public void post_init( ORBInitInfo info ) 
  -    {
  -        if( !m_flag ) return;
  +
  +        try
  +        {
  +	      info.register_initial_reference( 
  +              "TimeService", m_target._this_object() );
  +        }
  +        catch( Throwable e)
  +        {
  +            throw new CascadingRuntimeException( "Unable to register server.", e);
  +        }
  +
           try
           {
               m_target.start();
  @@ -121,6 +134,9 @@
           {
               throw new CascadingRuntimeException( "Unable to start embedded server.", e);
           }
  +
  +        m_initialized = true;
  +
       }
   
       //=======================================================================
  @@ -133,6 +149,12 @@
       */
       public void dispose()
       {
  +        if( !m_initialized )
  +        {
  +            m_target = null;
  +            return;
  +        }
  +
           if( getLogger().isDebugEnabled() ) getLogger().debug("initializer disposal" );
           try
           {
  @@ -145,6 +167,7 @@
           }
           finally
           {
  +            m_target.dispose();
               m_target = null;
               m_config = null;
               m_context = null;
  
  
  
  1.2       +258 -201  jakarta-avalon-apps/enterprise/time/src/java/org/apache/time/TimeProvider.java
  
  Index: TimeProvider.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/enterprise/time/src/java/org/apache/time/TimeProvider.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TimeProvider.java	12 Mar 2002 22:20:08 -0000	1.1
  +++ TimeProvider.java	5 Apr 2002 07:02:34 -0000	1.2
  @@ -14,6 +14,7 @@
   import java.io.OutputStream;
   import java.util.Iterator;
   import java.util.Properties;
  +import java.util.Date;
   
   import org.omg.CORBA.ORB;
   import org.omg.CORBA.Policy;
  @@ -22,12 +23,15 @@
   import org.omg.PortableInterceptor.ORBInitInfoPackage.DuplicateName;
   import org.omg.PortableInterceptor.ORBInitializer;
   import org.omg.PortableServer.POA;
  +import org.omg.PortableServer.Servant;
   import org.omg.PortableServer.POAHelper;
   import org.omg.PortableServer.ImplicitActivationPolicyValue;
   import org.omg.PortableServer.LifespanPolicyValue;
   import org.omg.PortableServer.IdUniquenessPolicyValue;
   import org.omg.CosTime.TimeServiceHelper;
   import org.omg.CosTime.TimeService;
  +import org.omg.CosTime.TimeServicePOA;
  +import org.omg.PortableServer.IdAssignmentPolicyValue;
   
   import org.apache.avalon.framework.CascadingException;
   import org.apache.avalon.framework.CascadingRuntimeException;
  @@ -38,10 +42,9 @@
   import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  -import org.apache.avalon.framework.component.Component;
  -import org.apache.avalon.framework.component.Composable;
  -import org.apache.avalon.framework.component.ComponentManager;
  -import org.apache.avalon.framework.component.ComponentException;
  +import org.apache.avalon.framework.service.ServiceManager;
  +import org.apache.avalon.framework.service.ServiceException;
  +import org.apache.avalon.framework.service.Serviceable;
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Initializable;
   import org.apache.avalon.framework.activity.Executable;
  @@ -50,7 +53,8 @@
   import org.apache.avalon.phoenix.BlockContext;
   import org.apache.avalon.phoenix.Block;
   
  -import org.apache.orb.ORBFactoryService;
  +import org.apache.orb.POAContext;
  +import org.apache.orb.DefaultSingletonManager;
   import org.apache.orb.util.IOR;
   
   import org.openorb.CORBA.LoggableLocalObject;
  @@ -69,8 +73,6 @@
    * <pre>
    *   &lt;configuration&gt;
    * 
  - *     &lt;ior file="time.ior"/&gt;
  - * 
    *     &lt;!-- 
    *     The profile element declares the default inaccuracy values 
    *     that will be used by the time server. 
  @@ -86,7 +88,7 @@
    * <td>
    * The <code>Context</code> value passed to the provider is used to determin if 
    * the time server has deplyed as an Initializer in which case the provider will 
  - * be registered as an initial reference.</td></tr>
  + * be registered as an initial reference. Note: Initializer currently disabled.</td></tr>
    * <tr><td width="20%">Initalizable</td>
    * <td>
    * Creation of the Time POA and optional registration of the service as an initial reference. 
  @@ -107,97 +109,111 @@
    * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
    */
   
  -public class TimeProvider extends LoggableLocalObject
  -implements Block, Configurable, Contextualizable, Initializable, Startable, Executable, Disposable, TimeService
  +public class TimeProvider extends TimeServicePOA
  +implements Block, LogEnabled, Contextualizable, Configurable, Serviceable, 
  +Initializable, Startable, Executable, Disposable
   {
  -    //=======================================================================
  -    // static
  -    //=======================================================================
  -    
  -    private static final String ROOT_POA = "RootPOA";
   
       //=======================================================================
       // state
       //=======================================================================
   
  +   /**
  +    * Looging channel.
  +    */
  +    private Logger m_logger;
  +
  +   /**
  +    * Application context.
  +    * (not used)
  +    */
  +    private Context m_context;
  +
  +   /**
  +    * Service static configuration.
  +    */
       private Configuration m_config;
  -    private ORB m_orb;
  -    private POA m_root;
  -    private String m_ior;
  +
  +   /**
  +    * Service manager that provides dependant POA context.
  +    */
  +    private ServiceManager m_manager;
  +
  +   /**
  +    * inaccuracy value.
  +    */
       private int m_inaccuracy = 10000;
  -    private org.omg.CosTime.TimeService m_time;
  -    private static Thread m_thread;
   
      /**
  -    * Application context
  +    * Internal reference to the time service reference.
  +    */
  +    private org.omg.CosTime.TimeService m_service;
  +
  +   /**
  +    * The root POA provided via the service manager.
  +    */
  +    private POA m_root;
  +
  +   /**
  +    * Tha POA created to handle the finder.
  +    */
  +    private POA m_poa;
  +
  +   /**
  +    * Flag holding initialized state.
       */
  -    Context m_context;
  +    private boolean m_initialized = false;
  +
  +   /**
  +    * Flag holding disposed state.
  +    */
  +    private boolean m_disposed = false;
   
       //=======================================================================
  -    // Configurable
  +    // LogEnabled
       //=======================================================================
       
  -    public void configure( final Configuration config )
  -    throws ConfigurationException
  +   /**
  +    * Sets the logging channel.
  +    * @param logger the logging channel
  +    */
  +    public void enableLogging( final Logger logger )
       {
  -        m_config = config;
  +        m_logger = logger;
       }
  -    
  -    //=================================================================
  -    // Contextualizable
  -    //=================================================================
   
      /**
  -    * Invoked by the container to provide the application context.
  -    * @param context the application context
  +    * Returns the logging channel.
  +    * @return Logger the logging channel
       */
  -    public void contextualize( Context context ) throws ContextException
  +    protected Logger getLogger()
       {
  -	  m_context = context;
  +        return m_logger;
       }
   
       //=======================================================================
  -    // Initializable
  +    // Contextualizable
       //=======================================================================
  -    
  +
      /**
  -    * Invoked by the container to initalize the provider.
  -    * @exception Exception if an initialization exception occurs.
  +    * Set the component context.
  +    * @param context the component context
       */
  -    public void initialize()
  -    throws Exception
  -    {       
  -
  -        //
  -        // Create a properties argument.  Using the apache ORB loader so we get automatic
  -        // addition of default properties, unpacking of the initializer declarations
  -        // from the configuration, and propergation of the logger, context and configuration.
  -        //
  -
  -        Properties properties = new Properties();
  -
  -        properties.setProperty("openorb.IgnoreXML","true");
  -        properties.setProperty("openorb.ORBLoader","org.apache.orb.CORBA.kernel.DefaultLoader");
  -        properties.setProperty("org.omg.CORBA.ORBClass", "org.openorb.CORBA.ORB" );
  -	  properties.setProperty("org.omg.CORBA.ORBSingletonClass", "org.openorb.CORBA.ORBSingleton" );
  -
  -        properties.put( "CONFIGURATION", m_config.getChild("orb") );
  -        properties.put( "LOGGER", getLogger().getChildLogger("orb") );
  -        properties.put( "CONTEXT", m_context );
  +    public void contextualize( Context context )
  +    throws ContextException
  +    {
  +	  if( getLogger().isDebugEnabled() ) getLogger().debug( "contextualization" );
  +	  m_context = context;
  +    }
   
  -        //
  -        // create an ORB
  -        //
  -        
  -        if( getLogger().isDebugEnabled() ) getLogger().debug("creating ORB" );
  -        try
  -        {
  -            m_orb = ORB.init( new String[0], properties );
  -        }
  -        catch( Throwable e)
  -        {
  -            throw new CascadingException( "Unable to instantiate an ORB.", e);
  -        }
  +    //=======================================================================
  +    // Configurable
  +    //=======================================================================
  +    
  +    public void configure( final Configuration config )
  +    throws ConfigurationException
  +    {
  +        m_config = config;
   
           //
           // get the time service parameters
  @@ -214,143 +230,109 @@
               if( getLogger().isDebugEnabled() ) getLogger().debug(
                 "setting inaccuracy to default " + m_inaccuracy );
           }
  -        
  -        m_ior = m_config.getChild("ior").getAttribute( "ior", null );
  -        if( getLogger().isDebugEnabled() )
  -        {
  -            if( m_ior != null ) 
  -            {
  -                getLogger().debug( "setting IOR path to " + m_ior );
  -            }
  -            else
  -            {
  -                getLogger().debug("IOR publication disabled" );
  -            }
  -        } 
  -        
  -        //
  -        // create the time server runtime POA
  -        //
  -        
  -        if( getLogger().isDebugEnabled() ) getLogger().debug("locating root POA" );
  -        try
  -        {
  -            m_root = POAHelper.narrow(m_orb.resolve_initial_references(ROOT_POA));
  -            POA timePOA = m_root.create_POA
  -            (
  -              "TimeServicePOA", // adapter name
  -              m_root.the_POAManager(), // manager
  -              new Policy[]
  -              {
  -                m_root.create_implicit_activation_policy(
  -                ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION),
  -                m_root.create_lifespan_policy( LifespanPolicyValue.PERSISTENT ),
  -                m_root.create_id_uniqueness_policy( IdUniquenessPolicyValue.UNIQUE_ID)
  -              }
  -            );
  -            
  -            org.omg.CosTime.TimeServicePOA servant =
  -            new org.apache.time.DefaultTimeService( m_orb, m_inaccuracy );
  -            byte[] servantID = timePOA.activate_object(servant);
  -            org.omg.CORBA.Object object = null;
  -            object = timePOA.id_to_reference(servantID);
  -            m_time = TimeServiceHelper.narrow( object );
  -            if( getLogger().isDebugEnabled() ) getLogger().debug("POA established" );
  -        }
  -        catch( Exception e)
  -        {
  -            throw new CascadingException("cannot instantiate POA", e);
  -        }
  -        
  -        //
  -        // register time service as an initial reference
  -        //
  -
  -        Object info = null;
  -        try
  -        {
  -            info = m_context.get("ORB_INIT_INFO");
  -        }
  -        catch( Throwable e )
  -        {
  -            // ignore - just means that we don't need to register the time service
  -            // as an initial ref
  -        }
  -        
  -        if(( info != null ) && (info instanceof ORBInitInfo )) try
  -        {
  -            ((ORBInitInfo)info).register_initial_reference("TimeService", m_time);
  -        }
  -        catch( Throwable e )
  -        {
  -            final String error = 
  -              "Unexpected exception while attempting to register time service as an inital reference.";
  -             throw new CascadingException( error, e );
  -        }
  -        if( getLogger().isDebugEnabled() ) getLogger().debug("initialization complete" );
       }
  +
  +    //============================================================================
  +    // Serviceable
  +    //============================================================================
       
  +    /**
  +     * Pass the <code>ServiceManager</code> to the <code>Serviceable</code>.
  +     * The <code>Serviceable</code> implementation should use the supplied
  +     * <code>ServiceManager</code> to acquire the components it needs for
  +     * execution.
  +     *
  +     * @param manager The <code>ServiceManager</code> which this
  +     *                <code>Serviceable</code> uses.
  +     */
  +    public void service( ServiceManager manager )
  +    throws ServiceException
  +    {
  +        if( getLogger().isDebugEnabled() ) getLogger().debug( "service composition" );
  +        m_manager = manager;
  +    }
  +
       //=======================================================================
  -    // Startable
  +    // Initializable
       //=======================================================================
       
  -    /**
  -     * Start the TimeServer.
  -     */
  -    public void start()
  +   /**
  +    * One-time initalization of the service during which the POA is established.
  +    * @exception IllegalStateException if the server has been disposed of, if 
  +    *  has not log enabled, configured, contextualized, or serviced.
  +    * @exception Exception if a general initalization error occurs
  +    */
  +    public void initialize()
       throws Exception
       {
  -        if( getLogger().isDebugEnabled() ) getLogger().debug("starting server" );
  +        if( m_disposed ) throw new IllegalStateException(
  +          "Service is disposed.");
  +
  +        if( m_initialized ) throw new IllegalStateException(
  +          "Service cannot be re-initialized.");
  +
  +        if( m_logger == null ) throw new IllegalStateException(
  +          "Missing logger.");
  +
  +        if( m_config == null ) throw new IllegalStateException(
  +          "Missing configuration.");
  +
  +        if( m_manager == null ) throw new IllegalStateException(
  +          "Missing service manager.");
  +
  +        if( getLogger().isDebugEnabled() ) getLogger().debug( "initialization" );
   
           //
  -        // set object reference
  +        // create the POA
  +        //
  +
  +        m_root = ((POAContext)m_manager.lookup( POAContext.POA_KEY )).getPOA();
  +        String name = "TIME";
  +
  +        try
  +	  {
  +            m_poa = m_root.create_POA(
  +                name,
  +                m_root.the_POAManager(),
  +                new Policy[]
  +                {
  +                    m_root.create_id_assignment_policy( IdAssignmentPolicyValue.USER_ID ),
  +                    m_root.create_lifespan_policy( LifespanPolicyValue.PERSISTENT )
  +                }
  +            );
  +	  }
  +	  catch( Throwable e )
  +	  {
  +	      String error = "Unable to create the application POA";
  +	      throw new CascadingException( error, e );
  +	  }
  +
  +        byte[] ID = name.getBytes();
  +        m_poa.activate_object_with_id( ID, this );
  +        m_service = TimeServiceHelper.narrow( m_poa.id_to_reference(ID) );
  +
  +        //
  +        // publish the service
           //
           
  -        if( m_ior != null )
  +        String ior = m_config.getChild("ior").getAttribute("value", null );
  +        if( ior != null )
           {
  -            if( getLogger().isDebugEnabled() ) getLogger().debug("creating external object reference" );
               try
               {
  -                IOR.writeIOR( m_orb, m_time, m_ior );
  -                if( getLogger().isDebugEnabled() ) getLogger().debug( "published IOR to: " + m_ior );
  +                IOR.writeIOR( this._orb(), m_service, ior );
  +                if( getLogger().isDebugEnabled() ) getLogger().debug( 
  +                  "IOR published to path: " + ior ); 
               }
  -            catch (Exception e)
  +            catch( Throwable e )
               {
  -                throw new CascadingException( "failed to create external IOR on " + m_ior );
  +                final String warning = "IOR publication disabled due to internal error.";
  +                if( getLogger().isWarnEnabled() ) getLogger().warn( warning, e ); 
               }
           }
  -        
  -        m_thread = new Thread(
  -        new Runnable() {
  -            public void run()
  -            {
  -                if( getLogger().isDebugEnabled() ) getLogger().debug("starting time server" );
  -                try
  -                {
  -                    m_root.the_POAManager().activate();
  -                    m_orb.run();
  -                }
  -                catch (Exception e)
  -                {
  -                    throw new CascadingRuntimeException( "failed to activate the server", e );
  -                }
  -            }
  -          }
  -        );
  -        m_thread.start();
  -        String banner = "Time Service available ";
  -        if( getLogger().isInfoEnabled() ) getLogger().info( banner );
  -    }
   
  -   /**
  -    * Stops the component.
  -    */
  -    public void stop()
  -    throws Exception
  -    {
  -        if( getLogger().isDebugEnabled() ) getLogger().debug("shutdown" );
  -        m_orb.shutdown( true );
  -        if( getLogger().isDebugEnabled() ) getLogger().debug("shutdown complete" );
  +        m_initialized = true;
  +
       }
   
       //=======================================================================
  @@ -365,6 +347,53 @@
           if( getLogger().isInfoEnabled() ) getLogger().info( 
             "current time: " + TimeUtils.convertToDate( this.universal_time().time() ));
       }
  +        
  +    //=======================================================================
  +    // Startable
  +    //=======================================================================
  +
  +   /**
  +    * Starts the finder resulting in the finder's readiness to handle 
  +    * requests.
  +    */
  +    public void start() 
  +    {
  +        if( !m_initialized ) throw new IllegalStateException(
  +          "Chooser has not been initalized.");
  +        if( m_disposed ) throw new IllegalStateException(
  +          "Chooser is disposed.");
  +        
  +        if( getLogger().isDebugEnabled() ) getLogger().debug( "start" );
  +        try
  +        {
  +            m_poa.the_POAManager().activate();
  +        }
  +        catch( Throwable e )
  +        {
  +            if( getLogger().isWarnEnabled() ) getLogger().warn( "startup exception", e );
  +        }
  +    }
  +
  +   /**
  +    * Stops the finder and destroys the underlying POA.
  +    */
  +    public void stop() 
  +    {
  +        if( !m_initialized ) throw new IllegalStateException(
  +          "Chooser has not been initalized.");
  +        if( m_disposed ) throw new IllegalStateException(
  +          "Chooser is disposed.");
  +
  +        if( getLogger().isDebugEnabled() ) getLogger().debug( "stop" );
  +        try
  +        {
  +            m_poa.destroy( true, true );
  +        }
  +        catch( Throwable e )
  +        {
  +            if( getLogger().isWarnEnabled() ) getLogger().warn( "ignoring POA related exception" );
  +        }
  +    }
   
       //=======================================================================
       // Disposable
  @@ -376,16 +405,36 @@
       */
       public void dispose()
       {
  -        if( getLogger().isDebugEnabled() ) getLogger().debug("dispose" );
  -        synchronized( m_orb )
  +        //
  +        // cleanup the IOR
  +        //
  +
  +        if( m_config != null )
           {
  -            m_orb = null;
  -            m_root = null;
  +            final String ior = m_config.getChild("ior").getAttribute("value", null );
  +            if( ior != null )
  +            {
  +                File file = new File( ior );
  +                try
  +                {
  +                    if( file.exists() );
  +                    file.delete();
  +                    if( getLogger().isDebugEnabled() ) getLogger().debug( "IOR removed" );
  +                }
  +                catch( Throwable e )
  +                {
  +                    final String warning = "Failed to remove the IOR.";
  +                    if( getLogger().isWarnEnabled() ) getLogger().warn( warning, e );
  +                }
  +            }
           }
  +
  +        m_service = null;
           m_config = null;
  -        m_ior = null;
  -        m_time = null;
  -        m_thread = null;
  +        m_context = null;
  +        m_manager = null;
  +        m_root = null;
  +        m_poa = null;
       }
       
       //=======================================================================
  @@ -402,7 +451,9 @@
       public org.omg.CosTime.UTO universal_time()
       throws org.omg.CosTime.TimeUnavailable
       {
  -        return m_time.universal_time();
  +        Date date = new Date();
  +        DefaultUTO uto = new DefaultUTO(date.getTime(), m_inaccuracy, (short)0);
  +        return uto._this( this._orb());
       }
       
      /**
  @@ -418,7 +469,9 @@
       public org.omg.CosTime.UTO secure_universal_time()
       throws org.omg.CosTime.TimeUnavailable
       {
  -        return m_time.secure_universal_time();
  +        Date date = new Date();
  +        DefaultUTO uto = new DefaultUTO(date.getTime(), m_inaccuracy, (short)0);
  +        return uto._this(this._orb());
       }
       
      /**
  @@ -432,7 +485,8 @@
   
       public org.omg.CosTime.UTO new_universal_time(long t, long inac, short tdf)
       {
  -        return m_time.new_universal_time( t, inac, tdf );
  +        DefaultUTO uto = new DefaultUTO(t, inac, tdf);
  +        return uto._this(this._orb());
       }
       
      /**
  @@ -444,7 +498,9 @@
   
       public org.omg.CosTime.UTO uto_from_utc(org.omg.TimeBase.UtcT utc)
       {
  -        return m_time.uto_from_utc( utc );
  +        long l = (utc.inacchi << 4) + utc.inacclo;
  +        DefaultUTO uto = new DefaultUTO( utc.time, l, utc.tdf);
  +        return uto._this(this._orb());
       }
       
      /**
  @@ -456,6 +512,7 @@
   
       public org.omg.CosTime.TIO new_interval(long lower, long upper)
       {
  -        return m_time.new_interval( lower, upper );
  +        DefaultTIO tio = new DefaultTIO(lower, upper);
  +        return tio._this(this._orb());
       }
   }
  
  
  
  1.3       +7 -2      jakarta-avalon-apps/enterprise/time/src/java/org/apache/time/TimeProvider.xinfo
  
  Index: TimeProvider.xinfo
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/enterprise/time/src/java/org/apache/time/TimeProvider.xinfo,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TimeProvider.xinfo	13 Mar 2002 02:12:26 -0000	1.2
  +++ TimeProvider.xinfo	5 Apr 2002 07:02:34 -0000	1.3
  @@ -25,11 +25,16 @@
       <service name="org.omg.CosTime.TimeService" version="1.0" />
     </services>
   
  +  <dependencies>
  +      <dependency>
  +          <role>poa</role>
  +          <service name="org.apache.orb.POAContext" version="1.0"/>
  +      </dependency>
  +  </dependencies>
  +
     <implementation policy="SINGLETON"/>
   
     <configuration>
  -
  -    <ior file="time.ior"/>
   
       <!-- 
       The profile element declares the default inaccuracy values 
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>