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

View File

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