Merged branch 'master' into 'jetty-9.3-ewyk'.

This commit is contained in:
Simone Bordet 2015-01-06 17:32:12 +01:00
commit 337d638422
8 changed files with 106 additions and 20 deletions

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.annotations;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI; import java.net.URI;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
@ -726,7 +727,15 @@ public class AnnotationConfiguration extends AbstractConfiguration
public Resource getJarFor (ServletContainerInitializer service) public Resource getJarFor (ServletContainerInitializer service)
throws MalformedURLException, IOException throws MalformedURLException, IOException
{ {
String loadingJarName = Thread.currentThread().getContextClassLoader().getResource(service.getClass().getName().replace('.','/')+".class").toString(); //try the thread context classloader to get the jar that loaded the class
URL jarURL = Thread.currentThread().getContextClassLoader().getResource(service.getClass().getName().replace('.','/')+".class");
//if for some reason that failed (eg we're in osgi and the TCCL does not know about the service) try the classloader that
//loaded the class
if (jarURL == null)
jarURL = service.getClass().getClassLoader().getResource(service.getClass().getName().replace('.','/')+".class");
String loadingJarName = jarURL.toString();
int i = loadingJarName.indexOf(".jar"); int i = loadingJarName.indexOf(".jar");
if (i < 0) if (i < 0)
@ -830,7 +839,6 @@ public class AnnotationConfiguration extends AbstractConfiguration
{ {
ArrayList<ServletContainerInitializer> nonExcludedInitializers = new ArrayList<ServletContainerInitializer>(); ArrayList<ServletContainerInitializer> nonExcludedInitializers = new ArrayList<ServletContainerInitializer>();
//We use the ServiceLoader mechanism to find the ServletContainerInitializer classes to inspect //We use the ServiceLoader mechanism to find the ServletContainerInitializer classes to inspect
long start = 0; long start = 0;

View File

@ -0,0 +1,30 @@
<!-- ======================================================================== -->
<!-- Copyright (c) 1995-2015 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. -->
<!-- ======================================================================== -->
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<goals>
<goal>jspc</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.osgi.boot;
import org.eclipse.jetty.deploy.App; import org.eclipse.jetty.deploy.App;
import org.eclipse.jetty.deploy.bindings.StandardDeployer; import org.eclipse.jetty.deploy.bindings.StandardDeployer;
import org.eclipse.jetty.deploy.graph.Node; import org.eclipse.jetty.deploy.graph.Node;
import org.eclipse.jetty.osgi.boot.internal.serverfactory.ServerInstanceWrapper;
import org.eclipse.jetty.osgi.boot.utils.EventSender; import org.eclipse.jetty.osgi.boot.utils.EventSender;
@ -34,6 +35,15 @@ import org.eclipse.jetty.osgi.boot.utils.EventSender;
public class OSGiDeployer extends StandardDeployer public class OSGiDeployer extends StandardDeployer
{ {
private ServerInstanceWrapper _server;
/* ------------------------------------------------------------ */
public OSGiDeployer (ServerInstanceWrapper server)
{
_server = server;
}
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
public void processBinding(Node node, App app) throws Exception public void processBinding(Node node, App app) throws Exception
{ {
@ -41,14 +51,14 @@ public class OSGiDeployer extends StandardDeployer
//OSGi Enterprise Spec only wants an event sent if its a webapp bundle (ie not a ContextHandler) //OSGi Enterprise Spec only wants an event sent if its a webapp bundle (ie not a ContextHandler)
if (!(app instanceof AbstractOSGiApp)) if (!(app instanceof AbstractOSGiApp))
{ {
super.processBinding(node,app); doProcessBinding(node,app);
} }
else else
{ {
EventSender.getInstance().send(EventSender.DEPLOYING_EVENT, ((AbstractOSGiApp)app).getBundle(), app.getContextPath()); EventSender.getInstance().send(EventSender.DEPLOYING_EVENT, ((AbstractOSGiApp)app).getBundle(), app.getContextPath());
try try
{ {
super.processBinding(node,app); doProcessBinding(node,app);
((AbstractOSGiApp)app).registerAsOSGiService(); ((AbstractOSGiApp)app).registerAsOSGiService();
EventSender.getInstance().send(EventSender.DEPLOYED_EVENT, ((AbstractOSGiApp)app).getBundle(), app.getContextPath()); EventSender.getInstance().send(EventSender.DEPLOYED_EVENT, ((AbstractOSGiApp)app).getBundle(), app.getContextPath());
} }
@ -58,6 +68,21 @@ public class OSGiDeployer extends StandardDeployer
throw e; throw e;
} }
} }
}
/* ------------------------------------------------------------ */
protected void doProcessBinding (Node node, App app) throws Exception
{
ClassLoader old = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(_server.getParentClassLoaderForWebapps());
try
{
super.processBinding(node,app);
}
finally
{
Thread.currentThread().setContextClassLoader(old);
}
} }
} }

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.osgi.boot;
import org.eclipse.jetty.deploy.App; import org.eclipse.jetty.deploy.App;
import org.eclipse.jetty.deploy.bindings.StandardUndeployer; import org.eclipse.jetty.deploy.bindings.StandardUndeployer;
import org.eclipse.jetty.deploy.graph.Node; import org.eclipse.jetty.deploy.graph.Node;
import org.eclipse.jetty.osgi.boot.internal.serverfactory.ServerInstanceWrapper;
import org.eclipse.jetty.osgi.boot.utils.EventSender; import org.eclipse.jetty.osgi.boot.utils.EventSender;
@ -35,11 +36,30 @@ import org.eclipse.jetty.osgi.boot.utils.EventSender;
*/ */
public class OSGiUndeployer extends StandardUndeployer public class OSGiUndeployer extends StandardUndeployer
{ {
private ServerInstanceWrapper _server;
/* ------------------------------------------------------------ */
public OSGiUndeployer (ServerInstanceWrapper server)
{
_server = server;
}
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
public void processBinding(Node node, App app) throws Exception public void processBinding(Node node, App app) throws Exception
{ {
EventSender.getInstance().send(EventSender.UNDEPLOYING_EVENT, ((AbstractOSGiApp)app).getBundle(), app.getContextPath()); EventSender.getInstance().send(EventSender.UNDEPLOYING_EVENT, ((AbstractOSGiApp)app).getBundle(), app.getContextPath());
super.processBinding(node,app); ClassLoader old = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(_server.getParentClassLoaderForWebapps());
try
{
super.processBinding(node,app);
}
finally
{
Thread.currentThread().setContextClassLoader(old);
}
EventSender.getInstance().send(EventSender.UNDEPLOYED_EVENT, ((AbstractOSGiApp)app).getBundle(), app.getContextPath()); EventSender.getInstance().send(EventSender.UNDEPLOYED_EVENT, ((AbstractOSGiApp)app).getBundle(), app.getContextPath());
((AbstractOSGiApp)app).deregisterAsOSGiService(); ((AbstractOSGiApp)app).deregisterAsOSGiService();
} }

View File

@ -376,10 +376,10 @@ public class ServerInstanceWrapper
_deploymentManager.setUseStandardBindings(false); _deploymentManager.setUseStandardBindings(false);
List<AppLifeCycle.Binding> deploymentLifeCycleBindings = new ArrayList<AppLifeCycle.Binding>(); List<AppLifeCycle.Binding> deploymentLifeCycleBindings = new ArrayList<AppLifeCycle.Binding>();
deploymentLifeCycleBindings.add(new OSGiDeployer()); deploymentLifeCycleBindings.add(new OSGiDeployer(this));
deploymentLifeCycleBindings.add(new StandardStarter()); deploymentLifeCycleBindings.add(new StandardStarter());
deploymentLifeCycleBindings.add(new StandardStopper()); deploymentLifeCycleBindings.add(new StandardStopper());
deploymentLifeCycleBindings.add(new OSGiUndeployer()); deploymentLifeCycleBindings.add(new OSGiUndeployer(this));
_deploymentManager.setLifeCycleBindings(deploymentLifeCycleBindings); _deploymentManager.setLifeCycleBindings(deploymentLifeCycleBindings);
if (!providerClassNames.contains(BundleWebAppProvider.class.getName())) if (!providerClassNames.contains(BundleWebAppProvider.class.getName()))

View File

@ -185,26 +185,20 @@ public class EnvConfiguration extends AbstractConfiguration
@Override @Override
public void destroy (WebAppContext context) throws Exception public void destroy (WebAppContext context) throws Exception
{ {
ClassLoader old_loader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(context.getClassLoader());
ContextFactory.associateClassLoader(context.getClassLoader());
try try
{ {
//unbind any NamingEntries that were configured in this webapp's name space //unbind any NamingEntries that were configured in this webapp's name space
NamingContext scopeContext = (NamingContext)NamingEntryUtil.getContextForScope(context); NamingContext scopeContext = (NamingContext)NamingEntryUtil.getContextForScope(context);
scopeContext.getParent().destroySubcontext(scopeContext.getName()); scopeContext.getParent().destroySubcontext(scopeContext.getName());
} }
catch (NameNotFoundException e) catch (NameNotFoundException e)
{ {
LOG.ignore(e); LOG.ignore(e);
LOG.debug("No naming entries configured in environment for webapp "+context); LOG.debug("No jndi entries scoped to webapp {}", context);
} }
finally catch (NamingException e)
{ {
ContextFactory.disassociateClassLoader(); LOG.debug("Error unbinding jndi entries scoped to webapp "+context, e);
Thread.currentThread().setContextClassLoader(old_loader);
} }
} }

View File

@ -268,7 +268,7 @@ public class SslContextFactory extends AbstractLifeCycle
} }
SecureRandom secureRandom = (_secureRandomAlgorithm == null)?null:SecureRandom.getInstance(_secureRandomAlgorithm); SecureRandom secureRandom = (_secureRandomAlgorithm == null)?null:SecureRandom.getInstance(_secureRandomAlgorithm);
SSLContext context = SSLContext.getInstance(_sslProtocol); SSLContext context = _sslProvider == null ? SSLContext.getInstance(_sslProtocol) : SSLContext.getInstance(_sslProtocol, _sslProvider);
context.init(null, trust_managers, secureRandom); context.init(null, trust_managers, secureRandom);
_context = context; _context = context;
} }
@ -309,7 +309,7 @@ public class SslContextFactory extends AbstractLifeCycle
TrustManager[] trustManagers = getTrustManagers(trustStore,crls); TrustManager[] trustManagers = getTrustManagers(trustStore,crls);
SecureRandom secureRandom = (_secureRandomAlgorithm == null)?null:SecureRandom.getInstance(_secureRandomAlgorithm); SecureRandom secureRandom = (_secureRandomAlgorithm == null)?null:SecureRandom.getInstance(_secureRandomAlgorithm);
SSLContext context = _sslProvider == null ? SSLContext.getInstance(_sslProtocol) : SSLContext.getInstance(_sslProtocol,_sslProvider); SSLContext context = _sslProvider == null ? SSLContext.getInstance(_sslProtocol) : SSLContext.getInstance(_sslProtocol, _sslProvider);
context.init(keyManagers,trustManagers,secureRandom); context.init(keyManagers,trustManagers,secureRandom);
_context = context; _context = context;
} }

View File

@ -405,6 +405,15 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo
return _threadsIdle.get(); return _threadsIdle.get();
} }
/**
* @return The number of busy threads in the pool
*/
@ManagedAttribute("total number of busy threads in the pool")
public int getBusyThreads()
{
return getThreads() - getIdleThreads();
}
/** /**
* @return True if the pool is at maxThreads and there are not more idle threads than queued jobs * @return True if the pool is at maxThreads and there are not more idle threads than queued jobs
*/ */