Class: ActiveRubinstein::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/active_rubinstein/base.rb

Overview

The serverpool is initialized here. The actual query methods are in these classes:

  • ActiveRubinstein::JenaQuery

  • ActiveRubinstein::LuceneSearcher

  • ActiveRubinstein::JosekiQuery

The SPARQL is created by ActiveRubinstein::SparqlFormulator

Direct Known Subclasses

JenaQuery, JosekiQuery, LuceneSearcher

Constant Summary collapse

@@language =

the default language for xml:lang matches

'fi'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

creates the server pool and starts the DRb client



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/active_rubinstein/base.rb', line 77

def initialize
  self.shuffle #unless defined? $serverPool
  self.roll

  unless $serverPool.any? then
    raise EmptyServerPoolError, "No servers in the pool"

  else # pick a server from the pool
    RUBIC_DATASTORES.to_a.each do |adapter|
      begin
        # instantiate the server for the class
        case adapter
        when :jena
          ActiveRubinstein::JenaQuery.new

        when :joseki
          ActiveRubinstein::JosekiQuery.new

        when :lucene
          ActiveRubinstein::LuceneSearcher.new

        when :geolucene
          ActiveRubinstein::LuceneSearcher.new( :geolucene )

        else
          raise AdapterNotFoundError, adapter
        end
      rescue
        raise ConnectionNotEstablishedError, $!
      end
    end
  end
end

Class Method Details

.set_language(lang) ⇒ Object

propagates the xml:lang preference to all submodules



183
184
185
186
# File 'lib/active_rubinstein/base.rb', line 183

def set_language( lang )
  @@language = lang
  ActiveRubinstein::JenaQuery.language = lang
end

Instance Method Details

#hello(server = nil) ⇒ Object

gets a greeting message from one or all of the servers in the pool

parameters:

  • 1 server (Symbol) – by default query all servers in the server pool



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/active_rubinstein/base.rb', line 208

def hello( server=nil )
  begin
    if server.nil? then # try all
      $serverPool.each_pair do |store, url|
        @@log.debug "Store: #{store.inspect}, url: #{url.inspect}"

        server = url.first
        @@log.rubinstein server.hello
      end
    else
      return server.hello
    end
  rescue
    @@log.error $!
  end
end

#rollObject

starts the DRb client



115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/active_rubinstein/base.rb', line 115

def roll

# # # # # # # # # # # # # # # # # # # # # # # # # # # # #

  # the daemon also includes this class, so do not attemp to start
  # the DRb client then.
  if @@in_daemon_mode then
    # TODO: check first if any of the servers are online and continue
    # pinging for..ever?
    @@log.rubinstein " * starting the DRb client"
    DRb.start_service
  end
end

#shuffleObject

initializes the server pool



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/active_rubinstein/base.rb', line 134

def shuffle

################ ############################## ###########   

            ####### #####         ##  #  ######### #### # ####   

  unless RUBIC_DATASTORES.any? then
    raise AdapterNotSpecifiedError, "No adapters specified"

  else
    $serverPool = {} unless defined? $serverPool

    RUBIC_DATASTORES.to_a.each do |adapter|
      begin
        case adapter
        when :jena
          server = JenaEndpoint.new
          if server.ping
            $serverPool.update :jena => [ server ]
            @@log.info " => added #{server.inspect} to pool"
          end

        when :joseki
          server = JosekiEndpoint.new
          if server.ping
            $serverPool.update :joseki => [ server ]
            @@log.info " => added #{server.inspect} to pool"
          end

        when :geolucene
          server = GeoLuceneEndpoint.new
          if server.ping
            $serverPool.update :geolucene => [ server ]
            @@log.info " => added #{server.inspect} to pool"
          end
        end
      rescue
        raise ConnectionFailedError, $!.message
      end
    end
  end
end