/** * Get the original event data string {@link String}. * * @return event data de-serialized into a string. * @throws javax.ws.rs.ProcessingException when provided type can't be read. The thrown exception wraps the original cause. * @since 2.3 */ public String readData() { return readData(STRING_AS_GENERIC_TYPE, null); }
/** * Read event data as a given generic type. * * @param type generic type to be used for event data de-serialization. * @return event data de-serialized as an instance of a given type. * @throws javax.ws.rs.ProcessingException when provided type can't be read. The thrown exception wraps the original cause. * @since 2.3 */ @SuppressWarnings("unused") public <T> T readData(GenericType<T> type) { return readData(type, null); }
@Override public String toString() { String s; try { s = readData(); } catch (ProcessingException e) { s = "<Error reading data into a string>"; } return "InboundEvent{" + "name='" + name + '\'' + ", id='" + id + '\'' + ", comment=" + (comment == null ? "[no comments]" : '\'' + comment + '\'') + ", data=" + s + '}'; }
/** * Read event data as a given Java type. * * @param type Java type to be used for event data de-serialization. * @return event data de-serialized as an instance of a given type. * @throws javax.ws.rs.ProcessingException when provided type can't be read. The thrown exception wraps the original cause. * @since 2.3 */ public <T> T readData(Class<T> type) { return readData(new GenericType<T>(type), null); }
/** * Read event data as a given Java type. * * @param messageType Java type to be used for event data de-serialization. * @param mediaType {@link MediaType media type} to be used for event data de-serialization. * @return event data de-serialized as an instance of a given type. * @throws javax.ws.rs.ProcessingException when provided type can't be read. The thrown exception wraps the original cause. * @since 2.3 */ @SuppressWarnings("unused") public <T> T readData(Class<T> messageType, MediaType mediaType) { return readData(new GenericType<T>(messageType), mediaType); }
/** * Read event data as a given generic type. * * @param type generic type to be used for event data de-serialization. * @return event data de-serialized as an instance of a given type. * @throws javax.ws.rs.ProcessingException when provided type can't be read. The thrown exception wraps the original cause. * @since 2.3 */ @SuppressWarnings("unused") public <T> T readData(GenericType<T> type) { return readData(type, null); }
/** * Get the original event data string {@link String}. * * @return event data de-serialized into a string. * @throws javax.ws.rs.ProcessingException when provided type can't be read. The thrown exception wraps the original cause. * @since 2.3 */ public String readData() { return readData(STRING_AS_GENERIC_TYPE, null); }
/** * Read event data as a given generic type. * * @param type generic type to be used for event data de-serialization. * @return event data de-serialized as an instance of a given type. * @throws javax.ws.rs.ProcessingException when provided type can't be read. The thrown exception wraps the original cause. * @since 2.3 */ @SuppressWarnings("unused") public <T> T readData(GenericType<T> type) { return readData(type, null); }
/** * Read event data as a given generic type. * * @param type generic type to be used for event data de-serialization. * @return event data de-serialized as an instance of a given type. * @throws javax.ws.rs.ProcessingException when provided type can't be read. The thrown exception wraps the original cause. * @since 2.3 */ @SuppressWarnings("unused") public <T> T readData(GenericType<T> type) { return readData(type, null); }
/** * Get the original event data string {@link String}. * * @return event data de-serialized into a string. * @throws javax.ws.rs.ProcessingException when provided type can't be read. The thrown exception wraps the original cause. * @since 2.3 */ public String readData() { return readData(STRING_AS_GENERIC_TYPE, null); }
/** * Get the original event data string {@link String}. * * @return event data de-serialized into a string. * @throws javax.ws.rs.ProcessingException when provided type can't be read. The thrown exception wraps the original cause. * @since 2.3 */ public String readData() { return readData(STRING_AS_GENERIC_TYPE, null); }
@Override public String toString() { String s; try { s = readData(); } catch (ProcessingException e) { s = "<Error reading data into a string>"; } return "InboundEvent{" + "name='" + name + '\'' + ", id='" + id + '\'' + ", comment=" + (comment == null ? "[no comments]" : '\'' + comment + '\'') + ", data=" + s + '}'; }
/** * Read event data as a given Java type. * * @param type Java type to be used for event data de-serialization. * @return event data de-serialized as an instance of a given type. * @throws javax.ws.rs.ProcessingException when provided type can't be read. The thrown exception wraps the original cause. * @since 2.3 */ public <T> T readData(Class<T> type) { return readData(new GenericType<T>(type), null); }
@Override public void onEvent(InboundEvent event) { String payload = event.readData(); if (!node.eventQueue().offer(payload)) { log.error("Unable to process event {} as processing queue is full", payload); } } }
/** * Read event data as a given Java type. * * @param type Java type to be used for event data de-serialization. * @return event data de-serialized as an instance of a given type. * @throws javax.ws.rs.ProcessingException when provided type can't be read. The thrown exception wraps the original cause. * @since 2.3 */ public <T> T readData(Class<T> type) { return readData(new GenericType<T>(type), null); }
/** * Read event data as a given Java type. * * @param type Java type to be used for event data de-serialization. * @return event data de-serialized as an instance of a given type. * @throws javax.ws.rs.ProcessingException when provided type can't be read. The thrown exception wraps the original cause. * @since 2.3 */ public <T> T readData(Class<T> type) { return readData(new GenericType<T>(type), null); }
/** * Read event data as a given Java type. * * @param messageType Java type to be used for event data de-serialization. * @param mediaType {@link MediaType media type} to be used for event data de-serialization. * @return event data de-serialized as an instance of a given type. * @throws javax.ws.rs.ProcessingException when provided type can't be read. The thrown exception wraps the original cause. * @since 2.3 */ @SuppressWarnings("unused") public <T> T readData(Class<T> messageType, MediaType mediaType) { return readData(new GenericType<T>(messageType), mediaType); }
/** * Read event data as a given Java type. * * @param messageType Java type to be used for event data de-serialization. * @param mediaType {@link MediaType media type} to be used for event data de-serialization. * @return event data de-serialized as an instance of a given type. * @throws javax.ws.rs.ProcessingException when provided type can't be read. The thrown exception wraps the original cause. * @since 2.3 */ @SuppressWarnings("unused") public <T> T readData(Class<T> messageType, MediaType mediaType) { return readData(new GenericType<T>(messageType), mediaType); }
/** * Read event data as a given Java type. * * @param messageType Java type to be used for event data de-serialization. * @param mediaType {@link MediaType media type} to be used for event data de-serialization. * @return event data de-serialized as an instance of a given type. * @throws javax.ws.rs.ProcessingException when provided type can't be read. The thrown exception wraps the original cause. * @since 2.3 */ @SuppressWarnings("unused") public <T> T readData(Class<T> messageType, MediaType mediaType) { return readData(new GenericType<T>(messageType), mediaType); }
Client client = ClientBuilder.newBuilder() .register(SseFeature.class).build(); WebTarget target = client.target("http://localhost:9998/events"); EventInput eventInput = target.request().get(EventInput.class); while (!eventInput.isClosed()) { final InboundEvent inboundEvent = eventInput.read(); if (inboundEvent == null) { // connection has been closed break; } System.out.println(inboundEvent.getName() + "; " + inboundEvent.readData(String.class)); }