WebSocket - better protection on metadata cache

This commit is contained in:
Joakim Erdfelt 2013-07-30 14:42:08 -07:00
parent 6fc7e23dc0
commit b63a6047d3
1 changed files with 10 additions and 8 deletions

View File

@ -31,15 +31,17 @@ public class JettyAnnotatedImpl implements EventDriverImpl
public EventDriver create(Object websocket, WebSocketPolicy policy)
{
Class<?> websocketClass = websocket.getClass();
JettyAnnotatedMetadata metadata = cache.get(websocketClass);
if (metadata == null)
synchronized (cache)
{
JettyAnnotatedScanner scanner = new JettyAnnotatedScanner();
metadata = scanner.scan(websocketClass);
cache.put(websocketClass,metadata);
JettyAnnotatedMetadata metadata = cache.get(websocketClass);
if (metadata == null)
{
JettyAnnotatedScanner scanner = new JettyAnnotatedScanner();
metadata = scanner.scan(websocketClass);
cache.put(websocketClass,metadata);
}
return new JettyAnnotatedEventDriver(policy,websocket,metadata);
}
return new JettyAnnotatedEventDriver(policy,websocket,metadata);
}
@Override
@ -58,6 +60,6 @@ public class JettyAnnotatedImpl implements EventDriverImpl
@Override
public String toString()
{
return String.format("{} [cache.count=%d]",this.getClass().getSimpleName(),cache.size());
return String.format("%s [cache.count=%d]",this.getClass().getSimpleName(),cache.size());
}
}