Package org.glassfish.jersey.media.sse

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


            }
        }
    }
   
    protected Response executeCommandAsSse(ParameterMap data) {
        EventChannel ec = ResourceUtil.runCommandWithSse(commandName, data, null, null);
        return Response.status(HttpURLConnection.HTTP_OK).entity(ec).build();
    }
View Full Code Here


        commandInvocation
                .outbound(new RestPayloadImpl.Outbound(false))
                .subject(getSubject())
                .managedJob()
                .parameters(params);
        final EventChannel ec = new EventChannel();
        AdminCommandListener listener = new AdminCommandListener() {
           
                    private AdminCommandEventBroker broker;
                   
                    private void unregister() {
                        if (broker != null) {
                            broker.unregisterListener(this);
                        }
                    }
                   
                    @Override
                    public void onAdminCommandEvent(String name, Object event) {
                        if (name == null || event == null) {
                            return;
                        }
                        if (BrokerListenerRegEvent.EVENT_NAME_LISTENER_REG.equals(name)) {
                            BrokerListenerRegEvent blre = (BrokerListenerRegEvent) event;
                            broker = blre.getBroker();
                            return;
                        }
                        if (name.startsWith(AdminCommandEventBroker.LOCAL_EVENT_PREFIX)) {
                            return; //Prevent events from client to be send back to client
                        }
                        if (ec.isClosed()) {
                            unregister();
                            return;
                        }
                        if ((event instanceof Number) ||
                            (event instanceof CharSequence) ||
                            (event instanceof Boolean)) {
                            event = String.valueOf(event);
                        }
                        OutboundEvent outEvent = new OutboundEvent.Builder()
                                                    .name(name)
                                                    .mediaType(event instanceof String ?
                                                            MediaType.TEXT_PLAIN_TYPE :
                                                            MediaType.APPLICATION_JSON_TYPE)
                                                    .data(event.getClass(), event)
                                                    .build();
                        try {
                            ec.write(outEvent);
                        } catch (Exception ex) {
                            if (logger.isLoggable(Level.FINE)) {
                                logger.log(Level.FINE, strings.getLocalString("sse.writeevent.exception",
                                        "Can not write object as SSE (type = {0})",
                                        event.getClass().getName()), ex);
                            }
                            if (ec.isClosed()) {
                                unregister();
                            }
                        }
                    }
                };
View Full Code Here

        commandInvocation
                .outbound(new RestPayloadImpl.Outbound(false))
                .subject(getSubject())
                .managedJob()
                .parameters(params);
        final EventChannel ec = new EventChannel();
        AdminCommandListener listener = new AdminCommandListener() {
           
                    private AdminCommandEventBroker broker;
                   
                    private void unregister() {
                        if (broker != null) {
                            broker.unregisterListener(this);
                        }
                    }
                   
                    @Override
                    public void onAdminCommandEvent(String name, Object event) {
                        if (name == null || event == null) {
                            return;
                        }
                        if (BrokerListenerRegEvent.EVENT_NAME_LISTENER_REG.equals(name)) {
                            BrokerListenerRegEvent blre = (BrokerListenerRegEvent) event;
                            broker = blre.getBroker();
                            return;
                        }
                        if (name.startsWith(AdminCommandEventBroker.LOCAL_EVENT_PREFIX)) {
                            return; //Prevent events from client to be send back to client
                        }
                        if (ec.isClosed()) {
                            unregister();
                            return;
                        }
                        if ((event instanceof Number) ||
                            (event instanceof CharSequence) ||
                            (event instanceof Boolean)) {
                            event = String.valueOf(event);
                        }
                        OutboundEvent outEvent = new OutboundEvent.Builder()
                                                    .name(name)
                                                    .mediaType(event instanceof String ?
                                                            MediaType.TEXT_PLAIN_TYPE :
                                                            MediaType.APPLICATION_JSON_TYPE)
                                                    .data(event.getClass(), event)
                                                    .build();
                        try {
                            ec.write(outEvent);
                        } catch (Exception ex) {
                            if (logger.isLoggable(Level.FINE)) {
                                logger.log(Level.FINE, strings.getLocalString("sse.writeevent.exception",
                                        "Can not write object as SSE (type = {0})",
                                        event.getClass().getName()), ex);
                            }
                            if (ec.isClosed()) {
                                unregister();
                            }
                        }
                    }
                };
View Full Code Here

        commandInvocation
                .outbound(new RestPayloadImpl.Outbound(false))
                .subject(getSubject())
                .managedJob()
                .parameters(params);
        final EventChannel ec = new EventChannel();
        AdminCommandListener listener = new AdminCommandListener() {
                    @Override
                    public void onAdminCommandEvent(String name, Object event) {
                        if (name == null || name.startsWith("client.")) {
                            return; //Prevent events from client to be send back to client
                        }
                        if (event == null) {
                            return;
                        }
                        if (ec.isClosed()) {
                            return;
                        }
                        OutboundEvent outEvent = new OutboundEvent.Builder()
                                                    .name(name)
                                                    .mediaType(MediaType.APPLICATION_JSON_TYPE)
                                                    .data(event.getClass(), event)
                                                    .build();
                        try {
                            ec.write(outEvent);
                        } catch (Exception ex) {
                            if (logger.isLoggable(Level.FINE)) {
                                logger.log(Level.FINE, strings.getLocalString("sse.writeevent.exception",
                                        "Can not write object as SSE (type = {0})",
                                        event.getClass().getName()), ex);
View Full Code Here

        commandInvocation
                .outbound(new RestPayloadImpl.Outbound(false))
                .subject(getSubject())
                .managedJob()
                .parameters(params);
        final EventChannel ec = new EventChannel();
        AdminCommandListener listener = new AdminCommandListener() {
                    @Override
                    public void onAdminCommandEvent(String name, Object event) {
                        if (name == null || name.startsWith("client.")) {
                            return; //Prevent events from client to be send back to client
                        }
                        if (event == null) {
                            return;
                        }
                        if (ec.isClosed()) {
                            return;
                        }
                        OutboundEvent outEvent = new OutboundEvent.Builder()
                                                    .name(name)
                                                    .mediaType(MediaType.APPLICATION_JSON_TYPE)
                                                    .data(event.getClass(), event)
                                                    .build();
                        try {
                            ec.write(outEvent);
                        } catch (Exception ex) {
                            if (logger.isLoggable(Level.FINE)) {
                                logger.log(Level.FINE, strings.getLocalString("sse.writeevent.exception",
                                        "Can not write object as SSE (type = {0})",
                                        event.getClass().getName()), ex);
View Full Code Here

TOP

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

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.