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

This commit is contained in:
Simone Bordet 2016-02-19 16:51:47 +01:00
commit a4889eee6b
4 changed files with 88 additions and 121 deletions

View File

@ -36,7 +36,6 @@ import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.Connection; import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.EofException; import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.io.RuntimeIOException;
import org.eclipse.jetty.io.SelectChannelEndPoint; import org.eclipse.jetty.io.SelectChannelEndPoint;
import org.eclipse.jetty.io.WriteFlusher; import org.eclipse.jetty.io.WriteFlusher;
import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.BufferUtil;
@ -144,19 +143,9 @@ public class SslConnection extends AbstractConnection
@Override @Override
public void onOpen() public void onOpen()
{ {
try
{
// Begin the handshake
_sslEngine.beginHandshake();
super.onOpen(); super.onOpen();
getDecryptedEndPoint().getConnection().onOpen(); getDecryptedEndPoint().getConnection().onOpen();
} }
catch (SSLException x)
{
getEndPoint().close();
throw new RuntimeIOException(x);
}
}
@Override @Override
public void onClose() public void onClose()

View File

@ -21,7 +21,6 @@ package org.eclipse.jetty.jmx;
import java.io.IOException; import java.io.IOException;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -29,7 +28,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import javax.management.InstanceNotFoundException; import javax.management.InstanceNotFoundException;
import javax.management.MBeanRegistrationException; import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer; import javax.management.MBeanServer;
import javax.management.ObjectInstance;
import javax.management.ObjectName; import javax.management.ObjectName;
import org.eclipse.jetty.util.component.Container; import org.eclipse.jetty.util.component.Container;
@ -37,7 +35,6 @@ import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.component.Dumpable;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.Locker;
/** /**
* Container class for the MBean instances * Container class for the MBean instances
@ -45,16 +42,15 @@ import org.eclipse.jetty.util.thread.Locker;
public class MBeanContainer implements Container.InheritedListener, Dumpable public class MBeanContainer implements Container.InheritedListener, Dumpable
{ {
private final static Logger LOG = Log.getLogger(MBeanContainer.class.getName()); private final static Logger LOG = Log.getLogger(MBeanContainer.class.getName());
private final static ConcurrentMap<String, AtomicInteger> __unique = new ConcurrentHashMap<String, AtomicInteger>(); private final static ConcurrentMap<String, AtomicInteger> __unique = new ConcurrentHashMap<>();
public static void resetUnique() public static void resetUnique()
{ {
__unique.clear(); __unique.clear();
} }
private final Locker _lock = new Locker();
private final MBeanServer _mbeanServer; private final MBeanServer _mbeanServer;
private final WeakHashMap<Object, ObjectName> _beans = new WeakHashMap<Object, ObjectName>(); private final Map<Object, ObjectName> _beans = new ConcurrentHashMap<>();
private String _domain = null; private String _domain = null;
/** /**
@ -63,31 +59,23 @@ public class MBeanContainer implements Container.InheritedListener, Dumpable
* @param object instance for which object name is looked up * @param object instance for which object name is looked up
* @return object name associated with specified instance, or null if not found * @return object name associated with specified instance, or null if not found
*/ */
public synchronized ObjectName findMBean(Object object) public ObjectName findMBean(Object object)
{ {
try (Locker.Lock lock = _lock.lock()) return _beans.get(object);
{
ObjectName bean = _beans.get(object);
return bean == null ? null : bean;
}
} }
/** /**
* Lookup an instance by object name * Lookup an instance by object name
* *
* @param oname object name of instance * @param objectName object name of instance
* @return instance associated with specified object name, or null if not found * @return instance associated with specified object name, or null if not found
*/ */
public synchronized Object findBean(ObjectName oname) public Object findBean(ObjectName objectName)
{
try (Locker.Lock lock = _lock.lock())
{ {
for (Map.Entry<Object, ObjectName> entry : _beans.entrySet()) for (Map.Entry<Object, ObjectName> entry : _beans.entrySet())
{ {
ObjectName bean = entry.getValue(); if (entry.getKey().equals(objectName))
if (bean.equals(oname)) return entry.getValue();
return entry.getKey();
}
} }
return null; return null;
} }
@ -139,41 +127,41 @@ public class MBeanContainer implements Container.InheritedListener, Dumpable
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
LOG.debug("beanAdded {}->{}", parent, obj); LOG.debug("beanAdded {}->{}", parent, obj);
try (Locker.Lock lock = _lock.lock()) // Is there an object name for the parent ?
{ ObjectName parentObjectName = null;
// Is their an object name for the parent
ObjectName pname=null;
if (parent != null) if (parent != null)
{ {
pname=_beans.get(parent); parentObjectName = findMBean(parent);
if (pname==null) if (parentObjectName == null)
{ {
// create the parent bean // Create the parent bean.
beanAdded(null, parent); beanAdded(null, parent);
pname=_beans.get(parent); parentObjectName = findMBean(parent);
} }
} }
// Does an mbean already exist? // Does the mbean already exist ?
if (obj == null || _beans.containsKey(obj)) if (obj == null || _beans.containsKey(obj))
return; return;
// Create an MBean for the object try
{
// Create an MBean for the object.
Object mbean = ObjectMBean.mbeanFor(obj); Object mbean = ObjectMBean.mbeanFor(obj);
if (mbean == null) if (mbean == null)
return; return;
ObjectName oname = null; ObjectName objectName = null;
if (mbean instanceof ObjectMBean) if (mbean instanceof ObjectMBean)
{ {
((ObjectMBean)mbean).setMBeanContainer(this); ((ObjectMBean)mbean).setMBeanContainer(this);
oname = ((ObjectMBean)mbean).getObjectName(); objectName = ((ObjectMBean)mbean).getObjectName();
} }
//no override mbean object name, so make a generic one // No override of the mbean's ObjectName, so make a generic one.
if (oname == null) if (objectName == null)
{ {
//if no explicit domain, create one // If no explicit domain, create one.
String domain = _domain; String domain = _domain;
if (domain == null) if (domain == null)
domain = obj.getClass().getPackage().getName(); domain = obj.getClass().getPackage().getName();
@ -183,12 +171,11 @@ public class MBeanContainer implements Container.InheritedListener, Dumpable
if (dot >= 0) if (dot >= 0)
type = type.substring(dot + 1); type = type.substring(dot + 1);
StringBuilder buf = new StringBuilder();
StringBuffer buf = new StringBuffer();
String context = (mbean instanceof ObjectMBean) ? makeName(((ObjectMBean)mbean).getObjectContextBasis()) : null; String context = (mbean instanceof ObjectMBean) ? makeName(((ObjectMBean)mbean).getObjectContextBasis()) : null;
if (context==null && pname!=null) if (context == null && parentObjectName != null)
context=pname.getKeyProperty("context"); context = parentObjectName.getKeyProperty("context");
if (context != null && context.length() > 1) if (context != null && context.length() > 1)
buf.append("context=").append(context).append(","); buf.append("context=").append(context).append(",");
@ -204,22 +191,24 @@ public class MBeanContainer implements Container.InheritedListener, Dumpable
AtomicInteger count = __unique.get(basis); AtomicInteger count = __unique.get(basis);
if (count == null) if (count == null)
{ {
count=__unique.putIfAbsent(basis,new AtomicInteger()); count = new AtomicInteger();
if (count==null) AtomicInteger existing = __unique.putIfAbsent(basis, count);
count=__unique.get(basis); if (existing != null)
count = existing;
} }
oname = ObjectName.getInstance(domain + ":" + basis + ",id=" + count.getAndIncrement()); objectName = ObjectName.getInstance(domain + ":" + basis + ",id=" + count.getAndIncrement());
} }
ObjectInstance oinstance = _mbeanServer.registerMBean(mbean, oname); _mbeanServer.registerMBean(mbean, objectName);
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
LOG.debug("Registered {}", oinstance.getObjectName()); LOG.debug("Registered {}", objectName);
_beans.put(obj, oinstance.getObjectName());
_beans.put(obj, objectName);
} }
catch (Exception e) catch (Throwable x)
{ {
LOG.warn("bean: " + obj, e); LOG.warn("bean: " + obj, x);
} }
} }
@ -228,28 +217,11 @@ public class MBeanContainer implements Container.InheritedListener, Dumpable
{ {
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
LOG.debug("beanRemoved {}", obj); LOG.debug("beanRemoved {}", obj);
try (Locker.Lock lock = _lock.lock())
{
ObjectName bean = _beans.remove(obj);
if (bean != null) ObjectName objectName = _beans.remove(obj);
{
try if (objectName != null)
{ unregister(objectName);
_mbeanServer.unregisterMBean(bean);
if (LOG.isDebugEnabled())
LOG.debug("Unregistered {}", bean);
}
catch (javax.management.InstanceNotFoundException e)
{
LOG.ignore(e);
}
catch (Exception e)
{
LOG.warn(e);
}
}
}
} }
/** /**
@ -259,19 +231,22 @@ public class MBeanContainer implements Container.InheritedListener, Dumpable
public String makeName(String basis) public String makeName(String basis)
{ {
if (basis == null) if (basis == null)
return basis; return null;
return basis.replace(':', '_').replace('*', '_').replace('?', '_').replace('=', '_').replace(',', '_').replace(' ', '_'); return basis
.replace(':', '_')
.replace('*', '_')
.replace('?', '_')
.replace('=', '_')
.replace(',', '_')
.replace(' ', '_');
} }
@Override @Override
public void dump(Appendable out, String indent) throws IOException public void dump(Appendable out, String indent) throws IOException
{
try (Locker.Lock lock = _lock.lock())
{ {
ContainerLifeCycle.dumpObject(out,this); ContainerLifeCycle.dumpObject(out,this);
ContainerLifeCycle.dump(out, indent, _beans.entrySet()); ContainerLifeCycle.dump(out, indent, _beans.entrySet());
} }
}
@Override @Override
public String dump() public String dump()
@ -281,22 +256,26 @@ public class MBeanContainer implements Container.InheritedListener, Dumpable
public void destroy() public void destroy()
{ {
try (Locker.Lock lock = _lock.lock()) _beans.values().stream()
{ .filter(objectName -> objectName != null)
for (ObjectName oname : _beans.values()) .forEach(this::unregister);
{ }
if (oname!=null)
private void unregister(ObjectName objectName)
{ {
try try
{ {
_mbeanServer.unregisterMBean(oname); getMBeanServer().unregisterMBean(objectName);
if (LOG.isDebugEnabled())
LOG.debug("Unregistered {}", objectName);
} }
catch (MBeanRegistrationException | InstanceNotFoundException e) catch (MBeanRegistrationException | InstanceNotFoundException x)
{ {
LOG.warn(e); LOG.ignore(x);
} }
} catch (Throwable x)
} {
LOG.warn(x);
} }
} }
} }

View File

@ -33,7 +33,6 @@
<New id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory"> <New id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory">
<Set name="KeyStorePath"><Property name="jetty.base" default="." />/<Property name="jetty.sslContext.keyStorePath" default="etc/keystore"/></Set> <Set name="KeyStorePath"><Property name="jetty.base" default="." />/<Property name="jetty.sslContext.keyStorePath" default="etc/keystore"/></Set>
<Set name="KeyStorePassword"><Property name="jetty.sslContext.keyStorePassword" default="OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"/></Set> <Set name="KeyStorePassword"><Property name="jetty.sslContext.keyStorePassword" default="OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"/></Set>
<Set name="KeyManagerPassword"><Property name="jetty.sslContext.keyManagerPassword" default="OBF:1u2u1wml1z7s1z7a1wnl1u2g"/></Set>
<Set name="TrustStorePath"><Property name="jetty.base" default="." />/<Property name="jetty.sslContext.trustStorePath" default="etc/keystore"/></Set> <Set name="TrustStorePath"><Property name="jetty.base" default="." />/<Property name="jetty.sslContext.trustStorePath" default="etc/keystore"/></Set>
<Set name="TrustStorePassword"><Property name="jetty.sslContext.trustStorePassword" default="OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"/></Set> <Set name="TrustStorePassword"><Property name="jetty.sslContext.trustStorePassword" default="OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"/></Set>
<Set name="EndpointIdentificationAlgorithm"></Set> <Set name="EndpointIdentificationAlgorithm"></Set>