Beispiel #1
0
        /// <summary>Stop the services in reverse order</summary>
        /// <param name="numOfServicesStarted">index from where the stop should work</param>
        /// <param name="stopOnlyStartedServices">
        /// flag to say "only start services that are
        /// started, not those that are NOTINITED or INITED.
        /// </param>
        /// <exception cref="RuntimeException">
        /// the first exception raised during the
        /// stop process -<i>after all services are stopped</i>
        /// </exception>
        private void Stop(int numOfServicesStarted, bool stopOnlyStartedServices)
        {
            // stop in reverse order of start
            Exception firstException = null;
            IList <Org.Apache.Hadoop.Service.Service> services = GetServices();

            for (int i = numOfServicesStarted - 1; i >= 0; i--)
            {
                Org.Apache.Hadoop.Service.Service service = services[i];
                if (Log.IsDebugEnabled())
                {
                    Log.Debug("Stopping service #" + i + ": " + service);
                }
                Service.STATE state = service.GetServiceState();
                //depending on the stop police
                if (state == Service.STATE.Started || (!stopOnlyStartedServices && state == Service.STATE
                                                       .Inited))
                {
                    Exception ex = ServiceOperations.StopQuietly(Log, service);
                    if (ex != null && firstException == null)
                    {
                        firstException = ex;
                    }
                }
            }
            //after stopping all services, rethrow the first exception raised
            if (firstException != null)
            {
                throw ServiceStateException.Convert(firstException);
            }
        }
Beispiel #2
0
 /// <summary><inheritDoc/></summary>
 /// <exception cref="ServiceStateException">
 /// if the current service state does not permit
 /// this action
 /// </exception>
 public override void Start()
 {
     if (IsInState(Service.STATE.Started))
     {
         return;
     }
     //enter the started state
     lock (stateChangeLock)
     {
         if (stateModel.EnterState(Service.STATE.Started) != Service.STATE.Started)
         {
             try
             {
                 startTime = Runtime.CurrentTimeMillis();
                 ServiceStart();
                 if (IsInState(Service.STATE.Started))
                 {
                     //if the service started (and isn't now in a later state), notify
                     if (Log.IsDebugEnabled())
                     {
                         Log.Debug("Service " + GetName() + " is started");
                     }
                     NotifyListeners();
                 }
             }
             catch (Exception e)
             {
                 NoteFailure(e);
                 ServiceOperations.StopQuietly(Log, this);
                 throw ServiceStateException.Convert(e);
             }
         }
     }
 }
Beispiel #3
0
 /// <summary>
 /// <inheritDoc/>
 /// This invokes
 /// <see cref="ServiceInit(Configuration)"/>
 /// </summary>
 /// <param name="conf">the configuration of the service. This must not be null</param>
 /// <exception cref="ServiceStateException">
 /// if the configuration was null,
 /// the state change not permitted, or something else went wrong
 /// </exception>
 public override void Init(Configuration conf)
 {
     if (conf == null)
     {
         throw new ServiceStateException("Cannot initialize service " + GetName() + ": null configuration"
                                         );
     }
     if (IsInState(Service.STATE.Inited))
     {
         return;
     }
     lock (stateChangeLock)
     {
         if (EnterState(Service.STATE.Inited) != Service.STATE.Inited)
         {
             SetConfig(conf);
             try
             {
                 ServiceInit(config);
                 if (IsInState(Service.STATE.Inited))
                 {
                     //if the service ended up here during init,
                     //notify the listeners
                     NotifyListeners();
                 }
             }
             catch (Exception e)
             {
                 NoteFailure(e);
                 ServiceOperations.StopQuietly(Log, this);
                 throw ServiceStateException.Convert(e);
             }
         }
     }
 }
Beispiel #4
0
 /// <summary><inheritDoc/></summary>
 public override void Stop()
 {
     if (IsInState(Service.STATE.Stopped))
     {
         return;
     }
     lock (stateChangeLock)
     {
         if (EnterState(Service.STATE.Stopped) != Service.STATE.Stopped)
         {
             try
             {
                 ServiceStop();
             }
             catch (Exception e)
             {
                 //stop-time exceptions are logged if they are the first one,
                 NoteFailure(e);
                 throw ServiceStateException.Convert(e);
             }
             finally
             {
                 //report that the service has terminated
                 terminationNotification.Set(true);
                 lock (terminationNotification)
                 {
                     Runtime.NotifyAll(terminationNotification);
                 }
                 //notify anything listening for events
                 NotifyListeners();
             }
         }
         else
         {
             //already stopped: note it
             if (Log.IsDebugEnabled())
             {
                 Log.Debug("Ignoring re-entrant call to stop()");
             }
         }
     }
 }