Sha256: 8e387ee30b9c510a003e3176c213c74c72281c4b4866fe0078c6f9245ba954a9

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 KB

Contents

require 'observer'

module Backport
  module Server
    # An extendable server class that provides basic start/stop functionality
    # and common callbacks.
    #
    class Base
      include Observable

      # Start the server.
      #
      def start
        return if started?
        starting
        @started = true
      end

      # Stop the server.
      #
      def stop
        return if stopped?
        stopping
        @started = false
        changed
        notify_observers self
      end

      def started?
        @started ||= false
      end

      def stopped?
        !started?
      end

      # A callback triggered when a Machine starts running or the server is
      # added to a running machine. Subclasses should override this method to
      # provide their own functionality.
      #
      # @return [void]
      def starting; end

      # A callback triggered when the server is stopping. Subclasses should
      # override this method to provide their own functionality.
      #
      # @return [void]
      def stopping; end

      # A callback triggered from the main loop of a running Machine.
      # Subclasses should override this method to provide their own
      # functionality.
      #
      # @return [void]
      def tick; end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
backport-1.1.2 lib/backport/server/base.rb
backport-1.1.1 lib/backport/server/base.rb
backport-1.1.0 lib/backport/server/base.rb