• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java InboundEvent类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.glassfish.jersey.media.sse.InboundEvent的典型用法代码示例。如果您正苦于以下问题:Java InboundEvent类的具体用法?Java InboundEvent怎么用?Java InboundEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



InboundEvent类属于org.glassfish.jersey.media.sse包,在下文中一共展示了InboundEvent类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: onEvent

import org.glassfish.jersey.media.sse.InboundEvent; //导入依赖的package包/类
@Override
public void onEvent(InboundEvent inboundEvent) {
	String eventName = inboundEvent.getName();
	if (mainEventName.equals(eventName)) {
		Optional<Response<T>> resp;
		try {
			resp = responseBuilder.buildResponse(inboundEvent.readData(), clazz, uri);
		} catch (Exception e) {
			sseObserver.onParseError(new ParseError(inboundEvent.getId(), e, inboundEvent.getRawData()));
			return;
		}
		sseObserver.onEvent(resp.get());
	} else {
		sseObserver.onSignal(eventName);
	}

}
 
开发者ID:Mercateo,项目名称:rest-hateoas-client,代码行数:18,代码来源:SSEListener.java


示例2: testFetch

import org.glassfish.jersey.media.sse.InboundEvent; //导入依赖的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


示例3: testSse

import org.glassfish.jersey.media.sse.InboundEvent; //导入依赖的package包/类
@Ignore
@Test
public void testSse() {
    Client client = ClientBuilder.newBuilder()
            .register(SseFeature.class).build();
    WebTarget target = client.target("http://localhost:8080/restskol/api")
            .path("events");

    EventInput eventInput = target.request().get(EventInput.class);
    while (!eventInput.isClosed()) {
        final InboundEvent inboundEvent = eventInput.read();
        if (inboundEvent == null) {
            break;
        }

        System.out.println(inboundEvent.getName() + "; "
                + inboundEvent.readData(String.class));
    }
}
 
开发者ID:cloudskol,项目名称:restskol,代码行数:20,代码来源:RestSkolSSEResourceTest.java


示例4: stream

import org.glassfish.jersey.media.sse.InboundEvent; //导入依赖的package包/类
/**
 * Allows to stream SSE events from horizon.
 * Certain endpoints in Horizon can be called in streaming mode using Server-Sent Events.
 * This mode will keep the connection to horizon open and horizon will continue to return
 * responses as ledgers close.
 * @see <a href="http://www.w3.org/TR/eventsource/" target="_blank">Server-Sent Events</a>
 * @see <a href="https://www.stellar.org/developers/horizon/learn/responses.html" target="_blank">Response Format documentation</a>
 * @param listener {@link EventListener} implementation with {@link AccountResponse} type
 * @return EventSource object, so you can <code>close()</code> connection when not needed anymore
 */
public EventSource stream(final EventListener<AccountResponse> listener) {
  Client client = ClientBuilder.newBuilder().register(SseFeature.class).build();
  WebTarget target = client.target(this.buildUri());
  EventSource eventSource = new EventSource(target) {
    @Override
    public void onEvent(InboundEvent inboundEvent) {
      String data = inboundEvent.readData(String.class);
      if (data.equals("\"hello\"")) {
        return;
      }
      AccountResponse account = GsonSingleton.getInstance().fromJson(data, AccountResponse.class);
      listener.onEvent(account);
    }
  };
  return eventSource;
}
 
开发者ID:stellar,项目名称:java-stellar-sdk,代码行数:27,代码来源:AccountsRequestBuilder.java


示例5: stream

import org.glassfish.jersey.media.sse.InboundEvent; //导入依赖的package包/类
/**
 * Allows to stream SSE events from horizon.
 * Certain endpoints in Horizon can be called in streaming mode using Server-Sent Events.
 * This mode will keep the connection to horizon open and horizon will continue to return
 * responses as ledgers close.
 * @see <a href="http://www.w3.org/TR/eventsource/" target="_blank">Server-Sent Events</a>
 * @see <a href="https://www.stellar.org/developers/horizon/learn/responses.html" target="_blank">Response Format documentation</a>
 * @param listener {@link EventListener} implementation with {@link OperationResponse} type
 * @return EventSource object, so you can <code>close()</code> connection when not needed anymore
 */
public EventSource stream(final EventListener<OperationResponse> listener) {
  Client client = ClientBuilder.newBuilder().register(SseFeature.class).build();
  WebTarget target = client.target(this.buildUri());
  EventSource eventSource = new EventSource(target) {
    @Override
    public void onEvent(InboundEvent inboundEvent) {
      String data = inboundEvent.readData(String.class);
      if (data.equals("\"hello\"")) {
        return;
      }
      OperationResponse payment = GsonSingleton.getInstance().fromJson(data, OperationResponse.class);
      listener.onEvent(payment);
    }
  };
  return eventSource;
}
 
