Class: GameMachine::Actor::Builder

Inherits:
Object
  • Object
show all
Defined in:
server/lib/game_machine/actor/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Object

Creates an actor builder instance. First argument is the actor class remaining arguments are optional and will be passed to post_init


13
14
15
16
17
18
19
20
21
22
# File 'server/lib/game_machine/actor/builder.rb', line 13

def initialize(*args)
  @klass = args.shift
  @name = @klass.name
  @create_hashring = false
  @hashring_size = 0
  factory = Actor::Factory.new(@klass,args)
  @props = JavaLib::Props.create(
    JavaLib::ActorFactory.java_class,factory,@klass.name)
  @actor_system = Akka.instance.actor_system
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


7
8
9
# File 'server/lib/game_machine/actor/builder.rb', line 7

def name
  @name
end

Instance Method Details

#distributed(hashring_size) ⇒ Object

Creates this router as a distributed router. It will create a group of actors distributed using consistent hashing. Suggest a hashring size of at least 40 up to 160.


76
77
78
79
80
# File 'server/lib/game_machine/actor/builder.rb', line 76

def distributed(hashring_size)
  @create_hashring = true
  @hashring_size = hashring_size
  self
end

#singletonObject

Special case. Must be created like so: Actor::Builder.new(SingletonActorClass).singleton NO OTHER OPTIONS. It will fail anyways if you do


27
28
29
30
31
32
33
34
# File 'server/lib/game_machine/actor/builder.rb', line 27

def singleton
  @actor_system.actor_of(
    JavaLib::ClusterSingletonManager.defaultProps(
      @props,@name,JavaLib::PoisonPill.get_instance,nil),'singleton')
  @actor_system.actor_of(
    JavaLib::ClusterSingletonProxy.defaultProps(
      "user/singleton/#{@name}", nil), @name);
end

#startObject

Start the actor(s). If the actor is distributed returns the entire Array of actor refs in the hash ring, otherwise a single actor ref


85
86
87
88
89
90
91
92
93
94
95
# File 'server/lib/game_machine/actor/builder.rb', line 85

def start
  GameMachine.logger.debug "Game actor #{@name} starting"
  if @create_hashring
    hashring = create_hashring(@hashring_size)
    hashring.nodes.to_a.each do |node_name|
      @actor_system.actor_of(@props, node_name)
    end
  else
    @actor_system.actor_of(@props, @name)
  end
end

#test_refObject


36
37
38
# File 'server/lib/game_machine/actor/builder.rb', line 36

def test_ref
  JavaLib::TestActorRef.create(@actor_system,@props,@name)
end

#with_dispatcher(name) ⇒ Object


56
57
58
59
# File 'server/lib/game_machine/actor/builder.rb', line 56

def with_dispatcher(name)
  @props = @props.with_dispatcher(name)
  self
end

#with_name(name) ⇒ Object

Sets the actor's name


51
52
53
54
# File 'server/lib/game_machine/actor/builder.rb', line 51

def with_name(name)
  @name = name
  self
end

#with_parent(parent) ⇒ Object

Sets the parent actor


43
44
45
46
# File 'server/lib/game_machine/actor/builder.rb', line 43

def with_parent(parent)
  @actor_system = parent
  self
end

#with_router(router_class, num_routers) ⇒ Object

Run the actor under a router


64
65
66
67
68
69
# File 'server/lib/game_machine/actor/builder.rb', line 64

def with_router(router_class,num_routers)
  @props = @props.with_router(
    router_class.new(num_routers)
  )
  self
end