<commit_before>#
# TODO: description
# TODO: describe that returned task is fully autonomyc. It's not needed
# TODO: to call it by consume() method.
# TODO: Events
#
module Server
  import Config
  import Event
  import Connection

  export ServerTask

  export create

  using Debug
  #
  # Contains observer and the task for parallel work of this server's
  # socket and other synchronous objects.
  #
  type ServerTask
    #
    # The Task, which is used for parallel work
    #
    task::Task
    #
    # Observer instance, which is used for event based communication
    #
    observer::Event.Observer
  end

  # TODO: update comments
  # It creates separate task for remote terminal. It waits a connection
  # from remote terminal on specified port by TCP/IP protocol. After 
  # terminal is connected, we wait for commands. After stop command
  # accures, we returns to the waiting loop. It Returns Task type 
  # instance, so we may parallel terminal connection and communication 
  # and other tasks like organisms scripts run.
  # @return {ServerTask}
  #
  @debug function create()
  @bp
    #
    # This Observer will be used for event based communication between
    # this server and it's listeners (like Manager mosule)
    #
    observer = Event.Observer(Dict{ASCIIString, Array{Function}}())
    #
    # This task is used for parallel work between this server's socket
    # and other synchronous objects like Organism code or other sockets.
    #
    task = begin
      # TODO: port should may be different on different instances on
      # TODO: the same machine (with same IP address)
      server = listen(Config.connection["startPort"])
      #
      # In this loop we are waiting for terminal connection.
      # We have to wait all the time.
      #
      while true
        socket = accept(server)
        #
        # In this loop we are reading command from the socket
        #
        while isopen(socket)
          try
            cmd = deserialize(socket)
            # TODO: remove this line
            println(cmd)
            #
            # This is how we drops the connection to terminal
            # TODO: stop command should be get from global config<commit_msg>* beta version of RPC like mechanism<commit_after>#
# TODO: description
# TODO: describe that returned task is fully autonomyc. It's not needed
# TODO: to call it by consume() method.
# TODO: Events
#
module Server
  import Config
  import Event
  import Connection

  export ServerTask

  export create

  using Debug
  #
  # Contains observer and the task for parallel work of this server's
  # socket and other synchronous objects.
  #
  type ServerTask
    #
    # The Task, which is used for parallel work
    #
    task::Task
    #
    # Observer instance, which is used for event based communication
    #
    observer::Event.Observer
  end

  # TODO: update comments
  # It creates separate task for remote terminal. It waits a connection
  # from remote terminal on specified port by TCP/IP protocol. After 
  # terminal is connected, we wait for commands. After stop command
  # accures, we returns to the waiting loop. It Returns Task type 
  # instance, so we may parallel terminal connection and communication 
  # and other tasks like organisms scripts run.
  # @return {ServerTask}
  #
  function create()
    #
    # This Observer will be used for event based communication between
    # this server and it's listeners (like Manager mosule)
    #
    observer = Event.Observer(Dict{ASCIIString, Array{Function}}())
    #
    # This task is used for parallel work between this server's socket
    # and other synchronous objects like Organism code or other sockets.
    #
    task = @async begin
      # TODO: port should may be different on different instances on
      # TODO: the same machine (with same IP address)
      server = listen(Config.connection["startPort"])
      #
      # In this loop we are waiting for terminal connection.
      # We have to wait all the time.
      #
      while true
        socket = accept(server)
        #
        # In this loop we are reading command from the socket
        #
        while isopen(socket)
          try
            cmd = deserialize(socket)
            # TODO: remove this line
            println(cmd)
            #
            # This is how we drops the connection to terminal
            # TODO: stop command should be get from global config
{'fraction_non_alphanumeric': 0.05747906766236705, 'fraction_numerical': 0.0, 'mean_word_length': 2.536, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1235926', 'n_tokens_mistral': 1126, 'n_tokens_neox': 1085, 'n_words': 532}