diff src/org/eclipse/jetty/server/handler/ContextHandler.java @ 989:900e5b8ccd19

remove useless listeners
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 17 Oct 2016 05:39:54 -0600
parents 13beba0c127f
children 688c39c50ee3
line wrap: on
line diff
--- a/src/org/eclipse/jetty/server/handler/ContextHandler.java	Mon Oct 17 05:22:25 2016 -0600
+++ b/src/org/eclipse/jetty/server/handler/ContextHandler.java	Mon Oct 17 05:39:54 2016 -0600
@@ -70,7 +70,6 @@
 import org.eclipse.jetty.server.Request;
 import org.eclipse.jetty.server.Server;
 import org.eclipse.jetty.util.AttributesMap;
-import org.eclipse.jetty.util.LazyList;
 import org.eclipse.jetty.util.StringUtil;
 import org.eclipse.jetty.util.TypeUtil;
 import org.eclipse.jetty.util.URIUtil;
@@ -131,7 +130,6 @@
 	private Map<String, String> _localeEncodingMap;
 	private String[] _welcomeFiles;
 	private String[] _vhosts;
-	private EventListener[] _eventListeners;
 	private Logger _logger;
 	private boolean _allowNullPathInfo;
 	private int _maxFormKeys = Integer.getInteger("org.eclipse.jetty.server.Request.maxFormKeys",-1).intValue();
@@ -139,11 +137,6 @@
 	private boolean _compactPath = false;
 	private boolean _aliasesAllowed = false;
 
-	private Object _contextListeners;
-	private Object _contextAttributeListeners;
-	private Object _requestListeners;
-	private Object _requestAttributeListeners;
-	private Object _durableListeners;
 	private Map<String, Object> _managedAttributes;
 	private String[] _protectedTargets;
 	private final CopyOnWriteArrayList<AliasCheck> _aliasChecks = new CopyOnWriteArrayList<ContextHandler.AliasCheck>();
@@ -439,84 +432,7 @@
 	public String getDisplayName()
 	{
 		return _displayName;
-	}
-
-	/* ------------------------------------------------------------ */
-	public EventListener[] getEventListeners()
-	{
-		return _eventListeners;
-	}
-
-	/* ------------------------------------------------------------ */
-	/**
-	 * Set the context event listeners.
-	 *
-	 * @param eventListeners
-	 *            the event listeners
-	 * @see ServletContextListener
-	 * @see ServletContextAttributeListener
-	 * @see ServletRequestListener
-	 * @see ServletRequestAttributeListener
-	 */
-	public void setEventListeners(EventListener[] eventListeners)
-	{
-		_contextListeners = null;
-		_contextAttributeListeners = null;
-		_requestListeners = null;
-		_requestAttributeListeners = null;
-
-		_eventListeners = eventListeners;
-
-		for (int i = 0; eventListeners != null && i < eventListeners.length; i++)
-		{
-			EventListener listener = _eventListeners[i];
-
-			if (listener instanceof ServletContextListener)
-				_contextListeners = LazyList.add(_contextListeners,listener);
-
-			if (listener instanceof ServletContextAttributeListener)
-				_contextAttributeListeners = LazyList.add(_contextAttributeListeners,listener);
-
-			if (listener instanceof ServletRequestListener)
-				_requestListeners = LazyList.add(_requestListeners,listener);
-
-			if (listener instanceof ServletRequestAttributeListener)
-				_requestAttributeListeners = LazyList.add(_requestAttributeListeners,listener);
-		}
-	}
-
-	/* ------------------------------------------------------------ */
-	/**
-	 * Add a context event listeners.
-	 *
-	 * @see ServletContextListener
-	 * @see ServletContextAttributeListener
-	 * @see ServletRequestListener
-	 * @see ServletRequestAttributeListener
-	 */
-	public void addEventListener(EventListener listener)
-	{
-		//Only listeners added before the context starts last through a stop/start cycle
-		if (!(isStarted() || isStarting()))
-			_durableListeners = LazyList.add(_durableListeners, listener);
-		
-		setEventListeners((EventListener[])LazyList.addToArray(getEventListeners(),listener,EventListener.class));
-	}
-	
-   
-	/**
-	 * Apply any necessary restrictions on a programmatically added
-	 * listener.
-	 * 
-	 * Superclasses should implement.
-	 * 
-	 * @param listener
-	 */
-	public void restrictEventListener (EventListener listener)
-	{
-	}
-
-	
+	}	
 
 	/* ------------------------------------------------------------ */
 	/**
@@ -665,16 +581,6 @@
 		}
 
 		super.doStart();
-
-		// Context listeners
-		if (_contextListeners != null)
-		{
-			ServletContextEvent event = new ServletContextEvent(_scontext);
-			for (int i = 0; i < LazyList.size(_contextListeners); i++)
-			{
-				callContextInitialized(((ServletContextListener)LazyList.get(_contextListeners, i)), event);
-			}
-		}
 	}
 
 	/* ------------------------------------------------------------ */
