Class: Synapse::ProcessManager::InMemoryProcessRepository

Inherits:
ProcessRepository show all
Defined in:
lib/synapse/process_manager/repository/in_memory.rb

Overview

Process repository that stores all processes in memory

This implementation is not thread-safe – use a lock manager for thread safety

Instance Method Summary collapse

Constructor Details

#initializeInMemoryProcessRepository

Returns a new instance of InMemoryProcessRepository.



7
8
9
10
# File 'lib/synapse/process_manager/repository/in_memory.rb', line 7

def initialize
  @managed_processes = Hash.new
  @lock = Mutex.new
end

Instance Method Details

#add(process) ⇒ undefined

Parameters:

Returns:

  • (undefined)


51
52
53
54
55
# File 'lib/synapse/process_manager/repository/in_memory.rb', line 51

def add(process)
  if process.active?
    commit process
  end
end

#commit(process) ⇒ undefined

Parameters:

Returns:

  • (undefined)


37
38
39
40
41
42
43
44
45
46
47
# File 'lib/synapse/process_manager/repository/in_memory.rb', line 37

def commit(process)
  @lock.synchronize do
    if process.active?
      @managed_processes.store process.id, process
    else
      @managed_processes.delete process.id
    end
  end

  process.correlations.commit
end

#countInteger

Returns The number of processes managed by this repository.

Returns:

  • (Integer)

    The number of processes managed by this repository



58
59
60
# File 'lib/synapse/process_manager/repository/in_memory.rb', line 58

def count
  @managed_processes.count
end

#find(type, correlation) ⇒ Set

Parameters:

Returns:

  • (Set)


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/synapse/process_manager/repository/in_memory.rb', line 15

def find(type, correlation)
  matching = Array.new

  @managed_processes.each_value do |process|
    if process.correlations.include? correlation
      matching.push process.id
    end
  end

  matching
end

#load(id) ⇒ Process

Returns nil if process could not be found

Parameters:

  • id (String)

Returns:

  • (Process)

    Returns nil if process could not be found



29
30
31
32
33
# File 'lib/synapse/process_manager/repository/in_memory.rb', line 29

def load(id)
  if @managed_processes.has_key? id
    @managed_processes.fetch id
  end
end