Class ClientEventService

java.lang.Object
org.apache.camel.builder.BuilderSupport
org.apache.camel.builder.RouteBuilder
org.openremote.manager.event.ClientEventService
All Implemented Interfaces:
org.apache.camel.builder.ModelRoutesBuilder, org.apache.camel.CamelContextAware, org.apache.camel.Ordered, org.apache.camel.RoutesBuilder, org.apache.camel.spi.HasCamelContext, org.apache.camel.spi.ResourceAware, org.openremote.model.ContainerService

public class ClientEventService extends org.apache.camel.builder.RouteBuilder implements org.openremote.model.ContainerService
Receives and publishes messages, handles the client/server event bus.

Messages always start with a message discriminator in all uppercase letters, followed by an optional JSON payload.

The following messages can be sent by a client:

SUBSCRIBE:{...}

The payload is a serialized representation of EventSubscription with an optional EventFilter. Clients can subscribe to receive SharedEvents when they are published on the server. Subscriptions are handled by Event.getEventType(java.lang.String).

UNSUBSCRIBE:{...}

The payload is a serialized representation of CancelEventSubscription. If a client does not want to wait for expiration of its subscriptions, it can cancel a subscription.

EVENT:{...}

The payload is a serialized representation of a subtype of SharedEvent. If the server does not recognize the event, it is silently ignored.

The following messages can be published/returned by the server:

UNAUTHORIZED:{...}

The payload is a serialized representation of UnauthorizedEventSubscription.

EVENT:{...}

The payload is a serialized representation of a subtype of SharedEvent.

EVENT:[...]

