changeset 847:5dfb10ec0ca5

remove LifeCycle.Listener
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 19 Sep 2016 16:11:15 -0600
parents 490960236c58
children 22a4e93ed20e
files src/org/eclipse/jetty/util/component/AbstractLifeCycle.java src/org/eclipse/jetty/util/component/LifeCycle.java
diffstat 2 files changed, 203 insertions(+), 252 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/eclipse/jetty/util/component/AbstractLifeCycle.java	Mon Sep 19 15:02:49 2016 -0600
+++ b/src/org/eclipse/jetty/util/component/AbstractLifeCycle.java	Mon Sep 19 16:11:15 2016 -0600
@@ -30,188 +30,158 @@
  */
 public abstract class AbstractLifeCycle implements LifeCycle
 {
-    private static final Logger LOG = LoggerFactory.getLogger(AbstractLifeCycle.class);
-    public static final String STOPPED="STOPPED";
-    public static final String FAILED="FAILED";
-    public static final String STARTING="STARTING";
-    public static final String STARTED="STARTED";
-    public static final String STOPPING="STOPPING";
-    public static final String RUNNING="RUNNING";
-    
-    private final Object _lock = new Object();
-    private final int __FAILED = -1, __STOPPED = 0, __STARTING = 1, __STARTED = 2, __STOPPING = 3;
-    private volatile int _state = __STOPPED;
-    
-    protected final CopyOnWriteArrayList<LifeCycle.Listener> _listeners=new CopyOnWriteArrayList<LifeCycle.Listener>();
+	private static final Logger LOG = LoggerFactory.getLogger(AbstractLifeCycle.class);
+	public static final String STOPPED="STOPPED";
+	public static final String FAILED="FAILED";
+	public static final String STARTING="STARTING";
+	public static final String STARTED="STARTED";
+	public static final String STOPPING="STOPPING";
+	public static final String RUNNING="RUNNING";
+	
+	private final Object _lock = new Object();
+	private final int __FAILED = -1, __STOPPED = 0, __STARTING = 1, __STARTED = 2, __STOPPING = 3;
+	private volatile int _state = __STOPPED;
+	
+	protected void doStart() throws Exception
+	{
+	}
 
-    protected void doStart() throws Exception
-    {
-    }
-
-    protected void doStop() throws Exception
-    {
-    }
+	protected void doStop() throws Exception
+	{
+	}
 
-    public final void start() throws Exception
-    {
-        synchronized (_lock)
-        {
-            try
-            {
-                if (_state == __STARTED || _state == __STARTING)
-                    return;
-                setStarting();
-                doStart();
-                setStarted();
-            }
-            catch (Exception e)
-            {
-                setFailed(e);
-                throw e;
-            }
-            catch (Error e)
-            {
-                setFailed(e);
-                throw e;
-            }
-        }
-    }
+	public final void start() throws Exception
+	{
+		synchronized (_lock)
+		{
+			try
+			{
+				if (_state == __STARTED || _state == __STARTING)
+					return;
+				setStarting();
+				doStart();
+				setStarted();
+			}
+			catch (Exception e)
+			{
+				setFailed(e);
+				throw e;
+			}
+			catch (Error e)
+			{
+				setFailed(e);
+				throw e;
+			}
+		}
+	}
 
-    public final void stop() throws Exception
-    {
-        synchronized (_lock)
-        {
-            try
-            {
-                if (_state == __STOPPING || _state == __STOPPED)
-                    return;
-                setStopping();
-                doStop();
-                setStopped();
-            }
-            catch (Exception e)
-            {
-                setFailed(e);
-                throw e;
-            }
-            catch (Error e)
-            {
-                setFailed(e);
-                throw e;
-            }
-        }
-    }
+	public final void stop() throws Exception
+	{
+		synchronized (_lock)
+		{
+			try
+			{
+				if (_state == __STOPPING || _state == __STOPPED)
+					return;
+				setStopping();
+				doStop();
+				setStopped();
+			}
+			catch (Exception e)
+			{
+				setFailed(e);
+				throw e;
+			}
+			catch (Error e)
+			{
+				setFailed(e);
+				throw e;
+			}
+		}
+	}
 
-    public boolean isRunning()
-    {
-        final int state = _state;
-        
-        return state == __STARTED || state == __STARTING;
-    }
-
-    public boolean isStarted()
-    {
-        return _state == __STARTED;
-    }
-
-    public boolean isStarting()
-    {
-        return _state == __STARTING;
-    }
+	public boolean isRunning()
+	{
+		final int state = _state;
+		
+		return state == __STARTED || state == __STARTING;
+	}
 
-    public boolean isStopping()
-    {
-        return _state == __STOPPING;
-    }
-
-    public boolean isStopped()
-    {
-        return _state == __STOPPED;
-    }
+	public boolean isStarted()
+	{
+		return _state == __STARTED;
+	}
 
-    public boolean isFailed()
-    {
-        return _state == __FAILED;
-    }
-
-    public void addLifeCycleListener(LifeCycle.Listener listener)
-    {
-        _listeners.add(listener);
-    }
+	public boolean isStarting()
+	{
+		return _state == __STARTING;
+	}
 
-    public void removeLifeCycleListener(LifeCycle.Listener listener)
-    {
-        _listeners.remove(listener);
-    }
-    
-    public String getState()
-    {
-        switch(_state)
-        {
-            case __FAILED: return FAILED;
-            case __STARTING: return STARTING;
-            case __STARTED: return STARTED;
-            case __STOPPING: return STOPPING;
-            case __STOPPED: return STOPPED;
-        }
-        return null;
-    }
-    
-    public static String getState(LifeCycle lc)
-    {
-        if (lc.isStarting()) return STARTING;
-        if (lc.isStarted()) return STARTED;
-        if (lc.isStopping()) return STOPPING;
-        if (lc.isStopped()) return STOPPED;
-        return FAILED;
-    }
+	public boolean isStopping()
+	{
+		return _state == __STOPPING;
+	}
+
+	public boolean isStopped()
+	{
+		return _state == __STOPPED;
+	}
+
+	public boolean isFailed()
+	{
+		return _state == __FAILED;
+	}
 
-    private void setStarted()
-    {
-        _state = __STARTED;
-        LOG.debug(STARTED+" {}",this);
-        for (Listener listener : _listeners)
-            listener.lifeCycleStarted(this);
-    }
-
-    private void setStarting()
-    {
-        LOG.debug("starting {}",this);
-        _state = __STARTING;
-        for (Listener listener : _listeners)
-            listener.lifeCycleStarting(this);
-    }
-
-    private void setStopping()
-    {
-        LOG.debug("stopping {}",this);
-        _state = __STOPPING;
-        for (Listener listener : _listeners)
-            listener.lifeCycleStopping(this);
-    }
+	public String getState()
+	{
+		switch(_state)
+		{
+			case __FAILED: return FAILED;
+			case __STARTING: return STARTING;
+			case __STARTED: return STARTED;
+			case __STOPPING: return STOPPING;
+			case __STOPPED: return STOPPED;
+		}
+		return null;
+	}
+	
+	public static String getState(LifeCycle lc)
+	{
+		if (lc.isStarting()) return STARTING;
+		if (lc.isStarted()) return STARTED;
+		if (lc.isStopping()) return STOPPING;
+		if (lc.isStopped()) return STOPPED;
+		return FAILED;
+	}
 
-    private void setStopped()
-    {
-        _state = __STOPPED;
-        LOG.debug("{} {}",STOPPED,this);
-        for (Listener listener : _listeners)
-            listener.lifeCycleStopped(this);
-    }
+	private void setStarted()
+	{
+		_state = __STARTED;
+		LOG.debug(STARTED+" {}",this);
+	}
+
+	private void setStarting()
+	{
+		LOG.debug("starting {}",this);
+		_state = __STARTING;
+	}
 
-    private void setFailed(Throwable th)
-    {
-        _state = __FAILED;
-        LOG.warn(FAILED+" " + this+": "+th,th);
-        for (Listener listener : _listeners)
-            listener.lifeCycleFailure(this,th);
-    }
+	private void setStopping()
+	{
+		LOG.debug("stopping {}",this);
+		_state = __STOPPING;
+	}
 
-    public static abstract class AbstractLifeCycleListener implements LifeCycle.Listener
-    {
-        public void lifeCycleFailure(LifeCycle event, Throwable cause) {}
-        public void lifeCycleStarted(LifeCycle event) {}
-        public void lifeCycleStarting(LifeCycle event) {}
-        public void lifeCycleStopped(LifeCycle event) {}
-        public void lifeCycleStopping(LifeCycle event) {}
-    }
+	private void setStopped()
+	{
+		_state = __STOPPED;
+		LOG.debug("{} {}",STOPPED,this);
+	}
+
+	private void setFailed(Throwable th)
+	{
+		_state = __FAILED;
+		LOG.warn(FAILED+" " + this+": "+th,th);
+	}
+
 }
