当前位置: 首页>>代码示例>>Java>>正文


Java OutboundEvent.Builder方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:uweschaefer,项目名称:factcast,代码行数:18,代码来源:FactsObserver.java

示例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);
    }

}
 
开发者ID:uweschaefer,项目名称:factcast,代码行数:19,代码来源:FactsObserver.java

示例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.";
	}
 
开发者ID:SumeetMoray,项目名称:Nearby-Shops-API,代码行数:17,代码来源:Globals.java

示例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.";
	}
 
开发者ID:SumeetMoray,项目名称:Nearby-Shops-API,代码行数:17,代码来源:Globals.java

示例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);
        }
    }
}
 
开发者ID:Mobility-Services-Lab,项目名称:AutomotiveServiceBus,代码行数:20,代码来源:EventOutputWrapper.java

示例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();
	}
}
 
开发者ID:nobeh,项目名称:visactor,代码行数:27,代码来源:EventResource.java

示例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 );
      }
    }
  }
}
 
开发者ID:realityforge,项目名称:gwt-packetio-example,代码行数:25,代码来源:TimeGenerator.java

示例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);
    }
}
 
开发者ID:uweschaefer,项目名称:factcast,代码行数:16,代码来源:FactsObserver.java

示例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;
        }

    }
 
开发者ID:uweschaefer,项目名称:factcast,代码行数:15,代码来源:FactsObserver.java

示例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);
    }
}
 
开发者ID:vgoldin,项目名称:cqrs-eventsourcing-kafka,代码行数:16,代码来源:InventoryItemResource.java

示例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() );
}
 
开发者ID:realityforge,项目名称:gwt-eventsource-example,代码行数:14,代码来源:TimeGenerator.java

示例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.";
}
 
开发者ID:csrinaldi,项目名称:powercode,代码行数:15,代码来源:SseResource.java

示例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.";
}
 
开发者ID:FTSRG,项目名称:mondo-collab-framework,代码行数:20,代码来源:BroadcasterResource.java

示例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;
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:25,代码来源:SseUtil.java


注:本文中的org.glassfish.jersey.media.sse.OutboundEvent.Builder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。