本文整理汇总了Java中org.glassfish.jersey.media.sse.OutboundEvent.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java OutboundEvent.Builder方法的具体用法?Java OutboundEvent.Builder怎么用?Java OutboundEvent.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.glassfish.jersey.media.sse.OutboundEvent
的用法示例。
在下文中一共展示了OutboundEvent.Builder方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
}
示例9: 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;
}
}
示例10: 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);
}
}
示例11: run
import org.glassfish.jersey.media.sse.OutboundEvent; //导入方法依赖的package包/类
@Override
public void run()
{
final OutboundEvent.Builder b = new OutboundEvent.Builder();
b.mediaType( MediaType.TEXT_PLAIN_TYPE );
b.id( String.valueOf( _id++ ) );
b.data( String.class, "The time is " + new Date() );
_broadcaster.broadcast( b.build() );
b.name( "time" );
_broadcaster.broadcast( b.build() );
}
示例12: broadcastMessage
import org.glassfish.jersey.media.sse.OutboundEvent; //导入方法依赖的package包/类
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public String broadcastMessage(String message) {
OutboundEvent.Builder eventBuilder = new OutboundEvent.Builder();
OutboundEvent event = eventBuilder.name("message")
.mediaType(MediaType.APPLICATION_JSON_TYPE)
.data(String.class, message)
.build();
broadcaster.broadcast(event);
return "Message was '" + message + "' broadcast.";
}
示例13: broadcastMessage
import org.glassfish.jersey.media.sse.OutboundEvent; //导入方法依赖的package包/类
@GET
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.TEXT_PLAIN)
public String broadcastMessage(@QueryParam("message") String message) {
OutboundEvent.Builder eventBuilder = new OutboundEvent.Builder();
OutboundEvent event = eventBuilder.name("message")
.mediaType(MediaType.TEXT_PLAIN_TYPE)
.data(String.class, message)
.build();
System.out.println("brcd");
broadcaster.broadcast(event);
return "Message '" + message + "' has been broadcast.";
}
示例14: buildEvent
import org.glassfish.jersey.media.sse.OutboundEvent; //导入方法依赖的package包/类
/**
* Creates a new {@link OutboundEvent} object containing an
* {@link StateBean} created for the given eventType, objectIdentifier,
* eventObject.
*
* @param eventType
* - the event type for the event
* @param objectIdentifier
* - the identifier for the main event object
* @param eventObject
* - the eventObject to be included
* @return a new OutboundEvent.
*/
public static OutboundEvent buildEvent(Object eventObject) {
OutboundEvent.Builder eventBuilder = new OutboundEvent.Builder();
StateBeanMessageBodyWriter writer = new StateBeanMessageBodyWriter();
// OutboundEvent event = eventBuilder.mediaType(MediaType.APPLICATION_JSON_TYPE).data(eventObject).build();
java.util.Date date = new java.util.Date();
OutboundEvent event = eventBuilder.mediaType(MediaType.APPLICATION_JSON_TYPE)
.data(writer.serialize(eventObject)).id(String.valueOf(date.getTime())).build();
return event;
}