开发者ID:stellar,项目名称:java-stellar-sdk,代码行数:27,代码来源:PaymentsRequestBuilder.java


示例6: stream

import org.glassfish.jersey.media.sse.InboundEvent; //导入依赖的package包/类
/**
 * Allows to stream SSE events from horizon.
 * Certain endpoints in Horizon can be called in streaming mode using Server-Sent Events.
 * This mode will keep the connection to horizon open and horizon will continue to return
 * responses as ledgers close.
 * @see <a href="http://www.w3.org/TR/eventsource/" target="_blank">Server-Sent Events</a>
 * @see <a href="https://www.stellar.org/developers/horizon/learn/responses.html" target="_blank">Response Format documentation</a>
 * @param listener {@link EventListener} implementation with {@link EffectResponse} type
 * @return EventSource object, so you can <code>close()</code> connection when not needed anymore
 */
public EventSource stream(final EventListener<EffectResponse> listener) {
  Client client = ClientBuilder.newBuilder().register(SseFeature.class).build();
  WebTarget target = client.target(this.buildUri());
  EventSource eventSource = new EventSource(target) {
    @Override
    public void onEvent(InboundEvent inboundEvent) {
      String data = inboundEvent.readData(String.class);
      if (data.equals("\"hello\"")) {
        return;
      }
      EffectResponse effect = GsonSingleton.getInstance().fromJson(data, EffectResponse.class);
      listener.onEvent(effect);
    }
  };
  return eventSource;
}
 
开发者ID:stellar,项目名称:java-stellar-sdk,代码行数:27,代码来源:EffectsRequestBuilder.java


示例7: stream

import org.glassfish.jersey.media.sse.InboundEvent; //导入依赖的package包/类
/**
 * Allows to stream SSE events from horizon.
 * Certain endpoints in Horizon can be called in streaming mode using Server-Sent Events.
 * This mode will keep the connection to horizon open and horizon will continue to return
 * responses as ledgers close.
 * @see <a href="http://www.w3.org/TR/eventsource/" target="_blank">Server-Sent Events</a>
 * @see <a href="https://www.stellar.org/developers/horizon/learn/responses.html" target="_blank">Response Format documentation</a>
 * @param listener {@link EventListener} implementation with {@link TransactionResponse} type
 * @return EventSource object, so you can <code>close()</code> connection when not needed anymore
 */
public EventSource stream(final EventListener<TransactionResponse> listener) {
  Client client = ClientBuilder.newBuilder().register(SseFeature.class).build();
  WebTarget target = client.target(this.buildUri());
  EventSource eventSource = new EventSource(target) {
    @Override
    public void onEvent(InboundEvent inboundEvent) {
      String data = inboundEvent.readData(String.class);
      if (data.equals("\"hello\"")) {
        return;
      }
      TransactionResponse transaction = GsonSingleton.getInstance().fromJson(data, TransactionResponse.class);
      listener.onEvent(transaction);
    }
  };
  return eventSource;
}
 
开发者ID:stellar,项目名称:java-stellar-sdk,代码行数:27,代码来源:TransactionsRequestBuilder.java


示例8: stream

import org.glassfish.jersey.media.sse.InboundEvent; //导入依赖的package包/类
/**
 * Allows to stream SSE events from horizon.
 * Certain endpoints in Horizon can be called in streaming mode using Server-Sent Events.
 * This mode will keep the connection to horizon open and horizon will continue to return
 * responses as ledgers close.
 * @see <a href="http://www.w3.org/TR/eventsource/" target="_blank">Server-Sent Events</a>
 * @see <a href="https://www.stellar.org/developers/horizon/learn/responses.html" target="_blank">Response Format documentation</a>
 * @param listener {@link EventListener} implementation with {@link LedgerResponse} type
 * @return EventSource object, so you can <code>close()</code> connection when not needed anymore
 */
public EventSource stream(final EventListener<LedgerResponse> listener) {
  Client client = ClientBuilder.newBuilder().register(SseFeature.class).build();
  WebTarget target = client.target(this.buildUri());
  EventSource eventSource = new EventSource(target) {
    @Override
    public void onEvent(InboundEvent inboundEvent) {
      String data = inboundEvent.readData(String.class);
      if (data.equals("\"hello\"")) {
        return;
      }
      LedgerResponse ledger = GsonSingleton.getInstance().fromJson(data, LedgerResponse.class);
      listener.onEvent(ledger);
    }
  };
  return eventSource;
}
 
