Class: Spider::Utils::SharedStore

Inherits:
Object
  • Object
show all
Defined in:
lib/spiderfw/utils/shared_store.rb

Overview

Abstract class for a shared store. A Shared Store is a Hash which may be accessed by different threads or processes. The various implementations will offer different persistency/availability.

Note: thread safety is guaranteed only for setting and getting store values. It doesn’t know about the data contained in the store: if you modify an object hold by the store, you should ensure thread safety yourself.

Direct Known Subclasses

FileSharedStore, MemorySharedStore

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ SharedStore

Returns a new instance of SharedStore.



23
24
25
# File 'lib/spiderfw/utils/shared_store.rb', line 23

def initialize(config={})
    @config = config
end

Class Method Details

.get(type = nil, config = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/spiderfw/utils/shared_store.rb', line 12

def self.get(type=nil, config=nil)
    type = Spider.conf.get('shared_store.type').to_sym unless type
    type = :memory unless type
    case type
    when :memory
        return MemorySharedStore.new(config)
    when :file
        return FileSharedStore.new(config)
    end
end

Instance Method Details

#[](key, &proc) ⇒ Object

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/spiderfw/utils/shared_store.rb', line 27

def [](key, &proc)
    raise NotImplementedError
end

#[]=(key) ⇒ Object

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/spiderfw/utils/shared_store.rb', line 31

def []=(key)
    raise NotImplementedError
end

#lock_all(&proc) ⇒ Object

Raises:

  • (NotImplementedError)


35
36
37
# File 'lib/spiderfw/utils/shared_store.rb', line 35

def lock_all(&proc)
    raise NotImplementedError
end