--- a/src/org/eclipse/jetty/util/component/LifeCycle.java	Mon Sep 19 15:02:49 2016 -0600
+++ b/src/org/eclipse/jetty/util/component/LifeCycle.java	Mon Sep 19 16:11:15 2016 -0600
@@ -31,89 +31,70 @@
  */
 public interface LifeCycle
 {
-    /* ------------------------------------------------------------ */
-    /**
-     * Starts the component.
-     * @throws Exception If the component fails to start
-     * @see #isStarted()
-     * @see #stop()
-     * @see #isFailed()
-     */
-    public void start()
-        throws Exception;
+	/* ------------------------------------------------------------ */
+	/**
+	 * Starts the component.
+	 * @throws Exception If the component fails to start
+	 * @see #isStarted()
+	 * @see #stop()
+	 * @see #isFailed()
+	 */
+	public void start()
+		throws Exception;
 
-    /* ------------------------------------------------------------ */
-    /**
-     * Stops the component.
-     * The component may wait for current activities to complete
-     * normally, but it can be interrupted.
-     * @exception Exception If the component fails to stop
-     * @see #isStopped()
-     * @see #start()
-     * @see #isFailed()
-     */
-    public void stop()
-        throws Exception;
+	/* ------------------------------------------------------------ */
+	/**
+	 * Stops the component.
+	 * The component may wait for current activities to complete
+	 * normally, but it can be interrupted.
+	 * @exception Exception If the component fails to stop
+	 * @see #isStopped()
+	 * @see #start()
+	 * @see #isFailed()
+	 */
+	public void stop()
+		throws Exception;
 
-    /* ------------------------------------------------------------ */
-    /**
-     * @return true if the component is starting or has been started.
-     */
-    public boolean isRunning();
-
-    /* ------------------------------------------------------------ */
-    /**
-     * @return true if the component has been started.
-     * @see #start()
-     * @see #isStarting()
-     */
-    public boolean isStarted();
+	/* ------------------------------------------------------------ */
+	/**
+	 * @return true if the component is starting or has been started.
+	 */
+	public boolean isRunning();
 
-    /* ------------------------------------------------------------ */
-    /**
-     * @return true if the component is starting.
-     * @see #isStarted()
-     */
-    public boolean isStarting();
+	/* ------------------------------------------------------------ */
+	/**
+	 * @return true if the component has been started.
+	 * @see #start()
+	 * @see #isStarting()
+	 */
+	public boolean isStarted();
 
-    /* ------------------------------------------------------------ */
-    /**
-     * @return true if the component is stopping.
-     * @see #isStopped()
-     */
-    public boolean isStopping();
-
-    /* ------------------------------------------------------------ */
-    /**
-     * @return true if the component has been stopped.
-     * @see #stop()
-     * @see #isStopping()
-     */
-    public boolean isStopped();
+	/* ------------------------------------------------------------ */
+	/**
+	 * @return true if the component is starting.
+	 * @see #isStarted()
+	 */
+	public boolean isStarting();
 
-    /* ------------------------------------------------------------ */
-    /**
-     * @return true if the component has failed to start or has failed to stop.
-     */
-    public boolean isFailed();
-    
-    /* ------------------------------------------------------------ */
-    public void addLifeCycleListener(LifeCycle.Listener listener);
-
-    /* ------------------------------------------------------------ */
-    public void removeLifeCycleListener(LifeCycle.Listener listener);
-    
+	/* ------------------------------------------------------------ */
+	/**
+	 * @return true if the component is stopping.
+	 * @see #isStopped()
+	 */
+	public boolean isStopping();
 
-    /* ------------------------------------------------------------ */
-    /** Listener.
-     * A listener for Lifecycle events.
-     */
-    public interface Listener extends EventListener
-    {
-        public void lifeCycleStarting(LifeCycle event);
-        public void lifeCycleStarted(LifeCycle event);
-        public void lifeCycleFailure(LifeCycle event,Throwable cause);
-        public void lifeCycleStopping(LifeCycle event);
-        public void lifeCycleStopped(LifeCycle event);
-    }
+	/* ------------------------------------------------------------ */
+	/**
+	 * @return true if the component has been stopped.
+	 * @see #stop()
+	 * @see #isStopping()
+	 */
+	public boolean isStopped();
+
+	/* ------------------------------------------------------------ */
+	/**
+	 * @return true if the component has failed to start or has failed to stop.
+	 */
+	public boolean isFailed();
+
 }