开发者ID:stellar,项目名称:java-stellar-sdk,代码行数:27,代码来源:LedgersRequestBuilder.java


示例9: test

import org.glassfish.jersey.media.sse.InboundEvent; //导入依赖的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


示例10: subscribeToNewMessageEvents

import org.glassfish.jersey.media.sse.InboundEvent; //导入依赖的package包/类
public void subscribeToNewMessageEvents(Consumer<Message> callback) {
    Thread thread = new Thread() {
        @Override
        public void run() {
            stopListening = false;
            EventInput eventInput = getWebTarget().path("status")
                    .request()
                    .header(HttpHeaders.AUTHORIZATION, getAuthorizationHeader())
                    .get(EventInput.class);
            while (!eventInput.isClosed() && !stopListening) {
                final InboundEvent inboundEvent = eventInput.read();
                if (inboundEvent == null) {
                    // connection has been closed
                    break;
                }
                if ("new-message".equals(inboundEvent.getName())) {
                    Message message = inboundEvent.readData(Message.class);
                    if (message != null) {
                        callback.accept(message);
                    }
                }
            }
        }
    };
    thread.setDaemon(true);
    thread.start();
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:28,代码来源:ConversationService.java


示例11: testSendDataWithValidAuthentication

import org.glassfish.jersey.media.sse.InboundEvent; //导入依赖的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


示例12: testSendDataWithInvalidAuthentication

import org.glassfish.jersey.media.sse.InboundEvent; //导入依赖的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


示例13: onEvent

import org.glassfish.jersey.media.sse.InboundEvent; //导入依赖的package包/类
private void onEvent(InboundEvent inboundEvent) {
    try {
        lastEventTimestamp = System.currentTimeMillis();

        String name = inboundEvent.getName();
        String data = inboundEvent.readData();

        logger.debug("Received '{}' event, data: {}", name, data);

        if (!connected) {
            logger.debug("Connected to streaming events");
            connected = true;
            listeners.forEach(listener -> listener.onConnected());
        }

        if (AUTH_REVOKED.equals(name)) {
            logger.debug("API authorization has been revoked for access token: {}", data);
            listeners.forEach(listener -> listener.onAuthorizationRevoked(data));
        } else if (ERROR.equals(name)) {
            logger.warn("Error occurred: {}", data);
            listeners.forEach(listener -> listener.onError(data));
        } else if (KEEP_ALIVE.equals(name)) {
            logger.debug("Received message to keep connection alive");
        } else if (OPEN.equals(name)) {
            logger.debug("Event stream opened");
        } else if (PUT.equals(name)) {
            logger.debug("Data has changed (or initial data sent)");
            lastReceivedTopLevelData = gson.fromJson(data, TopLevelStreamingData.class).getData();
            listeners.forEach(listener -> listener.onNewTopLevelData(lastReceivedTopLevelData));
        } else {
            logger.debug("Received unhandled event with name '{}' and data '{}'", name, data);
        }
    } catch (Exception e) {
        // catch exceptions here otherwise they will be swallowed by the implementation
        logger.warn("An exception occurred while processing the inbound event", e);
    }
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:38,代码来源:NestStreamingRestClient.java


示例14: doInBackground

import org.glassfish.jersey.media.sse.InboundEvent; //导入依赖的package包/类
@Override
protected String doInBackground(Integer... params) {


    Client client = ClientBuilder.newBuilder()
            .register(SseFeature.class).build();

    String url = UtilityGeneral.getServiceURL(MyApplication.getAppContext()) + "/api/broadcast";

    WebTarget target = client.target(url);



    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));

        publishProgress(inboundEvent.getName() + "; "
                + inboundEvent.readData(String.class));

    }

    return "finished";
}
 
开发者ID:SumeetMoray,项目名称:Nearby-Shops-Distributor-Android-app,代码行数:31,代码来源:SSEExample.java


示例15: eventSourceThree

import org.glassfish.jersey.media.sse.InboundEvent; //导入依赖的package包/类
void eventSourceThree()
    {


        eventSource = new EventSource(target) {
            @Override
            public void onEvent(InboundEvent inboundEvent) {

//                if ("message-to-client".equals(inboundEvent.getName())) {
                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());
            }


        };
    }
 
开发者ID:SumeetMoray,项目名称:Nearby-Shops-End-User-Android-app,代码行数:35,代码来源:IntentServiceSSE.java


示例16: handleNotificationThree

import org.glassfish.jersey.media.sse.InboundEvent; //导入依赖的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.InboundEvent类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java XmlInlineBinaryData类代码示例发布时间:2022-05-22
下一篇:
Java GetTaskAttemptReportRequestPBImpl类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap