Class BayeuxServerImpl

  • All Implemented Interfaces:
    Bayeux, BayeuxServer, org.eclipse.jetty.util.component.Container, org.eclipse.jetty.util.component.Destroyable, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.util.component.Dumpable.DumpableContainer, org.eclipse.jetty.util.component.LifeCycle

    @ManagedObject("The CometD server")
    public class BayeuxServerImpl
    extends org.eclipse.jetty.util.component.ContainerLifeCycle
    implements BayeuxServer, org.eclipse.jetty.util.component.Dumpable
    • Field Detail

      • ALLOWED_TRANSPORTS_OPTION

        public static final java.lang.String ALLOWED_TRANSPORTS_OPTION
        See Also:
        Constant Field Values
      • SWEEP_PERIOD_OPTION

        public static final java.lang.String SWEEP_PERIOD_OPTION
        See Also:
        Constant Field Values
      • SWEEP_THREADS_OPTION

        public static final java.lang.String SWEEP_THREADS_OPTION
        See Also:
        Constant Field Values
      • TRANSPORTS_OPTION

        public static final java.lang.String TRANSPORTS_OPTION
        See Also:
        Constant Field Values
      • VALIDATE_MESSAGE_FIELDS_OPTION

        public static final java.lang.String VALIDATE_MESSAGE_FIELDS_OPTION
        See Also:
        Constant Field Values
      • BROADCAST_TO_PUBLISHER_OPTION

        public static final java.lang.String BROADCAST_TO_PUBLISHER_OPTION
        See Also:
        Constant Field Values
      • SCHEDULER_THREADS

        public static final java.lang.String SCHEDULER_THREADS
        See Also:
        Constant Field Values
      • EXECUTOR_MAX_THREADS

        public static final java.lang.String EXECUTOR_MAX_THREADS
        See Also:
        Constant Field Values
    • Constructor Detail

      • BayeuxServerImpl

        public BayeuxServerImpl()
    • Method Detail

      • getName

        public java.lang.String getName()
      • doStart

        protected void doStart()
                        throws java.lang.Exception
        Overrides:
        doStart in class org.eclipse.jetty.util.component.ContainerLifeCycle
        Throws:
        java.lang.Exception
      • doStop

        protected void doStop()
                       throws java.lang.Exception
        Overrides:
        doStop in class org.eclipse.jetty.util.component.ContainerLifeCycle
        Throws:
        java.lang.Exception
      • initializeMetaChannels

        protected void initializeMetaChannels()
      • initializeJSONContext

        protected void initializeJSONContext()
                                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • initializeServerTransports

        protected void initializeServerTransports()
      • setExecutor

        public void setExecutor​(java.util.concurrent.Executor executor)
      • getExecutor

        public java.util.concurrent.Executor getExecutor()
      • execute

        public void execute​(java.lang.Runnable job)
      • setScheduler

        public void setScheduler​(org.eclipse.jetty.util.thread.Scheduler scheduler)
      • getScheduler

        public org.eclipse.jetty.util.thread.Scheduler getScheduler()
      • schedule

        public org.eclipse.jetty.util.thread.Scheduler.Task schedule​(java.lang.Runnable task,
                                                                     long delay)

        Entry point to schedule tasks in CometD.

        Subclasses may override and run the task in a Executor, rather than in the scheduler thread.

        Parameters:
        task - the task to schedule
        delay - the delay, in milliseconds, to run the task
        Returns:
        the task promise
      • newChannelId

        public ChannelId newChannelId​(java.lang.String id)
      • getOptions

        public java.util.Map<java.lang.String,​java.lang.Object> getOptions()
      • getOption

        @ManagedOperation(value="The value of the given configuration option",
                          impact="INFO")
        public java.lang.Object getOption​(@Name("optionName")
                                          java.lang.String qualifiedName)
        Specified by:
        getOption in interface Bayeux
        Parameters:
        qualifiedName - the configuration option name
        Returns:
        the configuration option with the given qualifiedName
        See Also:
        Bayeux.setOption(String, Object), Bayeux.getOptionNames()
      • getOption

        protected long getOption​(java.lang.String name,
                                 long dft)
      • getOption

        protected boolean getOption​(java.lang.String name,
                                    boolean dft)
      • setOption

        public void setOption​(java.lang.String qualifiedName,
                              java.lang.Object value)
        Specified by:
        setOption in interface Bayeux
        Parameters:
        qualifiedName - the configuration option name
        value - the configuration option value
        See Also:
        Bayeux.getOption(String)
      • setOptions

        public void setOptions​(java.util.Map<java.lang.String,​java.lang.Object> options)
      • randomLong

        public long randomLong()
      • createChannelIfAbsent

        public MarkedReference<ServerChannel> createChannelIfAbsent​(java.lang.String channelName,
                                                                    ConfigurableServerChannel.Initializer... initializers)
        Description copied from interface: BayeuxServer

        Creates a ServerChannel and initializes it atomically if the channel does not exist, or returns it if it already exists.

        This method can be used instead of adding a BayeuxServer.ChannelListener to atomically initialize a channel. The initializers will be called before any other thread can access the new channel instance.

        This method should be used when a channel needs to be initialized (e.g. by adding listeners) before any publish or subscribes can occur on the channel, or before any other thread may concurrently create the same channel.

        Specified by:
        createChannelIfAbsent in interface BayeuxServer
        Parameters:
        channelName - the channel name
        initializers - the initializers invoked to configure the channel
        Returns:
        a MarkedReference whose reference is the channel, and the mark signals whether the channel has been created because it did not exist before.
      • removeSession

        public boolean removeSession​(ServerSession session)
        Description copied from interface: BayeuxServer

        Removes the given session from this BayeuxServer.

        This method triggers the invocation of all listeners that would be called if the session was disconnected or if the session timed out.

        Specified by:
        removeSession in interface BayeuxServer
        Parameters:
        session - the session to remove
        Returns:
        true if the session was known to this BayeuxServer and was removed
      • removeServerSession

        public boolean removeServerSession​(ServerSession session,
                                           boolean timeout)
        Parameters:
        session - the session to remove
        timeout - whether the session has been removed due to a timeout
        Returns:
        true if the session was removed and was connected
      • newLocalSession

        public LocalSession newLocalSession​(java.lang.String idHint)
        Description copied from interface: BayeuxServer

        Creates a new LocalSession.

        A LocalSession is a server-side ClientSession that allows server-side code to have special clients (resident within the same JVM) that can be used to publish and subscribe like a client-side session would do.

        Specified by:
        newLocalSession in interface BayeuxServer
        Parameters:
        idHint - a hint to be included in the unique clientId of the session.
        Returns:
        a new LocalSession
      • getChannels

        public java.util.List<ServerChannel> getChannels()
        Specified by:
        getChannels in interface BayeuxServer
        Returns:
        the list of channels known to this BayeuxServer object
      • removeServerChannel

        protected boolean removeServerChannel​(ServerChannelImpl channel)
      • getTransport

        public ServerTransport getTransport​(java.lang.String transport)
        Specified by:
        getTransport in interface Bayeux
        Parameters:
        transport - the transport name
        Returns:
        the transport with the given name or null if no such transport exist
      • setTransports

        public void setTransports​(ServerTransport... transports)
      • setTransports

        public void setTransports​(java.util.List<ServerTransport> transports)
      • findHttpTransport

        protected AbstractHttpTransport findHttpTransport​(jakarta.servlet.http.HttpServletRequest request)
      • getAllowedTransports

        @ManagedAttribute(value="The transports allowed by this CometD server",
                          readonly=true)
        public java.util.List<java.lang.String> getAllowedTransports()
        Specified by:
        getAllowedTransports in interface Bayeux
        Returns:
        the ordered list of transport names that will be used in the negotiation of transports with the other peer.
        See Also:
        Bayeux.getKnownTransportNames()
      • setAllowedTransports

        public void setAllowedTransports​(java.lang.String... allowed)
      • setAllowedTransports

        public void setAllowedTransports​(java.util.List<java.lang.String> allowed)
      • isBroadcastToPublisher

        @ManagedAttribute(value="Whether this CometD server broadcast messages to the publisher",
                          readonly=true)
        public boolean isBroadcastToPublisher()
      • sweep

        @ManagedOperation(value="Sweeps channels and sessions of this CometD server",
                          impact="ACTION")
        public void sweep()
      • isDetailedDump

        @ManagedAttribute("Reports additional details in the dump() operation")
        public boolean isDetailedDump()
      • setDetailedDump

        public void setDetailedDump​(boolean detailedDump)
      • getSweepPeriod

        @ManagedAttribute("The period, in milliseconds, of the sweeping activity performed by the server")
        public long getSweepPeriod()
      • setSweepPeriod

        public void setSweepPeriod​(long sweepPeriod)
      • getSweepThreads

        @ManagedAttribute("The maximum number of threads that can be used by the sweeping activity performed by the server")
        public int getSweepThreads()
      • setSweepThreads

        public void setSweepThreads​(int sweepThreads)
      • dump

        public void dump​(java.lang.Appendable out,
                         java.lang.String indent)
                  throws java.io.IOException
        Specified by:
        dump in interface org.eclipse.jetty.util.component.Dumpable
        Overrides:
        dump in class org.eclipse.jetty.util.component.ContainerLifeCycle
        Throws:
        java.io.IOException
      • getLastSweepInfo

        public java.util.Map<java.lang.String,​java.lang.Object> getLastSweepInfo()
      • getLongestSweepInfo

        public java.util.Map<java.lang.String,​java.lang.Object> getLongestSweepInfo()