The payload is an array of SharedEvents.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final Collection<EventAuthorizer>
     
     
    protected final Set<org.openremote.model.util.Pair<org.openremote.model.event.shared.EventSubscription<? extends org.openremote.model.event.Event>,Consumer<? extends org.openremote.model.event.Event>>>
     
    protected ExecutorService
     
    protected Consumer<org.apache.camel.Exchange>
     
    protected GatewayService
     
     
    protected static final System.Logger
     
    protected org.openremote.container.message.MessageBrokerService
     
    static final int
     
    protected static final String
     
    protected final Map<String,io.undertow.websockets.core.WebSocketChannel>
     
    protected boolean
     
    protected org.openremote.container.timer.TimerService
     
    static final String
     
    protected final Map<String,Map<String,Consumer<? extends org.openremote.model.event.Event>>>
     

    Fields inherited from class org.apache.camel.builder.RouteBuilder

    log

    Fields inherited from interface org.openremote.model.ContainerService

    DEFAULT_PRIORITY, HIGH_PRIORITY, LOW_PRIORITY, MED_PRIORITY

    Fields inherited from interface org.apache.camel.Ordered

    HIGHEST, LOWEST
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    <T extends org.openremote.model.event.Event>
    void
    addSubscription(Class<T> eventClass, Consumer<T> consumer)
     
    <T extends org.openremote.model.event.Event>
    void
    addSubscription(Class<T> eventClass, org.openremote.model.event.shared.EventFilter<T> filter, Consumer<T> consumer)
     
    void
    addSubscription(org.openremote.model.event.shared.EventSubscription<? extends org.openremote.model.event.Event> eventSubscription, Consumer<? extends org.openremote.model.event.Event> consumer)
    Authorisation must be done before adding the subscription and is the responsibility of subscription creators.
    void
     
    boolean
    authorizeEventSubscription(String realm, org.openremote.container.security.AuthContext authContext, org.openremote.model.event.shared.EventSubscription<?> subscription)
    This handles basic authorisation checks for clients that want to subscribe to events in the system
    <T extends org.openremote.model.event.shared.SharedEvent>
    boolean
    authorizeEventWrite(String realm, org.openremote.container.security.AuthContext authContext, T event)
    This handles basic authorisation checks for clients that want to write an event to the system; this gets hit a lot so should be as performant as possible
    void
     
    void
     
    static String
    getClientId(org.apache.camel.Exchange exchange)
     
    int
     
    static String
    getSessionKey(org.apache.camel.Exchange exchange)
     
    void
    init(org.openremote.model.Container container)
     
    protected void
    onWebsocketSubscriptionTriggered(String sessionKey, org.openremote.model.event.shared.EventSubscription<?> subscription, org.openremote.model.event.shared.SharedEvent event)
     
    <T extends org.openremote.model.event.Event>
    void
    publishEvent(T event)
    Publish an event to interested subscribers
    void
    removeSubscription(Consumer<? extends org.openremote.model.event.Event> consumer)
     
    protected <T extends org.openremote.model.event.Event>
    void
     
    void
     
    void
    setGatewayInterceptor(Consumer<org.apache.camel.Exchange> consumer)
    This allows gateway connectors to intercept exchanges from gateway clients; it by-passes the standard processing including authorization so the interceptor provides its own authorization checks.
    void
    start(org.openremote.model.Container container)
     
    void
    stop(org.openremote.model.Container container)
     
     

    Methods inherited from class org.apache.camel.builder.RouteBuilder

    addLifecycleInterceptor, addRoutes, addRoutesToCamelContext, addTemplatedRoutesToCamelContext, bindToRegistry, bindToRegistry, checkInitialized, configuration, configureRest, configureRests, configureRoute, configureRouteConfiguration, configureRoutes, configureRouteTemplate, configureTemplatedRoute, customize, customize, dataFormat, errorHandler, errorHandler, expression, from, from, from, fromF, fromV, fromV, getBeans, getOrder, getResource, getRestCollection, getRestConfiguration, getRests, getRouteCollection, getRoutes, getRouteTemplateCollection, getTemplatedRouteCollection, initializeCamelContext, intercept, interceptFrom, interceptFrom, interceptSendToEndpoint, loadRoutesBuilder, loadRoutesBuilder, onCompletion, onException, onException, populateBeans, populateOrUpdateRoutes, populateRests, populateRoutes, populateRouteTemplates, populateTemplatedRoutes, populateTransformers, populateValidators, prepareModel, property, propertyInject, removeLifecycleInterceptor, rest, rest, restConfiguration, routeTemplate, setErrorHandlerFactory, setResource, setRestCollection, setRouteTemplateCollection, setTemplatedRouteCollection, templatedRoute, tokenizer, transformer, updateRoutesToCamelContext, validator

    Methods inherited from class org.apache.camel.builder.BuilderSupport

    body, bodyAs, constant, constant, constant, createErrorHandlerBuilder, csimple, csimple, datasonnet, datasonnet, datasonnet, deadLetterChannel, deadLetterChannel, defaultErrorHandler, endpoint, endpoint, exceptionMessage, exchangeProperty, expression, getCamelContext, getContext, getErrorHandlerFactory, hasErrorHandlerFactory, header, java, java, joor, joor, jq, jq, jsonpath, jsonpath, jtaTransactionErrorHandler, jtaTransactionErrorHandler, jtaTransactionErrorHandler, method, method, method, method, noErrorHandler, regexReplaceAll, regexReplaceAll, setCamelContext, simple, simple, simpleF, simpleF, springTransactionErrorHandler, springTransactionErrorHandler, springTransactionErrorHandler, systemProperty, systemProperty, variable, xpath, xpath, xpath, xpath

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • PRIORITY

      public static final int PRIORITY
      See Also:
    • WEBSOCKET_URI

      public static final String WEBSOCKET_URI
      See Also:
    • LOG

      protected static final System.Logger LOG
    • PUBLISH_QUEUE

      protected static final String PUBLISH_QUEUE
      See Also:
    • eventSubscriptionAuthorizers

      protected final Collection<EventSubscriptionAuthorizer> eventSubscriptionAuthorizers
    • eventAuthorizers

      protected final Collection<EventAuthorizer> eventAuthorizers
    • eventSubscriptions

      protected final Set<org.openremote.model.util.Pair<org.openremote.model.event.shared.EventSubscription<? extends org.openremote.model.event.Event>,Consumer<? extends org.openremote.model.event.Event>>> eventSubscriptions
    • sessionChannels

      protected final Map<String,io.undertow.websockets.core.WebSocketChannel> sessionChannels
    • websocketSessionSubscriptionConsumers

      protected final Map<String,Map<String,Consumer<? extends org.openremote.model.event.Event>>> websocketSessionSubscriptionConsumers
    • timerService

      protected org.openremote.container.timer.TimerService timerService
    • executorService

      protected ExecutorService executorService
    • messageBrokerService

      protected org.openremote.container.message.MessageBrokerService messageBrokerService
    • identityService

      protected ManagerIdentityService identityService
    • gatewayService

      protected GatewayService gatewayService
    • started

      protected boolean started
    • gatewayInterceptor

      protected Consumer<org.apache.camel.Exchange> gatewayInterceptor
  • Constructor Details

    • ClientEventService

      public ClientEventService()
  • Method Details

    • getSessionKey

      public static String getSessionKey(org.apache.camel.Exchange exchange)
    • getClientId

      public static String getClientId(org.apache.camel.Exchange exchange)
    • getPriority

      public int getPriority()
      Specified by:
      getPriority in interface org.openremote.model.ContainerService
    • init

      public void init(org.openremote.model.Container container) throws Exception
      Specified by:
      init in interface org.openremote.model.ContainerService
      Throws:
      Exception
    • configure

      public void configure() throws Exception
      Specified by:
      configure in class org.apache.camel.builder.RouteBuilder
      Throws:
      Exception
    • sendToSubscribers

      protected <T extends org.openremote.model.event.Event> void sendToSubscribers(T event)
    • addSubscription

      public void addSubscription(org.openremote.model.event.shared.EventSubscription<? extends org.openremote.model.event.Event> eventSubscription, Consumer<? extends org.openremote.model.event.Event> consumer) throws IllegalStateException
      Authorisation must be done before adding the subscription and is the responsibility of subscription creators.
      Throws:
      IllegalStateException
    • addSubscription

      public <T extends org.openremote.model.event.Event> void addSubscription(Class<T> eventClass, Consumer<T> consumer) throws IllegalStateException
      Throws:
      IllegalStateException
    • addSubscription

      public <T extends org.openremote.model.event.Event> void addSubscription(Class<T> eventClass, org.openremote.model.event.shared.EventFilter<T> filter, Consumer<T> consumer) throws IllegalStateException
      Throws:
      IllegalStateException
    • removeSubscription

      public void removeSubscription(Consumer<? extends org.openremote.model.event.Event> consumer)
    • start

      public void start(org.openremote.model.Container container)
      Specified by:
      start in interface org.openremote.model.ContainerService
    • stop

      public void stop(org.openremote.model.Container container)
      Specified by:
      stop in interface org.openremote.model.ContainerService
    • addSubscriptionAuthorizer

      public void addSubscriptionAuthorizer(EventSubscriptionAuthorizer authorizer)
    • addEventAuthorizer

      public void addEventAuthorizer(EventAuthorizer authorizer)
    • authorizeEventSubscription

      public boolean authorizeEventSubscription(String realm, org.openremote.container.security.AuthContext authContext, org.openremote.model.event.shared.EventSubscription<?> subscription)
      This handles basic authorisation checks for clients that want to subscribe to events in the system
    • authorizeEventWrite

      public <T extends org.openremote.model.event.shared.SharedEvent> boolean authorizeEventWrite(String realm, org.openremote.container.security.AuthContext authContext, T event)
      This handles basic authorisation checks for clients that want to write an event to the system; this gets hit a lot so should be as performant as possible
    • publishEvent

      public <T extends org.openremote.model.event.Event> void publishEvent(T event)
      Publish an event to interested subscribers
    • setGatewayInterceptor

      public void setGatewayInterceptor(Consumer<org.apache.camel.Exchange> consumer)
      This allows gateway connectors to intercept exchanges from gateway clients; it by-passes the standard processing including authorization so the interceptor provides its own authorization checks.
    • onWebsocketSubscriptionTriggered

      protected void onWebsocketSubscriptionTriggered(String sessionKey, org.openremote.model.event.shared.EventSubscription<?> subscription, org.openremote.model.event.shared.SharedEvent event)
    • sendToWebsocketSession

      public void sendToWebsocketSession(String sessionKey, Object data)
    • closeWebsocketSession

      public void closeWebsocketSession(String sessionKey)
    • toString

      public String toString()
      Overrides:
      toString in class org.apache.camel.builder.RouteBuilder