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,18 +143,8 @@ 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);
}
super.onOpen();
getDecryptedEndPoint().getConnection().onOpen();
}
@Override

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)
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 (bean.equals(oname))
return entry.getKey();
}
if (entry.getKey().equals(objectName))
return entry.getValue();
}
return null;
}
@ -137,43 +125,43 @@ public class MBeanContainer implements Container.InheritedListener, Dumpable
public void beanAdded(Container parent, Object obj)
{
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;
if (parent != null)
{
// Is their an object name for the parent
ObjectName pname=null;
if (parent!=null)
parentObjectName = findMBean(parent);
if (parentObjectName == null)
{
pname=_beans.get(parent);
if (pname==null)
{
// create the parent bean
beanAdded(null,parent);
pname=_beans.get(parent);
}
// Create the parent bean.
beanAdded(null, parent);
parentObjectName = findMBean(parent);
}
}
// Does an mbean already exist?
if (obj == null || _beans.containsKey(obj))
return;
// 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)
{
//if no explicit domain, create one
// No override of the mbean's ObjectName, so make a generic one.
if (objectName == null)
{
// If no explicit domain, create one.
String domain = _domain;
if (domain == null)
domain = obj.getClass().getPackage().getName();
@ -183,43 +171,44 @@ public class MBeanContainer implements Container.InheritedListener, Dumpable
if (dot >= 0)
type = type.substring(dot + 1);
StringBuilder buf = new StringBuilder();
StringBuffer buf = new StringBuffer();
String context = (mbean instanceof ObjectMBean) ? makeName(((ObjectMBean)mbean).getObjectContextBasis()) : null;
if (context == null && parentObjectName != null)
context = parentObjectName.getKeyProperty("context");
String context = (mbean instanceof ObjectMBean)?makeName(((ObjectMBean)mbean).getObjectContextBasis()):null;
if (context==null && pname!=null)
context=pname.getKeyProperty("context");
if (context != null && context.length()>1)
if (context != null && context.length() > 1)
buf.append("context=").append(context).append(",");
buf.append("type=").append(type);
String name = (mbean instanceof ObjectMBean)?makeName(((ObjectMBean)mbean).getObjectNameBasis()):context;
if (name != null && name.length()>1)
String name = (mbean instanceof ObjectMBean) ? makeName(((ObjectMBean)mbean).getObjectNameBasis()) : context;
if (name != null && name.length() > 1)
buf.append(",").append("name=").append(name);
String basis = buf.toString();
AtomicInteger count = __unique.get(basis);
if (count==null)
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);
}
}
@ -227,29 +216,12 @@ public class MBeanContainer implements Container.InheritedListener, Dumpable
public void beanRemoved(Container parent, Object obj)
{
if (LOG.isDebugEnabled())
LOG.debug("beanRemoved {}",obj);
try (Locker.Lock lock = _lock.lock())
{
ObjectName bean = _beans.remove(obj);
LOG.debug("beanRemoved {}", 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);
}
/**
@ -258,19 +230,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(' ', '_');
if (basis == null)
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());
}
ContainerLifeCycle.dumpObject(out,this);
ContainerLifeCycle.dump(out, indent, _beans.entrySet());
}
@Override
@ -281,22 +256,26 @@ public class MBeanContainer implements Container.InheritedListener, Dumpable
public void destroy()
{
try (Locker.Lock lock = _lock.lock())
_beans.values().stream()
.filter(objectName -> objectName != null)
.forEach(this::unregister);
}
private void unregister(ObjectName objectName)
{
try
{
for (ObjectName oname : _beans.values())
{
if (oname!=null)
{
try
{
_mbeanServer.unregisterMBean(oname);
}
catch (MBeanRegistrationException | InstanceNotFoundException e)
{
LOG.warn(e);
}
}
}
getMBeanServer().unregisterMBean(objectName);
if (LOG.isDebugEnabled())
LOG.debug("Unregistered {}", objectName);
}
catch (MBeanRegistrationException | InstanceNotFoundException x)
{
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>