本文整理汇总了Java中org.glassfish.jersey.media.sse.EventListener类的典型用法代码示例。如果您正苦于以下问题:Java EventListener类的具体用法?Java EventListener怎么用?Java EventListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EventListener类属于org.glassfish.jersey.media.sse包,在下文中一共展示了EventListener类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testFetch
import org.glassfish.jersey.media.sse.EventListener; //导入依赖的package包/类
@Test
public void testFetch() throws Exception {
final CountDownLatch latch = new CountDownLatch(10);
final EventSource source = client.fetch();
final EventListener listener = new EventListener() {
@Override
public void onEvent(InboundEvent inboundEvent) {
latch.countDown();
}
};
source.register(listener, "message-to-client");
source.open();
latch.await(10, TimeUnit.SECONDS);
source.close();
}
开发者ID:smoketurner,项目名称:pipeline,代码行数:17,代码来源:PipelineClientTest.java
示例2: test
import org.glassfish.jersey.media.sse.EventListener; //导入依赖的package包/类
@Test
public void test() throws Exception {
Client client = ClientBuilder.newBuilder().register(SseFeature.class).build();
WebTarget target = client.target(uri("/events"));
List<InboundEvent> events = new ArrayList<>();
CountDownLatch latch = new CountDownLatch(3);
EventSource eventSource = EventSource.target(target).build();
EventListener listener = inboundEvent -> {
events.add(inboundEvent);
latch.countDown();
};
eventSource.register(listener);
eventSource.open();
sse.send(event("Hello 1\nLine 1").withId("1").withName("hello1"));
sse.send(event("Hello 2\nLine 2").withId("2").withName("hello2"));
sse.send(event("Hello 3\nLine 3").withId("3").withName("hello3"));
assertTrue(latch.await(500, TimeUnit.MILLISECONDS));
assertThat(events.get(1).getId(), equalTo("2"));
assertThat(events.get(1).getName(), equalTo("hello2"));
assertThat(events.get(1).readData(), equalTo("Hello 2\nLine 2"));
}
开发者ID:nosceon,项目名称:titanite,代码行数:27,代码来源:ServerSentEventsE2ETest.java
示例3: testSendDataWithValidAuthentication
import org.glassfish.jersey.media.sse.EventListener; //导入依赖的package包/类
@Test
public void testSendDataWithValidAuthentication() throws InterruptedException {
//given
final ServerSentEventService serverSentEventService = Application.getInstance(ServerSentEventService.class);
final Config config = Application.getInstance(Config.class);
final String data = "Server sent data with authentication FTW!";
//when
final WebTarget target = ClientBuilder.newBuilder()
.register(SseFeature.class)
.build()
.target("http://" + config.getConnectorHttpHost() + ":" + config.getConnectorHttpPort() + "/sseauth");
final CustomWebTarget customWebTarget = new CustomWebTarget(target, new Cookie(COOKIE_NAME, VALID_COOKIE_VALUE));
final EventSource eventSource = EventSource.target(customWebTarget).build();
final EventListener listener = new EventListener() {
@Override
public void onEvent(InboundEvent inboundEvent) {
if (StringUtils.isBlank(eventData)) {
eventData = inboundEvent.readData(String.class);
}
}
};
eventSource.register(listener);
eventSource.open();
serverSentEventService.send("/sseauth", data);
//then
await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> assertThat(eventData, equalTo(data)));
eventSource.close();
}
开发者ID:svenkubiak,项目名称:mangooio,代码行数:32,代码来源:ServerSentEventServiceTest.java
示例4: testSendDataWithInvalidAuthentication
import org.glassfish.jersey.media.sse.EventListener; //导入依赖的package包/类
@Test
public void testSendDataWithInvalidAuthentication() throws InterruptedException {
//given
final ServerSentEventService serverSentEventService = Application.getInstance(ServerSentEventService.class);
final Config config = Application.getInstance(Config.class);
final String data = "Server sent data with authentication FTW!";
//when
final WebTarget target = ClientBuilder.newBuilder()
.register(SseFeature.class)
.build()
.target("http://" + config.getConnectorHttpHost() + ":" + config.getConnectorHttpPort() + "/sseauth");
final CustomWebTarget customWebTarget = new CustomWebTarget(target, new Cookie(COOKIE_NAME, INVALID_COOKIE_VALUE));
final EventSource eventSource = EventSource.target(customWebTarget).build();
final EventListener listener = new EventListener() {
@Override
public void onEvent(InboundEvent inboundEvent) {
if (StringUtils.isBlank(eventData)) {
eventData = inboundEvent.readData(String.class);
}
}
};
eventSource.register(listener);
eventSource.open();
serverSentEventService.send("/sseauth", data);
//then
await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> assertThat(eventData, not(equalTo(data))));
eventSource.close();
}
开发者ID:svenkubiak,项目名称:mangooio,代码行数:32,代码来源:ServerSentEventServiceTest.java
示例5: buildEventListener
import org.glassfish.jersey.media.sse.EventListener; //导入依赖的package包/类
private EventListener buildEventListener(Consumer<SparkEvent> eventHandler) {
return inboundEvent -> {
String rawJson = inboundEvent.readData().replaceFirst("^\\{", "{\"name\":\"" + inboundEvent.getName() + "\",");
if(rawJson.isEmpty()) return;
SparkEvent sparkEvent = (SparkEvent) SparkRestApi.jsonToObject(rawJson, new TypeReference<SparkEvent>() {});
eventHandler.accept(sparkEvent);
};
}
开发者ID:grantwest,项目名称:SparkJ,代码行数:9,代码来源:SparkEventStream.java
示例6: handleNotificationThree
import org.glassfish.jersey.media.sse.EventListener; //导入依赖的package包/类
void handleNotificationThree()
{
Client client = ClientBuilder.newBuilder()
.register(SseFeature.class).build();
int endUserID = -1;
if(UtilityLogin.getEndUser(getBaseContext())!=null)
{
endUserID = UtilityLogin.getEndUser(getBaseContext()).getEndUserID();
}
else
{
return;
}
System.out.println("On Handle Intent : Handle Notification !");
String url = UtilityGeneral.getServiceURL(MyApplication.getAppContext()) + "/api/v1/EndUser/Notifications/" + String.valueOf(endUserID);
System.out.println("URL : " + url);
// logMessage("URL : " + url);
WebTarget target = client.target(url);
eventSourceThree = EventSource.target(target)
.reconnectingEvery(5,TimeUnit.SECONDS)
.build();
EventListener listener = new EventListener() {
@Override
public void onEvent(InboundEvent inboundEvent) {
System.out.println(inboundEvent.getName() + "; "
+ inboundEvent.readData(String.class));
String eventName = inboundEvent.getName();
String message = inboundEvent.readData(String.class);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(IntentServiceSSE.this)
.setContentTitle(eventName)
.setContentText(message)
.setContentInfo(message)
.setSmallIcon(R.mipmap.shopping_basket_png)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(2, mBuilder.build());
}
};
eventSourceThree.register(listener);
eventSourceThree.open();
}
开发者ID:SumeetMoray,项目名称:Nearby-Shops-End-User-Android-app,代码行数:70,代码来源:IntentServiceSSE.java
注:本文中的org.glassfish.jersey.media.sse.EventListener类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论