Package org.glassfish.jersey.media.sse

Examples of org.glassfish.jersey.media.sse.EventOutput


        }
    }

    protected Response actSse(final CommandInvoker invoker) {
        final boolean includeResourceLinks = includeResourceLinks();
        EventOutput eo = executeSseCommand(getSubject(), invoker.getCommand(), invoker.getParams(), new ResponseBodyBuilderImpl() {
            @Override
            protected ResponseBody success(ActionReport report) {
                invoker.setResult(report.getExtraProperties());
                SseResponseBody responseBody = new SseResponseBody();
                responseBody.addSuccess(invoker.getSuccessMessage());
View Full Code Here


    }

    protected Response createSse(final CreateCommandInvoker invoker) throws Exception {
        final String collectionUri = uriInfo.getAbsolutePathBuilder().build().toString();
        final boolean includeResourceLinks = includeResourceLinks();
        EventOutput eo = executeSseCommand(getSubject(), invoker.getCommand(), invoker.getParams(), new ResponseBodyBuilderImpl() {
            @Override
            protected ResponseBody success(ActionReport report) {
                invoker.setResult(report.getExtraProperties());
                SseResponseBody responseBody = new SseResponseBody();
                responseBody.addHeader("Location", collectionUri + "/id/" + invoker.getNewItemName())
View Full Code Here

        if (process != null) {
            if (testSource) {
                process.release();
            }
            final EventOutput eventOutput = new EventOutput();
            process.getBroadcaster().add(eventOutput);
            return eventOutput;
        } else {
            throw new NotFoundException();
        }
View Full Code Here

    }

    @DELETE
    public void close() throws IOException {
        eventOutput.close();
        eventOutput = new EventOutput();
    }
View Full Code Here

    @POST
    @Path("domains/{id}")
    @Produces(SseFeature.SERVER_SENT_EVENTS)
    public EventOutput startDomain(@PathParam("id") final String id) {
        final EventOutput seq = new EventOutput();

        new Thread() {
            public void run() {
                try {
                    seq.write(new OutboundEvent.Builder().name("domain-progress").data(String.class, "starting domain " + id + " ...").build());
                    Thread.sleep(200);
                    seq.write(new OutboundEvent.Builder().name("domain-progress").data(String.class, "50%").build());
                    Thread.sleep(200);
                    seq.write(new OutboundEvent.Builder().name("domain-progress").data(String.class, "60%").build());
                    Thread.sleep(200);
                    seq.write(new OutboundEvent.Builder().name("domain-progress").data(String.class, "70%").build());
                    Thread.sleep(200);
                    seq.write(new OutboundEvent.Builder().name("domain-progress").data(String.class, "99%").build());
                    Thread.sleep(200);
                    seq.write(new OutboundEvent.Builder().name("domain-progress").data(String.class, "done").build());
                    seq.close();

                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
View Full Code Here

public class ExampleService {

  @GET
  @Produces( SseFeature.SERVER_SENT_EVENTS )
  public EventOutput getServerSentEvents() {
    final EventOutput eventOutput = new EventOutput();
    new Thread( new Runnable() {

      @Override
      public void run() {
        try {
          for( int i = 0; i < 10; i++ ) {
            Thread.sleep( 1000 );
            final OutboundEvent.Builder eventBuilder = new OutboundEvent.Builder();
            eventBuilder.name( "message-to-client" );
            eventBuilder.data( String.class, "Hello world " + i + "!" );
            final OutboundEvent event = eventBuilder.build();
            eventOutput.write( event );
          }
        } catch( IOException e ) {
          throw new RuntimeException( "Error when writing the event.", e );
        } catch( InterruptedException e ) {
          e.printStackTrace();
        } finally {
          try {
            eventOutput.close();
          } catch( IOException ioClose ) {
            throw new RuntimeException( "Error when closing the event output.", ioClose );
          }
        }
      }
View Full Code Here

    @GET
    @Path("events")
    @Produces(SseFeature.SERVER_SENT_EVENTS)
    public EventOutput itemEvents(
            @HeaderParam(SseFeature.LAST_EVENT_ID_HEADER) @DefaultValue("-1") int lastEventId) {
        final EventOutput eventOutput = new EventOutput();

        if (lastEventId >= 0) {
            LOGGER.info("Received last event id :" + lastEventId);

            // decide the reconnect handling strategy based on current reconnect delay value.
View Full Code Here

    @GET
    @Path("events")
    @Produces(SseFeature.SERVER_SENT_EVENTS)
    public EventOutput connect() {
        EventOutput output = new EventOutput();
        SimEngine.register(output);
        return output;
    }
View Full Code Here

    }

    @DELETE
    public void close() throws IOException {
        eventOutput.close();
        ServerSentEventsResource.setEventOutput(new EventOutput());
    }
View Full Code Here

    @POST
    @Path("domains/{id}")
    @Produces(SseFeature.SERVER_SENT_EVENTS)
    public EventOutput startDomain(@PathParam("id") final String id) {
        final EventOutput seq = new EventOutput();

        new Thread() {
            public void run() {
                try {
                    seq.write(new OutboundEvent.Builder().name("domain-progress").data(String.class, "starting domain " + id + " ...").build());
                    Thread.sleep(200);
                    seq.write(new OutboundEvent.Builder().name("domain-progress").data(String.class, "50%").build());
                    Thread.sleep(200);
                    seq.write(new OutboundEvent.Builder().name("domain-progress").data(String.class, "60%").build());
                    Thread.sleep(200);
                    seq.write(new OutboundEvent.Builder().name("domain-progress").data(String.class, "70%").build());
                    Thread.sleep(200);
                    seq.write(new OutboundEvent.Builder().name("domain-progress").data(String.class, "99%").build());
                    Thread.sleep(200);
                    seq.write(new OutboundEvent.Builder().name("domain-progress").data(String.class, "done").build());
                    seq.close();

                } catch (final InterruptedException | IOException e) {
                    e.printStackTrace();
                }
            }
View Full Code Here

TOP

Related Classes of org.glassfish.jersey.media.sse.EventOutput

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.