use of org.eclipse.jetty.websocket.jsr356.metadata.MessageHandlerMetadata in project jetty.project by eclipse.
the class MessageHandlerFactoryTest method testStringPartial.
@Test
public void testStringPartial() throws DeploymentException {
List<MessageHandlerMetadata> metadatas = factory.getMetadata(StringPartialHandler.class);
Assert.assertThat("Metadata.list.size", metadatas.size(), is(1));
MessageHandlerMetadata handlerMetadata = metadatas.get(0);
DecoderMetadata decoderMetadata = decoders.getMetadataFor(handlerMetadata.getMessageClass());
Assert.assertThat("Message Type", decoderMetadata.getMessageType(), is(MessageType.TEXT));
Assert.assertThat("Message Class", handlerMetadata.getMessageClass(), is((Type) String.class));
}
use of org.eclipse.jetty.websocket.jsr356.metadata.MessageHandlerMetadata in project jetty.project by eclipse.
the class MessageHandlerFactoryTest method testByteArrayPartial.
@Test
public void testByteArrayPartial() throws DeploymentException {
List<MessageHandlerMetadata> metadatas = factory.getMetadata(ByteArrayPartialHandler.class);
Assert.assertThat("Metadata.list.size", metadatas.size(), is(1));
MessageHandlerMetadata handlerMetadata = metadatas.get(0);
DecoderMetadata decoderMetadata = decoders.getMetadataFor(handlerMetadata.getMessageClass());
Assert.assertThat("Message Type", decoderMetadata.getMessageType(), is(MessageType.BINARY));
Assert.assertThat("Message Class", handlerMetadata.getMessageClass(), is((Type) byte[].class));
}
use of org.eclipse.jetty.websocket.jsr356.metadata.MessageHandlerMetadata in project jetty.project by eclipse.
the class JsrSession method removeMessageHandler.
@Override
public void removeMessageHandler(MessageHandler handler) {
synchronized (wrappers) {
try {
for (MessageHandlerMetadata metadata : messageHandlerFactory.getMetadata(handler.getClass())) {
DecoderMetadata decoder = decoderFactory.getMetadataFor(metadata.getMessageClass());
MessageType key = decoder.getMessageType();
wrappers[key.ordinal()] = null;
}
updateMessageHandlerSet();
} catch (IllegalStateException e) {
LOG.warn("Unable to identify MessageHandler: " + handler.getClass().getName(), e);
}
}
}
use of org.eclipse.jetty.websocket.jsr356.metadata.MessageHandlerMetadata in project jetty.project by eclipse.
the class JsrSession method addMessageHandler.
@Override
public void addMessageHandler(MessageHandler handler) throws IllegalStateException {
Objects.requireNonNull(handler, "MessageHandler cannot be null");
synchronized (wrappers) {
for (MessageHandlerMetadata metadata : messageHandlerFactory.getMetadata(handler.getClass())) {
DecoderFactory.Wrapper wrapper = decoderFactory.getWrapperFor(metadata.getMessageClass());
if (wrapper == null) {
StringBuilder err = new StringBuilder();
err.append("Unable to find decoder for type <");
err.append(metadata.getMessageClass().getName());
err.append("> used in <");
err.append(metadata.getHandlerClass().getName());
err.append(">");
throw new IllegalStateException(err.toString());
}
MessageType key = wrapper.getMetadata().getMessageType();
MessageHandlerWrapper other = wrappers[key.ordinal()];
if (other != null) {
StringBuilder err = new StringBuilder();
err.append("Encountered duplicate MessageHandler handling message type <");
err.append(wrapper.getMetadata().getObjectType().getName());
err.append(">, ").append(metadata.getHandlerClass().getName());
err.append("<");
err.append(metadata.getMessageClass().getName());
err.append("> and ");
err.append(other.getMetadata().getHandlerClass().getName());
err.append("<");
err.append(other.getMetadata().getMessageClass().getName());
err.append("> both implement this message type");
throw new IllegalStateException(err.toString());
} else {
MessageHandlerWrapper handlerWrapper = new MessageHandlerWrapper(handler, metadata, wrapper);
wrappers[key.ordinal()] = handlerWrapper;
}
}
// Update handlerSet
updateMessageHandlerSet();
}
}
use of org.eclipse.jetty.websocket.jsr356.metadata.MessageHandlerMetadata in project jetty.project by eclipse.
the class MessageHandlerFactory method register.
public List<MessageHandlerMetadata> register(Class<? extends MessageHandler> handler) {
List<MessageHandlerMetadata> metadatas = new ArrayList<>();
boolean partial = false;
if (MessageHandler.Partial.class.isAssignableFrom(handler)) {
if (LOG.isDebugEnabled()) {
LOG.debug("supports Partial: {}", handler);
}
partial = true;
Class<?> onMessageClass = ReflectUtils.findGenericClassFor(handler, MessageHandler.Partial.class);
if (LOG.isDebugEnabled()) {
LOG.debug("Partial message class: {}", onMessageClass);
}
metadatas.add(new MessageHandlerMetadata(handler, onMessageClass, partial));
}
if (MessageHandler.Whole.class.isAssignableFrom(handler)) {
if (LOG.isDebugEnabled()) {
LOG.debug("supports Whole: {}", handler.getName());
}
partial = false;
Class<?> onMessageClass = ReflectUtils.findGenericClassFor(handler, MessageHandler.Whole.class);
if (LOG.isDebugEnabled()) {
LOG.debug("Whole message class: {}", onMessageClass);
}
metadatas.add(new MessageHandlerMetadata(handler, onMessageClass, partial));
}
registered.put(handler, metadatas);
return metadatas;
}
Aggregations