Class AbstractService

    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractService​(BayeuxServer bayeux, java.lang.String name)
      Instantiates a CometD service with the given name.
      AbstractService​(BayeuxServer bayeux, java.lang.String name, int maxThreads)
      Instantiate a CometD service with the given name and max number of pooled threads.
    • Constructor Detail

      • AbstractService

        public AbstractService​(BayeuxServer bayeux,
                               java.lang.String name)

        Instantiates a CometD service with the given name.

        Parameters:
        bayeux - The BayeuxServer instance.
        name - The name of the service (used as client ID prefix).
      • AbstractService

        public AbstractService​(BayeuxServer bayeux,
                               java.lang.String name,
                               int maxThreads)

        Instantiate a CometD service with the given name and max number of pooled threads.

        Parameters:
        bayeux - The BayeuxServer instance.
        name - The name of the service (used as client ID prefix).
        maxThreads - The max size of a ThreadPool to create to handle messages.
    • Method Detail

      • getName

        public java.lang.String getName()
      • setThreadPool

        public void setThreadPool​(org.eclipse.jetty.util.thread.ThreadPool pool)

        Sets the thread pool associated to this CometD service.

        If the ThreadPool is a LifeCycle instance, and it is not already started, then it will started.

        Parameters:
        pool - The ThreadPool
      • isSeeOwnPublishes

        public boolean isSeeOwnPublishes()
        Returns:
        whether this CometD service receives messages published by itself on channels it is subscribed to (defaults to false).
        See Also:
        setSeeOwnPublishes(boolean)
      • setSeeOwnPublishes

        public void setSeeOwnPublishes​(boolean seeOwnPublishes)
        Parameters:
        seeOwnPublishes - whether this CometD service receives messages published by itself on channels it is subscribed to (defaults to false).
        See Also:
        isSeeOwnPublishes()
      • addService

        protected void addService​(java.lang.String channelName,
                                  java.lang.String methodName)

        Maps the method of a subclass with the given name to a ServerChannel.MessageListener on the given channel, so that the method is invoked for each message received on the channel.

        The channel name may be a wildcard channel name.

        The method must have a unique name and the following signature:

        • myMethod(ServerSession from, ServerMessage message)

        Typically a service will be used to a channel in the /service/** space which is not a broadcast channel.

        Any object returned by a mapped method is delivered back to the client that sent the message and not broadcast. If the method returns void or null, then no response is sent.

        A mapped method may also call send(org.cometd.bayeux.server.ServerSession, String, Object) to deliver message(s) to specific clients and/or channels.

        A mapped method may also publish to different channels via ServerChannel.publish(Session, ServerMessage.Mutable, Promise).

        Parameters:
        channelName - The channel to listen to
        methodName - The name of the method on this subclass to call when messages are received on the channel
        See Also:
        removeService(String, String)
      • removeService

        protected void removeService​(java.lang.String channelName,
                                     java.lang.String methodName)

        Unmaps the method with the given name that has been mapped to the given channel.

        Parameters:
        channelName - The channel name
        methodName - The name of the method to unmap
        See Also:
        addService(String, String), removeService(String)
      • send

        protected void send​(ServerSession toClient,
                            java.lang.String onChannel,
                            java.lang.Object data)

        Sends data to an individual remote client.

        The data passed is sent to the client as the "data" member of a message with the given channel. The message is not published on the channel and is thus not broadcast to all channel subscribers, but instead delivered directly to the target client.

        Typically this method is only required if a service method sends response(s) to clients other than the sender, or on different channels. If the response is to be sent to the sender on the same channel, then the data can simply be the return value of the method.

        Parameters:
        toClient - The target client
        onChannel - The channel of the message
        data - The data of the message
      • exception

        protected void exception​(java.lang.String method,
                                 ServerSession session,
                                 LocalSession local,
                                 ServerMessage message,
                                 java.lang.Throwable x)

        Handles exceptions during the invocation of a mapped method.

        This method is called when a mapped method throws and exception while handling a message.

        Parameters:
        method - the name of the method invoked that threw an exception
        session - the remote session that sent the message
        local - the local session associated to this service
        message - the message sent by the remote session
        x - the exception thrown