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

While the storage of processes are thread-safe, the processes themselves may not be. Use a lock manager if the processes are not thread-safe.

Instance Method Summary collapse

Constructor Details

#initializeInMemoryProcessRepository

Returns a new instance of InMemoryProcessRepository.



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

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

Instance Method Details

#add(process) ⇒ undefined

Parameters:

Returns:

  • (undefined)


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

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

#commit(process) ⇒ undefined

Parameters:

Returns:

  • (undefined)


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

def commit(process)
  @mutex.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



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

def count
  @managed_processes.count
end

#find(type, correlation) ⇒ Set<String>

Parameters:

Returns:

  • (Set<String>)


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

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



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

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