Class: Orocos::Async::RemoteNameService

Inherits:
NameServiceBase show all
Extended by:
Utilrb::EventLoop::Forwardable
Defined in:
lib/orocos/async/name_service.rb

Overview

Base class for name services that are accessed remotely (e.g. over the network)

Constant Summary

Constants included from Namespace

Namespace::DELIMATOR

Instance Attribute Summary

Attributes inherited from NameServiceBase

#task_context_proxies

Attributes included from ObjectBase::Periodic::ClassMethods

#default_period

Attributes inherited from ObjectBase

#emitting, #event_loop, #options, #pending_adds

Instance Method Summary collapse

Methods inherited from NameServiceBase

#on_task_added, #proxy, #really_add_listener, #remove_listener

Methods included from Namespace

#basename, #map_to_namespace, #namespace, #namespace=, #same_namespace?, #split_name, split_name, validate_namespace_name, #verify_same_namespace

Methods included from ObjectBase::Periodic

#default_period, #period, #period=

Methods inherited from ObjectBase

#add_listener, define_event, define_events, #disable_emitting, #event, event_names, #event_names, #invalidate_delegator!, #listener?, #listeners, #number_of_listeners, #on_event, #proxy_event, #reachable!, #reachable?, #really_add_listener, #remove_all_listeners, #remove_listener, #remove_proxy_event, #valid_delegator?, valid_event?, #valid_event?, validate_event, #validate_event, #wait

Constructor Details

#initialize(name_service, options = Hash.new) ⇒ RemoteNameService

Returns a new instance of RemoteNameService



270
271
272
273
274
275
276
277
278
279
# File 'lib/orocos/async/name_service.rb', line 270

def initialize(name_service,options = Hash.new)
    options = Kernel.validate_options options,
        :reconnect => true,
        :known_errors => Array.new
    
    @reconnect = options.delete(:reconnect)
    options[:known_errors].concat([Orocos::ComError,Orocos::NotFound])
    super(name_service,options)
    @namespace = name_service.namespace
end

Instance Method Details

#get(name, options = Hash.new, &block) ⇒ Object



313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/orocos/async/name_service.rb', line 313

def get(name,options=Hash.new,&block)
    async_options,other_options = Kernel.filter_options options, 
        :sync_key => nil,:raise => nil,:event_loop => @event_loop,
        :period => nil,:wait => nil

    if block
        p = proc do |task,error|
            async_options[:use] = task
            atask = if !error
                        task.to_async(async_options)
                    end
            if block.arity == 2
                block.call atask,error
            elsif !error
                block.call atask
            end
        end 
        orig_get name,other_options,&p
    else
        task = orig_get name,other_options
        task.to_async(Hash[:use => task].merge(async_options))
    end
end

#nameObject



309
310
311
# File 'lib/orocos/async/name_service.rb', line 309

def name
    @delegator_obj.name
end

#reconnect?Boolean

True if this name service should automatically reconnect

Returns:

  • (Boolean)


283
# File 'lib/orocos/async/name_service.rb', line 283

def reconnect?; @reconnect end

#unreachable!(options = Hash.new) ⇒ Object



285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/orocos/async/name_service.rb', line 285

def unreachable!(options = Hash.new)
    @watchdog_timer.stop
    if !valid_delegator?
        raise "This should never happen. There must be always a valid delegator obj"
    end

    if reconnect? && options.has_key?(:error)
        obj = @delegator_obj
        obj.reset
        timer = @event_loop.async_every obj.method(:names),:period => 1.0,:sync_key => nil,:known_errors => [Orocos::NotFound,Orocos::ComError] do |names,error|
            if error
                obj.reset
            else
                reachable!(obj)
                @watchdog_timer.start
                timer.stop
            end
        end
        timer.doc = "NameService #{name} reconnect"
    else
    end
    super
end