higgs 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,65 @@
1
+ # = remote services
2
+ #
3
+ # Author:: $Author $
4
+ # Date:: $Date: 2007-11-09 01:09:51 +0900 (Fri, 09 Nov 2007) $
5
+ # Revision:: $Revision: 676 $
6
+ #
7
+ # == license
8
+ # :include:LICENSE
9
+ #
10
+
11
+ require 'drb'
12
+
13
+ module Higgs
14
+ # = remote services
15
+ class RemoteServices
16
+ # for ident(1)
17
+ CVS_ID = '$Id: services.rb 676 2007-11-08 16:09:51Z toki $'
18
+
19
+ # theses options are defined.
20
+ # [<tt>:remote_services_uri</tt>] URI for DRb remote call to provide services.
21
+ # [<tt>:storage</tt>] an instance of Higgs::Storage as remote service provider.
22
+ # [<tt>:transaction_manager</tt>] an instance of Higgs::TransactionManager
23
+ # as remote service provider.
24
+ #
25
+ # these methods are exported as remote services.
26
+ # * Higgs::Storage#alive?
27
+ # * Higgs::Storage#localhost_check
28
+ # * Higgs::Storage#rotate_journal_log
29
+ # * Higgs::TransactionManager#apply_journal_log
30
+ # * Higgs::TransactionManager#switch_to_write
31
+ #
32
+ def initialize(options)
33
+ @remote_services_uri = options[:remote_services_uri]
34
+ @storage = options[:storage]
35
+ @tman = options[:transaction_manager]
36
+
37
+ @service_map = {}
38
+ if (@storage) then
39
+ @service_map[:alive_service_v1] = @storage.method(:alive?)
40
+ @service_map[:localhost_check_service_v1] = @storage.method(:localhost_check)
41
+ @service_map[:jlog_rotate_service_v1] = @storage.method(:rotate_journal_log)
42
+ end
43
+ if (@tman) then
44
+ @service_map[:jlog_apply_service_v1] = @tman.method(:apply_journal_log)
45
+ @service_map[:switch_to_write_service_v1] = @tman.method(:switch_to_write)
46
+ end
47
+
48
+ @service_map.extend(DRb::DRbUndumped)
49
+ @service_map.freeze
50
+ @server = DRb::DRbServer.new(@remote_services_uri, @service_map) if @remote_services_uri
51
+ end
52
+
53
+ attr_reader :remote_services_uri
54
+
55
+ def shutdown
56
+ @server.stop_service if @remote_services_uri
57
+ nil
58
+ end
59
+ end
60
+ end
61
+
62
+ # Local Variables:
63
+ # mode: Ruby
64
+ # indent-tabs-mode: nil
65
+ # End:
data/lib/higgs/sman.rb ADDED
@@ -0,0 +1,98 @@
1
+ # = storage manager
2
+ #
3
+ # Author:: $Author: toki $
4
+ # Date:: $Date: 2007-11-05 00:06:41 +0900 (Mon, 05 Nov 2007) $
5
+ # Revision:: $Revision: 665 $
6
+ #
7
+ # == license
8
+ # :include:LICENSE
9
+ #
10
+
11
+ require 'forwardable'
12
+ require 'higgs/services'
13
+ require 'higgs/storage'
14
+ require 'higgs/tman'
15
+
16
+ module Higgs
17
+ # = storage manager
18
+ # the front end of these classes.
19
+ # * Higgs::Storage
20
+ # * Higgs::TransactionManager
21
+ # * Higgs::RemoteServices
22
+ #
23
+ # these methods are delegated to Higgs::Storage.
24
+ # * Higgs::Storage#name
25
+ # * Higgs::Storage#number_of_read_io
26
+ # * Higgs::Storage#data_hash_type
27
+ # * Higgs::Storage#jlog_sync
28
+ # * Higgs::Storage#jlog_hash_type
29
+ # * Higgs::Storage#jlog_rotate_size
30
+ # * Higgs::Storage#jlog_rotate_max
31
+ # * Higgs::Storage#shutdown?
32
+ # * Higgs::Storage#rotate_journal_log
33
+ #
34
+ # these methods are delegated to Higgs::TransactionManager.
35
+ # * Higgs::TransactionManager#read_only
36
+ # * Higgs::TransactionManager#transaction
37
+ # * Higgs::TransactionManager#apply_journal_log
38
+ # * Higgs::TransactionManager#switch_to_write
39
+ #
40
+ # these methods are delegated to Higgs::RemoteServices.
41
+ # * Higgs::RemoteServices#remote_services_uri
42
+ #
43
+ class StorageManager
44
+ # for ident(1)
45
+ CVS_ID = '$Id: sman.rb 665 2007-11-04 15:06:41Z toki $'
46
+
47
+ extend Forwardable
48
+
49
+ # <tt>name</tt> is a storage name and see Higgs::Storage.new for
50
+ # detail. see Higgs::Storage::InitOptions,
51
+ # Higgs::TransactionManager::InitOptions and
52
+ # Higgs::RemoteServices.new for <tt>options</tt>.
53
+ def initialize(name, options={})
54
+ @storage = Storage.new(name, options)
55
+ @tman = TransactionManager.new(@storage, options)
56
+ options = options.dup
57
+ options[:storage] = @storage
58
+ options[:transaction_manager] = @tman
59
+ @services = RemoteServices.new(options)
60
+ end
61
+
62
+ def_delegator :@storage, :name
63
+ def_delegator :@storage, :number_of_read_io
64
+ def_delegator :@storage, :data_hash_type
65
+ def_delegator :@storage, :jlog_sync
66
+ def_delegator :@storage, :jlog_hash_type
67
+ def_delegator :@storage, :jlog_rotate_size
68
+ def_delegator :@storage, :jlog_rotate_max
69
+ def_delegator :@storage, :shutdown?
70
+ def_delegator :@storage, :rotate_journal_log
71
+ def_delegator :@tman, :read_only
72
+ def_delegator :@tman, :transaction
73
+ def_delegator :@tman, :apply_journal_log
74
+ def_delegator :@tman, :switch_to_write
75
+ def_delegator :@services, :remote_services_uri
76
+
77
+ def shutdown
78
+ @storage.shutdown
79
+ @services.shutdown
80
+ nil
81
+ end
82
+
83
+ def self.open(*args)
84
+ sman = new(*args)
85
+ begin
86
+ r = yield(sman)
87
+ ensure
88
+ sman.shutdown
89
+ end
90
+ r
91
+ end
92
+ end
93
+ end
94
+
95
+ # Local Variables:
96
+ # mode: Ruby
97
+ # indent-tabs-mode: nil
98
+ # End: