418625 - WebSocket / Jsr RemoteEndpoint.sendObject(java.nio.HeapByteBuffer) doesn't find encoder

+ Adding fallback lookup using isAssignable(type) if basic map based
  lookup fails first.  Remembers successful isAssignable(type) match
  for future lookups via basic map approach.
This commit is contained in:
Joakim Erdfelt 2013-10-03 14:05:04 -07:00
parent 1620b34a6e
commit 8d5013e15f
1 changed files with 26 additions and 0 deletions

View File

@ -18,6 +18,7 @@
package org.eclipse.jetty.websocket.jsr356.metadata;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@ -144,12 +145,37 @@ public abstract class CoderMetadataSet<T, M extends CoderMetadata<T>> implements
{
Integer idx = typeMap.get(type);
if (idx == null)
{
// Quick lookup failed, try slower lookup via isAssignable instead
idx = getMetadataByAssignableType(type);
if (idx != null)
{
// add new entry map
typeMap.put(type,idx);
}
}
// If idx is STILL null, we've got no match
if (idx == null)
{
return null;
}
return metadatas.get(idx);
}
private Integer getMetadataByAssignableType(Class<?> type)
{
for (Map.Entry<Class<?>, Integer> entry : typeMap.entrySet())
{
if (entry.getKey().isAssignableFrom(type))
{
return entry.getValue();
}
}
return null;
}
@Override
public Iterator<M> iterator()
{