本文整理汇总了Java中org.glassfish.jersey.media.sse.OutboundEvent类的典型用法代码示例。如果您正苦于以下问题:Java OutboundEvent类的具体用法?Java OutboundEvent怎么用?Java OutboundEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OutboundEvent类属于org.glassfish.jersey.media.sse包,在下文中一共展示了OutboundEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onNext
import org.glassfish.jersey.media.sse.OutboundEvent; //导入依赖的package包/类
@Override
public void onNext(Fact f) {
final OutboundEvent.Builder eventBuilder = new OutboundEvent.Builder();
eventBuilder.name("new-fact");
ObjectWithSchema<?> withSchema = createPayload(f, fullOutputMode);
eventBuilder.data(withSchema);
eventBuilder.mediaType(MediaType.APPLICATION_JSON_TYPE);
eventBuilder.id(f.id().toString());
final OutboundEvent event = eventBuilder.build();
try {
eventOutput.write(event);
} catch (IOException e) {
unsubscribe();
log.debug("Error while writing into the pipe", e);
}
}
示例2: onComplete
import org.glassfish.jersey.media.sse.OutboundEvent; //导入依赖的package包/类
@Override
public void onComplete() {
final OutboundEvent.Builder eventBuilder = new OutboundEvent.Builder();
eventBuilder.name("complete");
eventBuilder.comment("Signal event for completion");
eventBuilder.data("{\"complete\":true}");
final OutboundEvent event = eventBuilder.build();
try {
eventOutput.write(event);
eventOutput.close();
subcription.get().close();
} catch (Exception e) {
unsubscribe();
log.debug("Error while writing into the pipe", e);
}
}
示例3: broadcastMessageToShop
import org.glassfish.jersey.media.sse.OutboundEvent; //导入依赖的package包/类
public static String broadcastMessageToShop(String message, int shopID) {
OutboundEvent.Builder eventBuilder = new OutboundEvent.Builder();
OutboundEvent event = eventBuilder.name("Order Received !")
.mediaType(MediaType.TEXT_PLAIN_TYPE)
.data(String.class, message)
.build();
if(broadcasterMap.get(shopID)!=null)
{
broadcasterMap.get(shopID).broadcast(event);
}
return "Message '" + message + "' has been broadcast.";
}
示例4: broadcastMessageToEndUser
import org.glassfish.jersey.media.sse.OutboundEvent; //导入依赖的package包/类
public static String broadcastMessageToEndUser(String title, String message, int endUserID) {
OutboundEvent.Builder eventBuilder = new OutboundEvent.Builder();
OutboundEvent event = eventBuilder.name(title)
.mediaType(MediaType.TEXT_PLAIN_TYPE)
.data(String.class, message)
.build();
if(broadcasterMapEndUser.get(endUserID)!=null)
{
broadcasterMapEndUser.get(endUserID).broadcast(event);
}
return "Message '" + message + "' has been broadcast.";
}
示例5: update
import org.glassfish.jersey.media.sse.OutboundEvent; //导入依赖的package包/类
@Override
public void update(Observable observable, Object newValue) {
LOG.info("Building an outbound event...");
final OutboundEvent.Builder eventBuilder = new OutboundEvent.Builder();
eventBuilder.data(String.class, newValue + "\n\n");
final OutboundEvent event = eventBuilder.build();
try {
LOG.info("Writing the event...");
eventOutput.write(event);
} catch (IOException e) {
try {
eventOutput.close();
} catch (IOException ioClose) {
LOG.error("Error when closing the event output: {}", ioClose);
} finally {
observable.deleteObserver(this);
}
}
}
示例6: broadcast
import org.glassfish.jersey.media.sse.OutboundEvent; //导入依赖的package包/类
/**
* Publishes the events since the last event ID.
*
* @param lastEventId
* the ID of the event that last was published.
* @return the new last event ID.
*/
protected long broadcast(long lastEventId) {
OutboundEvent.Builder oeb = new OutboundEvent.Builder();
List<Event> events = store.events(lastEventId);
oeb.name("event");
long newLastEventId = events.get(events.size() - 1).getTimestamp();
oeb.id(Long.toString(newLastEventId));
oeb.reconnectDelay(1000);
oeb.mediaType(MediaType.APPLICATION_JSON_TYPE);
oeb.data(Event.class, events);
try {
OutboundEvent event = oeb.build();
broadcaster.broadcast(event);
logger.info("Flushed SSE event: {}", event);
return this.lastEventId.getAndSet(newLastEventId);
} catch (Exception x) {
logger.error("Failed flushing SSE event: {}", x);
return this.lastEventId.get();
}
}
示例7: run
import org.glassfish.jersey.media.sse.OutboundEvent; //导入依赖的package包/类
@Override
public void run()
{
final String message = "The time is " + new Date();
final OutboundEvent.Builder b = new OutboundEvent.Builder();
b.mediaType( MediaType.TEXT_PLAIN_TYPE );
b.data( String.class, "sse: " + message );
_broadcaster.broadcast( b.build() );
synchronized ( _waiters )
{
final Iterator<AsyncResponse> iterator = _waiters.iterator();
while( iterator.hasNext() )
{
final AsyncResponse response = iterator.next();
iterator.remove();
if( !response.isCancelled() )
{
response.resume( "lp: " + message );
}
}
}
}
示例8: onEvent
import org.glassfish.jersey.media.sse.OutboundEvent; //导入依赖的package包/类
@Subscribe
public void onEvent(Event event) {
try {
String eventData = JacksonMarshaller.marshal(event);
OutboundEvent outboundEvent = new OutboundEvent.Builder()
.mediaType(MediaType.APPLICATION_JSON_TYPE)
.data(String.class, eventData)
.build();
sseBroadcaster.broadcast(outboundEvent);
} catch (JsonProcessingException e) {
logger.error("Failed marshalling event for REST SSE events", e);
}
}
示例9: onCatchup
import org.glassfish.jersey.media.sse.OutboundEvent; //导入依赖的package包/类
@Override
public void onCatchup() {
final OutboundEvent.Builder eventBuilder = new OutboundEvent.Builder();
eventBuilder.name("catchup");
eventBuilder.comment("Signal event for catching up");
eventBuilder.data("{\"catchup\":true}");
final OutboundEvent event = eventBuilder.build();
try {
eventOutput.write(event);
} catch (IOException e) {
unsubscribe();
log.debug("Error while writing into the pipe", e);
}
}
示例10: isConnectionAlive
import org.glassfish.jersey.media.sse.OutboundEvent; //导入依赖的package包/类
boolean isConnectionAlive() {
final OutboundEvent.Builder eventBuilder = new OutboundEvent.Builder();
eventBuilder.name("keep-alive");
eventBuilder.comment("Signal event for keep-alive");
final OutboundEvent event = eventBuilder.build();
try {
eventOutput.write(event);
return true;
} catch (Exception e) {
return false;
}
}
示例11: testOnNext
import org.glassfish.jersey.media.sse.OutboundEvent; //导入依赖的package包/类
@Test
public void testOnNext() throws Exception {
uut.onNext(TestFacts.one);
ArgumentCaptor<OutboundEvent> cap = ArgumentCaptor.forClass(OutboundEvent.class);
verify(eventOutput).write(cap.capture());
OutboundEvent ev = cap.getValue();
@SuppressWarnings("unchecked")
JsonHyperSchema jsonHyperSchema = ((ObjectWithSchema<Void>) ev.getData()).schema;
assertTrue(jsonHyperSchema.getByRel(Rel.CANONICAL).isPresent());
assertThat(ev.getId(), is(TestFacts.one.id().toString()));
}
示例12: testOnCatchup
import org.glassfish.jersey.media.sse.OutboundEvent; //导入依赖的package包/类
@Test
public void testOnCatchup() throws Exception {
uut.onCatchup();
ArgumentCaptor<OutboundEvent> cap = ArgumentCaptor.forClass(OutboundEvent.class);
verify(eventOutput).write(cap.capture());
OutboundEvent event = cap.getValue();
assertThat(event, is(notNullValue()));
assertThat(event.getName(), is("catchup"));
verifyNoMoreInteractions(subscription, linkFatory, eventOutput);
}
示例13: testOnComplete
import org.glassfish.jersey.media.sse.OutboundEvent; //导入依赖的package包/类
@Test
public void testOnComplete() throws Exception {
uut.onComplete();
ArgumentCaptor<OutboundEvent> cap = ArgumentCaptor.forClass(OutboundEvent.class);
verify(eventOutput).write(cap.capture());
OutboundEvent event = cap.getValue();
assertThat(event, is(notNullValue()));
assertThat(event.getName(), is("complete"));
verify(subscription).close();
verify(eventOutput).close();
verifyNoMoreInteractions(subscription, linkFatory, eventOutput);
}
示例14: test_isConnectionAlive_verifySignalEvent
import org.glassfish.jersey.media.sse.OutboundEvent; //导入依赖的package包/类
@Test
public void test_isConnectionAlive_verifySignalEvent() throws IOException {
// when
uut.isConnectionAlive();
// then
ArgumentCaptor<OutboundEvent> capture = ArgumentCaptor.forClass(OutboundEvent.class);
verify(eventOutput).write(capture.capture());
OutboundEvent value = capture.getValue();
assertEquals("keep-alive", value.getName());
}
示例15: update
import org.glassfish.jersey.media.sse.OutboundEvent; //导入依赖的package包/类
@Override
public void update(Observable o, Object arg) {
if (o instanceof StreamBroadcaster && arg != null) {
EventEnvelope e = (EventEnvelope) arg;
OutboundEvent.Builder eventBuilder = new OutboundEvent.Builder();
OutboundEvent event = eventBuilder
.mediaType(MediaType.APPLICATION_JSON_TYPE)
.id(e.eventId.orElse(null))
.name(e.eventType)
.data(e.eventData)
.build();
BROADCASTER.broadcast(event);
}
}