Skip to content

Commit

Permalink
Issue #5083 - Convert synchronized usages to AutoLock.
Browse files Browse the repository at this point in the history
Fixes after merge.

Signed-off-by: Simone Bordet <[email protected]>
  • Loading branch information
sbordet committed Aug 4, 2020
1 parent a79c0cf commit 062878f
Showing 1 changed file with 39 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
import org.eclipse.jetty.util.component.DumpableCollection;
import org.eclipse.jetty.util.component.Graceful;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.thread.AutoLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -185,7 +184,6 @@ public enum ContextStatus
DESTROYED
}

private final AutoLock _lock = new AutoLock();
protected ContextStatus _contextStatus = ContextStatus.NOTSET;
protected Context _scontext;
private final AttributesMap _attributes;
Expand Down Expand Up @@ -1846,13 +1844,10 @@ public Class<?> loadClass(String className) throws ClassNotFoundException
if (className == null)
return null;

try (AutoLock l = _lock.lock())
{
if (_classLoader == null)
return Loader.loadClass(className);
if (_classLoader == null)
return Loader.loadClass(className);

return _classLoader.loadClass(className);
}
return _classLoader.loadClass(className);
}

public void addLocaleEncoding(String locale, String encoding)
Expand Down Expand Up @@ -2084,7 +2079,6 @@ public void clearAliasChecks()
*/
public class Context extends StaticContext
{
private final AutoLock _lock = new AutoLock();
protected boolean _enabled = true; // whether or not the dynamic API is enabled for callers
protected boolean _extendedListenerTypes = false;

Expand Down Expand Up @@ -2324,78 +2318,66 @@ public Enumeration<String> getInitParameterNames()
@Override
public Object getAttribute(String name)
{
try (AutoLock l = _lock.lock())
{
Object o = ContextHandler.this.getAttribute(name);
if (o == null)
o = super.getAttribute(name);
return o;
}
Object o = ContextHandler.this.getAttribute(name);
if (o == null)
o = super.getAttribute(name);
return o;
}

@Override
public Enumeration<String> getAttributeNames()
{
try (AutoLock l = _lock.lock())
HashSet<String> set = new HashSet<>();
Enumeration<String> e = super.getAttributeNames();
while (e.hasMoreElements())
{
HashSet<String> set = new HashSet<>();
Enumeration<String> e = super.getAttributeNames();
while (e.hasMoreElements())
{
set.add(e.nextElement());
}
e = ContextHandler.this.getAttributeNames();
while (e.hasMoreElements())
{
set.add(e.nextElement());
}
return Collections.enumeration(set);
set.add(e.nextElement());
}
e = ContextHandler.this.getAttributeNames();
while (e.hasMoreElements())
{
set.add(e.nextElement());
}
return Collections.enumeration(set);
}

@Override
public void setAttribute(String name, Object value)
{
try (AutoLock l = _lock.lock())
{
Object oldValue = super.getAttribute(name);
Object oldValue = super.getAttribute(name);

if (value == null)
super.removeAttribute(name);
else
super.setAttribute(name, value);
if (value == null)
super.removeAttribute(name);
else
super.setAttribute(name, value);

if (!_servletContextAttributeListeners.isEmpty())
{
ServletContextAttributeEvent event = new ServletContextAttributeEvent(_scontext, name, oldValue == null ? value : oldValue);
if (!_servletContextAttributeListeners.isEmpty())
{
ServletContextAttributeEvent event = new ServletContextAttributeEvent(_scontext, name, oldValue == null ? value : oldValue);

for (ServletContextAttributeListener listener : _servletContextAttributeListeners)
{
if (oldValue == null)
listener.attributeAdded(event);
else if (value == null)
listener.attributeRemoved(event);
else
listener.attributeReplaced(event);
}
for (ServletContextAttributeListener listener : _servletContextAttributeListeners)
{
if (oldValue == null)
listener.attributeAdded(event);
else if (value == null)
listener.attributeRemoved(event);
else
listener.attributeReplaced(event);
}
}
}

@Override
public void removeAttribute(String name)
{
try (AutoLock l = _lock.lock())
Object oldValue = super.getAttribute(name);
super.removeAttribute(name);
if (oldValue != null && !_servletContextAttributeListeners.isEmpty())
{
Object oldValue = super.getAttribute(name);
super.removeAttribute(name);
if (oldValue != null && !_servletContextAttributeListeners.isEmpty())
ServletContextAttributeEvent event = new ServletContextAttributeEvent(_scontext, name, oldValue);
for (ServletContextAttributeListener listener : _servletContextAttributeListeners)
{
ServletContextAttributeEvent event = new ServletContextAttributeEvent(_scontext, name, oldValue);
for (ServletContextAttributeListener listener : _servletContextAttributeListeners)
{
listener.attributeRemoved(event);
}
listener.attributeRemoved(event);
}
}
}
Expand Down

0 comments on commit 062878f

Please sign in to comment.