handlers cannot be updated after start

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@86 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2009-04-02 04:59:19 +00:00
parent da4c17cd1c
commit 13d4e0af1f
12 changed files with 256 additions and 136 deletions

View File

@ -1,4 +1,4 @@
jetty-7.0.0.incubator0-SNAPSHOT
jetty-7.0.0.M0-SNAPSHOT
+ JETTY-496 Support inetd/xinetd through use of System.inheritedChannel()
+ JETTY-540 Merged 3.0 Public Review changes
+ JETTY-567 Delay in initial TLS Handshake With FireFox 3 beta5 and SslSelectChannelConnector
@ -82,6 +82,7 @@ jetty-7.0.0.incubator0-SNAPSHOT
+ JETTY-953 SSL keystore file input stream is not being closed directly
+ JETTY-956 SslSelectChannelConnector - password should be the default value of keyPassword if not specified
+ moved to org.eclipse packages
+ simplified HandlerContainer API
jetty-6.1.15 4 March 2009
+ JETTY-931 Fix issue with jetty-rewrite.xml

View File

@ -634,56 +634,6 @@ public class Server extends HandlerWrapper implements Attributes
}
}
/* ------------------------------------------------------------ */
/** Append a handler.
* If the handler is null, set it as the passed handler.
* If the handler is a HandlerWrapper, append it to the handler
* If the handler is a HandlerCollection, add it to the handler
* else throw an {@link IllegalStateException}
*
* @param handler
*/
public void appendHandler(Handler handler)
{
Handler old = getHandler();
if (old==null)
setHandler(handler);
else if (old instanceof HandlerWrapper)
((HandlerWrapper)old).appendHandler(handler);
else if (old instanceof HandlerCollection)
((HandlerCollection)old).addHandler(handler);
else
throw new IllegalStateException();
}
/* ------------------------------------------------------------ */
/**
*/
public Handler[] getHandlers()
{
if (getHandler() instanceof HandlerCollection)
return ((HandlerCollection)getHandler()).getHandlers();
return null;
}
/* ------------------------------------------------------------ */
/**
*/
public void setHandlers(Handler[] handlers)
{
HandlerCollection collection;
if (getHandler() instanceof HandlerCollection)
collection=(HandlerCollection)getHandler();
else
{
collection=new HandlerCollection();
setHandler(collection);
}
collection.setHandlers(handlers);
}
/* ------------------------------------------------------------ */
/*
* @see org.eclipse.util.AttributesMap#clearAttributes()

View File

@ -172,7 +172,7 @@ public class ContextHandler extends HandlerWrapper implements Attributes, Server
this();
setContextPath(contextPath);
if (parent instanceof HandlerWrapper)
((HandlerWrapper)parent).appendHandler(this);
((HandlerWrapper)parent).setHandler(this);
else if (parent instanceof HandlerCollection)
((HandlerCollection)parent).addHandler(this);
}

View File

@ -44,8 +44,13 @@ import org.eclipse.jetty.util.log.Log;
*/
public class ContextHandlerCollection extends HandlerCollection
{
private PathMap _contextMap;
private Class _contextClass = ContextHandler.class;
private volatile PathMap _contextMap;
private Class<? extends ContextHandler> _contextClass = ContextHandler.class;
public ContextHandlerCollection()
{
super(true);
}
/* ------------------------------------------------------------ */
/**

View File

@ -37,12 +37,19 @@ import org.eclipse.jetty.util.MultiException;
*/
public class HandlerCollection extends AbstractHandlerContainer
{
private Handler[] _handlers;
private final boolean _mutableWhenRunning;
private volatile Handler[] _handlers;
/* ------------------------------------------------------------ */
public HandlerCollection()
{
super();
_mutableWhenRunning=false;
}
/* ------------------------------------------------------------ */
public HandlerCollection(boolean mutableWhenRunning)
{
_mutableWhenRunning=mutableWhenRunning;
}
/* ------------------------------------------------------------ */
@ -61,6 +68,9 @@ public class HandlerCollection extends AbstractHandlerContainer
*/
public void setHandlers(Handler[] handlers)
{
if (!_mutableWhenRunning && isStarted())
throw new IllegalStateException(STARTED);
Handler [] old_handlers = _handlers==null?null:(Handler[])_handlers.clone();
if (getServer()!=null)
@ -74,9 +84,10 @@ public class HandlerCollection extends AbstractHandlerContainer
handlers[i].setServer(server);
}
// quasi atomic.... so don't go doing this under load on a SMP system.
// handlers is volatile
_handlers = handlers;
// stop old handlers
for (int i=0;old_handlers!=null && i<old_handlers.length;i++)
{
if (old_handlers[i]!=null)
@ -174,6 +185,9 @@ public class HandlerCollection extends AbstractHandlerContainer
/* ------------------------------------------------------------ */
public void setServer(Server server)
{
if (isStarted())
throw new IllegalStateException(STARTED);
Server old_server=getServer();
super.setServer(server);

View File

@ -39,7 +39,6 @@ public class HandlerWrapper extends AbstractHandlerContainer
*/
public HandlerWrapper()
{
super();
}
/* ------------------------------------------------------------ */
@ -57,58 +56,22 @@ public class HandlerWrapper extends AbstractHandlerContainer
*/
public void setHandler(Handler handler)
{
try
{
Handler old_handler = _handler;
if (getServer()!=null)
getServer().getContainer().update(this, old_handler, handler, "handler");
if (handler!=null)
{
handler.setServer(getServer());
}
_handler = handler;
if (old_handler!=null)
{
if (old_handler.isStarted())
old_handler.stop();
}
}
catch(Exception e)
{
IllegalStateException ise= new IllegalStateException();
ise.initCause(e);
throw ise;
}
}
if (isStarted())
throw new IllegalStateException(STARTED);
Handler old_handler = _handler;
/* ------------------------------------------------------------ */
/** Append a handler.
* If the handler is null, set it as the passed handler.
* If the handler is a HandlerWrapper, append it to the handler
* If the handler is a HandlerCollection, add it to the handler
* else throw an {@link IllegalStateException}
*
* @param handler
*/
public void appendHandler(Handler handler)
{
Handler old = getHandler();
if (old==null)
setHandler(handler);
else if (old instanceof HandlerWrapper)
((HandlerWrapper)old).appendHandler(handler);
else if (old instanceof HandlerCollection)
((HandlerCollection)old).addHandler(handler);
else
throw new IllegalStateException();
if (getServer()!=null)
getServer().getContainer().update(this, old_handler, handler, "handler");
if (handler!=null)
{
handler.setServer(getServer());
}
_handler = handler;
}
/* ------------------------------------------------------------ */
/*
* @see org.eclipse.thread.AbstractLifeCycle#doStart()
@ -147,6 +110,9 @@ public class HandlerWrapper extends AbstractHandlerContainer
/* ------------------------------------------------------------ */
public void setServer(Server server)
{
if (isStarted())
throw new IllegalStateException(STARTED);
Server old_server=getServer();
super.setServer(server);

View File

@ -0,0 +1,157 @@
// ========================================================================
// Copyright (c) 2004-2009 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.server.handler;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.HandlerContainer;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.component.LifeCycle;
/* ------------------------------------------------------------ */
/** A <code>HandlerContainer</code> that allows a hot swap
* of a wrapped handler.
*
*/
public class HotSwapHandler extends AbstractHandlerContainer
{
private volatile Handler _handler;
/* ------------------------------------------------------------ */
/**
*
*/
public HotSwapHandler()
{
}
/* ------------------------------------------------------------ */
/**
* @return Returns the handlers.
*/
public Handler getHandler()
{
return _handler;
}
/* ------------------------------------------------------------ */
/**
* @param handler Set the {@link Handler} which should be wrapped.
*/
public void setHandler(Handler handler)
{
try
{
if (isRunning())
throw new IllegalStateException(RUNNING);
Handler old_handler = _handler;
if (getServer()!=null)
getServer().getContainer().update(this, old_handler, handler, "handler");
if (handler!=null)
{
handler.setServer(getServer());
if (isStarted())
handler.start();
}
_handler = handler;
if (isStarted())
old_handler.stop();
}
catch(Error e)
{
throw e;
}
catch(RuntimeException e)
{
throw e;
}
catch(Exception e)
{
throw new RuntimeException(e);
}
}
/* ------------------------------------------------------------ */
/*
* @see org.eclipse.thread.AbstractLifeCycle#doStart()
*/
protected void doStart() throws Exception
{
if (_handler!=null)
_handler.start();
super.doStart();
}
/* ------------------------------------------------------------ */
/*
* @see org.eclipse.thread.AbstractLifeCycle#doStop()
*/
protected void doStop() throws Exception
{
super.doStop();
if (_handler!=null)
_handler.stop();
}
/* ------------------------------------------------------------ */
/*
* @see org.eclipse.jetty.server.server.EventHandler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public void handle(String target, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
if (_handler!=null && isStarted())
{
_handler.handle(target,request, response);
}
}
/* ------------------------------------------------------------ */
public void setServer(Server server)
{
if (isRunning())
throw new IllegalStateException(RUNNING);
Server old_server=getServer();
super.setServer(server);
Handler h=getHandler();
if (h!=null)
h.setServer(server);
if (server!=null && server!=old_server)
server.getContainer().update(this, null,_handler, "handler");
}
/* ------------------------------------------------------------ */
protected Object expandChildren(Object list, Class byClass)
{
return expandHandler(_handler,list,byClass);
}
}

View File

@ -65,7 +65,6 @@ public class HttpConnectionTest extends TestCase
/* --------------------------------------------------------------- */
public void testFragmentedChunk()
{
String response=null;
try
{
@ -97,8 +96,6 @@ public class HttpConnectionTest extends TestCase
offset = checkContains(response,offset,"HTTP/1.1 200");
offset = checkContains(response,offset,"/R2");
offset = checkContains(response,offset,"ABCDE");
}
catch(Exception e)
{
@ -127,7 +124,6 @@ public class HttpConnectionTest extends TestCase
/* --------------------------------------------------------------- */
public void testAutoFlush() throws Exception
{
String response=null;
int offset=0;
@ -286,7 +282,9 @@ public class HttpConnectionTest extends TestCase
offset = checkContains(response,offset,"*");
// to prevent the DumpHandler from picking this up and returning 200 OK
server.stop();
server.setHandler(null);
server.start();
offset=0; connector.reopen();
response=connector.getResponses("GET * HTTP/1.1\n"+
"Host: localhost\n"+

View File

@ -181,13 +181,17 @@ public class StatisticsHandlerTest extends TestCase
public synchronized void process(HandlerWrapper customHandler) throws Exception
{
_statsHandler.stop();
_statsHandler.setHandler(customHandler);
_statsHandler.start();
String request = "GET / HTTP/1.1\r\n" + "Host: localhost\r\n" + "Content-Length: 6\r\n" + "\r\n" + "test\r\n";
_connector.reopen();
_connector.getResponses(request);
_statsHandler.stop();
_statsHandler.setHandler(null);
_statsHandler.start();
}

View File

@ -109,7 +109,7 @@ public class ServletContextHandler extends ContextHandler
setContextPath(contextPath);
if (parent instanceof HandlerWrapper)
((HandlerWrapper)parent).appendHandler(this);
((HandlerWrapper)parent).setHandler(this);
else if (parent instanceof HandlerCollection)
((HandlerCollection)parent).addHandler(this);
}

View File

@ -71,8 +71,8 @@ $(jetty.home)/resources/
# Add servlet api
[servlet-api,default,server]
$(jetty.home)/lib/servlet-api-3.0-SNAPSHOT.jar ! available javax.servlet.ServletContext
$(repository)/org/eclipse/jetty/servlet-api/3.0-SNAPSHOT/servlet-api-3.0-SNAPSHOT.jar ! available javax.servlet.ServletContext
$(jetty.home)/lib/servlet-api-2.5.jar ! available javax.servlet.ServletContext
$(repository)/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar ! available javax.servlet.ServletContext
# Add jetty modules
[jetty-util,*]
@ -91,6 +91,10 @@ $(repository)/org/eclipse/jetty/jetty-xml/$(version)/jetty-xml-$(version).jar
$(jetty.home)/lib/jetty-http-$(version).jar ! available org.eclipse.jetty.http.HttpParser
$(repository)/org/eclipse/jetty/jetty-http/$(version)/jetty-http-$(version).jar ! available org.eclipse.jetty.http.HttpParser
[continuation,default,Server]
$(jetty.home)/lib/jetty-continuation-$(version).jar ! available org.eclipse.jetty.continuation.Continuation
$(repository)/org/eclipse/jetty/jetty-continuation/$(version)/jetty-continuation-$(version).jar ! available org.eclipse.jetty.continuation.Continuation
[server,default,Server]
$(jetty.home)/lib/jetty-server-$(version).jar ! available org.eclipse.jetty.server.Server
$(repository)/org/eclipse/jetty/jetty-server/$(version)/jetty-server-$(version).jar ! available org.eclipse.jetty.server.Server

View File

@ -23,9 +23,16 @@ import org.eclipse.jetty.util.log.Log;
*/
public abstract class AbstractLifeCycle implements LifeCycle
{
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;
private final int __FAILED = -1, __STOPPED = 0, __STARTING = 1, __STARTED = 2, __STOPPING = 3;
private volatile int _state = __STOPPED;
protected LifeCycle.Listener[] _listeners;
protected void doStart() throws Exception
@ -42,22 +49,22 @@ public abstract class AbstractLifeCycle implements LifeCycle
{
try
{
if (_state == STARTED || _state == STARTING)
if (_state == __STARTED || _state == __STARTING)
return;
setStarting();
doStart();
Log.debug("started {}",this);
Log.debug(STARTED+" {}",this);
setStarted();
}
catch (Exception e)
{
Log.warn("failed " + this,e);
Log.warn(FAILED+" " + this,e);
setFailed(e);
throw e;
}
catch (Error e)
{
Log.warn("failed " + this,e);
Log.warn(FAILED+" " + this,e);
setFailed(e);
throw e;
}
@ -70,22 +77,22 @@ public abstract class AbstractLifeCycle implements LifeCycle
{
try
{
if (_state == STOPPING || _state == STOPPED)
if (_state == __STOPPING || _state == __STOPPED)
return;
setStopping();
doStop();
Log.debug("stopped {}",this);
Log.debug(STOPPED+" {}",this);
setStopped();
}
catch (Exception e)
{
Log.warn("failed " + this,e);
Log.warn(FAILED+" " + this,e);
setFailed(e);
throw e;
}
catch (Error e)
{
Log.warn("failed " + this,e);
Log.warn(FAILED+" " + this,e);
setFailed(e);
throw e;
}
@ -94,32 +101,32 @@ public abstract class AbstractLifeCycle implements LifeCycle
public boolean isRunning()
{
return _state == STARTED || _state == STARTING;
return _state == __STARTED || _state == __STARTING;
}
public boolean isStarted()
{
return _state == STARTED;
return _state == __STARTED;
}
public boolean isStarting()
{
return _state == STARTING;
return _state == __STARTING;
}
public boolean isStopping()
{
return _state == STOPPING;
return _state == __STOPPING;
}
public boolean isStopped()
{
return _state == STOPPED;
return _state == __STOPPED;
}
public boolean isFailed()
{
return _state == FAILED;
return _state == __FAILED;
}
public void addLifeCycleListener(LifeCycle.Listener listener)
@ -131,10 +138,23 @@ public abstract class AbstractLifeCycle implements LifeCycle
{
LazyList.removeFromArray(_listeners,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;
}
private void setStarted()
{
_state = STARTED;
_state = __STARTED;
if (_listeners != null)
{
for (int i = 0; i < _listeners.length; i++)
@ -146,7 +166,7 @@ public abstract class AbstractLifeCycle implements LifeCycle
private void setStarting()
{
_state = STARTING;
_state = __STARTING;
if (_listeners != null)
{
for (int i = 0; i < _listeners.length; i++)
@ -158,7 +178,7 @@ public abstract class AbstractLifeCycle implements LifeCycle
private void setStopping()
{
_state = STOPPING;
_state = __STOPPING;
if (_listeners != null)
{
for (int i = 0; i < _listeners.length; i++)
@ -170,7 +190,7 @@ public abstract class AbstractLifeCycle implements LifeCycle
private void setStopped()
{
_state = STOPPED;
_state = __STOPPED;
if (_listeners != null)
{
for (int i = 0; i < _listeners.length; i++)
@ -182,7 +202,7 @@ public abstract class AbstractLifeCycle implements LifeCycle
private void setFailed(Throwable error)
{
_state = FAILED;
_state = __FAILED;
if (_listeners != null)
{
for (int i = 0; i < _listeners.length; i++)
@ -192,4 +212,5 @@ public abstract class AbstractLifeCycle implements LifeCycle
}
}
}