@@ -715,20 +621,6 @@
 
 			super.doStop();
 
-			// Context listeners
-			if (_contextListeners != null)
-			{
-				ServletContextEvent event = new ServletContextEvent(_scontext);
-				for (int i = LazyList.size(_contextListeners); i-- > 0;)
-				{
-					((ServletContextListener)LazyList.get(_contextListeners,i)).contextDestroyed(event);
-				}
-			}
-			
-			//remove all non-durable listeners
-			setEventListeners((EventListener[])LazyList.toArray(_durableListeners, EventListener.class));
-			_durableListeners = null;
-
 			Enumeration e = _scontext.getAttributeNames();
 			while (e.hasMoreElements())
 			{
@@ -946,25 +838,6 @@
 		final boolean new_context = baseRequest.takeNewContext();
 		try
 		{
-			if (new_context)
-			{
-				// Handle the REALLY SILLY request events!
-				if (_requestAttributeListeners != null)
-				{
-					final int s = LazyList.size(_requestAttributeListeners);
-					for (int i = 0; i < s; i++)
-						baseRequest.addEventListener(((EventListener)LazyList.get(_requestAttributeListeners,i)));
-				}
-
-				if (_requestListeners != null)
-				{
-					final int s = LazyList.size(_requestListeners);
-					final ServletRequestEvent sre = new ServletRequestEvent(_scontext,request);
-					for (int i = 0; i < s; i++)
-						((ServletRequestListener)LazyList.get(_requestListeners,i)).requestInitialized(sre);
-				}
-			}
-
 			if (DispatcherType.REQUEST.equals(dispatch) && isProtectedTarget(target))
 				throw new HttpException(HttpServletResponse.SC_NOT_FOUND);
 
@@ -984,25 +857,6 @@
 			baseRequest.setHandled(true);
 			response.sendError(e.getStatus(),e.getReason());
 		}
-		finally
-		{
-			// Handle more REALLY SILLY request events!
-			if (new_context)
-			{
-				if (_requestListeners != null)
-				{
-					final ServletRequestEvent sre = new ServletRequestEvent(_scontext,request);
-					for (int i = LazyList.size(_requestListeners); i-- > 0;)
-						((ServletRequestListener)LazyList.get(_requestListeners,i)).requestDestroyed(sre);
-				}
-
-				if (_requestAttributeListeners != null)
-				{
-					for (int i = LazyList.size(_requestAttributeListeners); i-- > 0;)
-						baseRequest.removeEventListener(((EventListener)LazyList.get(_requestAttributeListeners,i)));
-				}
-			}
-		}
 	}
 
 	/* ------------------------------------------------------------ */
@@ -1882,23 +1736,6 @@
 				_contextAttributes.removeAttribute(name);
 			else
 				_contextAttributes.setAttribute(name,value);
-
-			if (_contextAttributeListeners != null)
-			{
-				ServletContextAttributeEvent event = new ServletContextAttributeEvent(_scontext,name,old_value == null?value:old_value);
-
-				for (int i = 0; i < LazyList.size(_contextAttributeListeners); i++)
-				{
-					ServletContextAttributeListener l = (ServletContextAttributeListener)LazyList.get(_contextAttributeListeners,i);
-
-					if (old_value == null)
-						l.attributeAdded(event);
-					else if (value == null)
-						l.attributeRemoved(event);
-					else
-						l.attributeReplaced(event);
-				}
-			}
 		}
 
 		/* ------------------------------------------------------------ */
@@ -1916,18 +1753,7 @@
 				return;
 			}
 
-			Object old_value = _contextAttributes.getAttribute(name);
 			_contextAttributes.removeAttribute(name);
-			if (old_value != null)
-			{
-				if (_contextAttributeListeners != null)
-				{
-					ServletContextAttributeEvent event = new ServletContextAttributeEvent(_scontext,name,old_value);
-
-					for (int i = 0; i < LazyList.size(_contextAttributeListeners); i++)
-						((ServletContextAttributeListener)LazyList.get(_contextAttributeListeners,i)).attributeRemoved(event);
-				}
-			}
 		}
 
 		/* ------------------------------------------------------------ */