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,18 +143,8 @@ public class SslConnection extends AbstractConnection
@Override @Override
public void onOpen() public void onOpen()
{ {
try super.onOpen();
{ getDecryptedEndPoint().getConnection().onOpen();
// Begin the handshake
_sslEngine.beginHandshake();
super.onOpen();
getDecryptedEndPoint().getConnection().onOpen();
}
catch (SSLException x)
{
getEndPoint().close();
throw new RuntimeIOException(x);
}
} }
@Override @Override

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()) if (entry.getKey().equals(objectName))
{ return entry.getValue();
ObjectName bean = entry.getValue();
if (bean.equals(oname))
return entry.getKey();
}
} }
return null; return null;
} }
@ -137,43 +125,43 @@ public class MBeanContainer implements Container.InheritedListener, Dumpable
public void beanAdded(Container parent, Object obj) public void beanAdded(Container parent, Object obj)
{ {
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;
if (parent != null)
{ {
// Is their an object name for the parent parentObjectName = findMBean(parent);
ObjectName pname=null; if (parentObjectName == null)
if (parent!=null)
{ {
pname=_beans.get(parent); // Create the parent bean.
if (pname==null) beanAdded(null, parent);
{ parentObjectName = findMBean(parent);
// create the parent bean
beanAdded(null,parent);
pname=_beans.get(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,43 +171,44 @@ 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;
if (context == null && parentObjectName != null)
context = parentObjectName.getKeyProperty("context");
String context = (mbean instanceof ObjectMBean)?makeName(((ObjectMBean)mbean).getObjectContextBasis()):null; if (context != null && context.length() > 1)
if (context==null && pname!=null)
context=pname.getKeyProperty("context");
if (context != null && context.length()>1)
buf.append("context=").append(context).append(","); buf.append("context=").append(context).append(",");
buf.append("type=").append(type); buf.append("type=").append(type);
String name = (mbean instanceof ObjectMBean)?makeName(((ObjectMBean)mbean).getObjectNameBasis()):context; String name = (mbean instanceof ObjectMBean) ? makeName(((ObjectMBean)mbean).getObjectNameBasis()) : context;
if (name != null && name.length()>1) if (name != null && name.length() > 1)
buf.append(",").append("name=").append(name); buf.append(",").append("name=").append(name);
String basis = buf.toString(); String basis = buf.toString();
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);
} }
} }
@ -227,29 +216,12 @@ public class MBeanContainer implements Container.InheritedListener, Dumpable
public void beanRemoved(Container parent, Object obj) public void beanRemoved(Container parent, Object obj)
{ {
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);
}
}
}
} }
/** /**
@ -258,19 +230,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.dump(out, indent, _beans.entrySet());
ContainerLifeCycle.dumpObject(out,this);
ContainerLifeCycle.dump(out, indent, _beans.entrySet());
}
} }
@Override @Override
@ -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)
.forEach(this::unregister);
}
private void unregister(ObjectName objectName)
{
try
{ {
for (ObjectName oname : _beans.values()) getMBeanServer().unregisterMBean(objectName);
{ if (LOG.isDebugEnabled())
if (oname!=null) LOG.debug("Unregistered {}", objectName);
{ }
try catch (MBeanRegistrationException | InstanceNotFoundException x)
{ {
_mbeanServer.unregisterMBean(oname); LOG.ignore(x);
} }
catch (MBeanRegistrationException | InstanceNotFoundException e) catch (Throwable x)
{ {
LOG.warn(e); 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>