module Isomorfeus module Transport class ServerSocketProcessor OJ_OBJ_RE = /"(\^c|\^o|\^u)":/ include Isomorfeus::Transport::ServerProcessor def initialize(user, session_id) @user = user @session_id = session_id @atime = Time.now end 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 Isomorfeus.init_store Isomorfeus.store.clear! if user.respond_to?(:reload) cu = Thread.current[:isomorfeus_user] Thread.current[:isomorfeus_user] = LocalSystem.new begin user.reload ensure Thread.current[:isomorfeus_user] = cu end end Thread.current[:isomorfeus_user] = user request_hash = Oj.load(data, mode: :strict) 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 def on_close(client) # nothing for now end def on_open(client) # nothing for now end def on_shutdown(client) # nothing for now end def user t = Time.now if @session_id && (t - @atime) > 600 Isomorfeus.session_class&.touch(session_id: @session_id) @atime = t end @user end end end end