Class: Isomorfeus::Transport::ServerSocketProcessor

Inherits:
Object
  • Object
show all
Includes:
ServerProcessor
Defined in:
lib/isomorfeus/transport/server_socket_processor.rb

Instance Method Summary collapse

Methods included from ServerProcessor

#process_request

Constructor Details

#initialize(user, session_id) ⇒ ServerSocketProcessor

Returns a new instance of ServerSocketProcessor.



6
7
8
9
10
# File 'lib/isomorfeus/transport/server_socket_processor.rb', line 6

def initialize(user, session_id)
  @user = user
  @session_id = session_id
  @atime = Time.now
end

Instance Method Details

#on_close(client) ⇒ Object



45
46
47
# File 'lib/isomorfeus/transport/server_socket_processor.rb', line 45

def on_close(client)
  # nothing for now
end

#on_message(client, data) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/isomorfeus/transport/server_socket_processor.rb', line 12

def on_message(client, data)
  if Isomorfeus.development?
    if Isomorfeus.server_requires_reload?
      write_lock = Isomorfeus.zeitwerk_lock.try_write_lock
      if write_lock
        Isomorfeus.zeitwerk.reload
        Isomorfeus.zeitwerk_lock.release_write_lock
      end
    end
    Isomorfeus.zeitwerk_lock.acquire_read_lock
  end
  request_hash = Oj.load(data, mode: :strict)
  Thread.current[:isomorfeus_user] = user
  unless request_hash.key?(:iso_ping)
    handler_instance_cache = {}
    response_agent_array = []
    Thread.current[:isomorfeus_pub_sub_client] = client
    process_request(request_hash, handler_instance_cache, response_agent_array)
    handler_instance_cache.each_value do |handler|
      handler.resolve if handler.resolving?
    end
    result = {}
    response_agent_array.each do |response_agent|
      result.deep_merge!(response_agent.result)
    end
    client.write Oj.dump(result, mode: :strict) unless result.empty?
  end
ensure
  Thread.current[:isomorfeus_user] = nil
  Thread.current[:isomorfeus_pub_sub_client] = nil
  Isomorfeus.zeitwerk_lock.release_read_lock if Isomorfeus.development?
end

#on_open(client) ⇒ Object



49
50
51
# File 'lib/isomorfeus/transport/server_socket_processor.rb', line 49

def on_open(client)
  # nothing for now
end

#on_shutdown(client) ⇒ Object



53
54
55
# File 'lib/isomorfeus/transport/server_socket_processor.rb', line 53

def on_shutdown(client)
  # nothing for now
end

#userObject



57
58
59
60
61
62
63
64
# File 'lib/isomorfeus/transport/server_socket_processor.rb', line 57

def user
  t = Time.now
  if @session_id && (t - @atime) > 600
    Isomorfeus.session_class&.touch(session_id: @session_id)
    @atime = t
  end
  @user
end