class Porcupine

Constants

DEFAULT_GROUP
DEFAULT_TIMEOUT

Attributes

block[R]

Public Class Methods

new(name_or_setter, group=DEFAULT_GROUP, timeout=DEFAULT_TIMEOUT, &block) click to toggle source
Calls superclass method
# File lib/porcupine/porcupine.rb, line 12
def initialize(name_or_setter, group=DEFAULT_GROUP, timeout=DEFAULT_TIMEOUT, &block)
  @block = block

  setter = name_or_setter if name_or_setter.is_a?(com.netflix.hystrix.HystrixCommand::Setter)
  setter ||= Setter.withGroupKey(HystrixCommandGroupKey::Factory.asKey(group))
                   .andCommandKey(HystrixCommandKey::Factory.asKey(name_or_setter))
                   .andCommandPropertiesDefaults(HystrixCommandProperties::Setter().withExecutionIsolationThreadTimeoutInMilliseconds(timeout))

  super(setter)
end

Public Instance Methods

execute() click to toggle source

Only catch Java exceptions since we already handle most exceptions in Observable#get

# File lib/porcupine/porcupine.rb, line 24
def execute
  queue.get
rescue Java::JavaLang::Throwable => e
  raise decomposeException(e)
end
getFallback() click to toggle source
# File lib/porcupine/porcupine.rb, line 54
def getFallback
  return getFailedExecutionException.getException if isFailedExecution
  return RejectedError.new                        if isResponseRejected
  return ShortCircuitError.new                    if isResponseShortCircuited
  return TimeoutError.new                         if isResponseTimedOut
  RuntimeError.new
end
observe() click to toggle source
Calls superclass method
# File lib/porcupine/porcupine.rb, line 30
def observe
  Observable.new(super)
end
queue() click to toggle source
Calls superclass method
# File lib/porcupine/porcupine.rb, line 46
def queue
  Future.new(super)
end
run() click to toggle source
# File lib/porcupine/porcupine.rb, line 50
def run
  block.call
end
toObservable(*args) click to toggle source

Only wrap the outer-most call; otherwise Java gets angry because the class of the returned object won’t match the signature when the calls recurse

Calls superclass method
# File lib/porcupine/porcupine.rb, line 36
def toObservable(*args)
  result = super

  unless caller.first.match(/toObservable/) || caller.first.match(/observe/)
    result = Observable.new(result)
  end

  result
end