Sha256: f9e0c1bc73c39ca76e8cf4ba82669cca5a64949fda64fdcf38bcb5a694e574ce

Contents?: true

Size: 1.11 KB

Versions: 13

Compression:

Stored size: 1.11 KB

Contents

module Einhorn::Event
  class Connection < AbstractTextDescriptor
    include Persistent

    def parse_record
      split = @read_buffer.split("\n", 2)
      if split.length > 1
        split
      else
        nil
      end
    end

    def consume_record(command)
      Einhorn::Command::Interface.process_command(self, command)
    end

    def to_state
      state = {:class => self.class.to_s, :socket => @socket.fileno}
      # Don't include by default because it's not that pretty
      state[:read_buffer] = @read_buffer if @read_buffer.length > 0
      state[:write_buffer] = @write_buffer if @write_buffer.length > 0
      state
    end

    def self.from_state(state)
      fd = state[:socket]
      socket = Socket.for_fd(fd)
      conn = self.open(socket)
      conn.read_buffer = state[:read_buffer] if state[:read_buffer]
      conn.write_buffer = state[:write_buffer] if state[:write_buffer]
      conn
    end

    def register!
      log_info("client connected")
      super
    end

    def deregister!
      log_info("client disconnected") if Einhorn::TransientState.whatami == :master
      super
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
einhorn-0.4.9 lib/einhorn/event/connection.rb
einhorn-0.4.8 lib/einhorn/event/connection.rb
einhorn-0.4.7 lib/einhorn/event/connection.rb
einhorn-0.4.6 lib/einhorn/event/connection.rb
einhorn-0.4.5 lib/einhorn/event/connection.rb
einhorn-0.4.4 lib/einhorn/event/connection.rb
einhorn-0.4.3 lib/einhorn/event/connection.rb
einhorn-0.4.2 lib/einhorn/event/connection.rb
einhorn-0.4.1 lib/einhorn/event/connection.rb
einhorn-0.4.0 lib/einhorn/event/connection.rb
einhorn-0.3.2 lib/einhorn/event/connection.rb
einhorn-0.3.1 lib/einhorn/event/connection.rb
einhorn-0.3.0 lib/einhorn/event/connection.rb