Class: EventMachine::Connection
- Inherits:
-
Object
- Object
- EventMachine::Connection
- Defined in:
- lib/lspace/eventmachine.rb
Class Method Summary collapse
-
.allocate ⇒ Object
Overridden allocate which sets up a new LSpace.
-
.allocate_without_lspace ⇒ Object
As EM uses a custom implementation of new, the only sane way to set up the LSpace in advance is to override allocate.
-
.in_lspace ⇒ Object
Ensure that instances of this connection are run in the current LSpace.
Instance Method Summary collapse
-
#setup_lspace ⇒ Object
Override this method to setup the LSpace in a manner which you require.
Class Method Details
.allocate ⇒ Object
Overridden allocate which sets up a new LSpace.
Each connection object is run in its own LSpace, which can be configured by implementing the #setup_lspace method.
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/lspace/eventmachine.rb', line 99 def self.allocate lspace = @lspace || LSpace.current allocate_without_lspace.instance_eval do extend EventMachine::LSpacePreserver # Create a new LSpace per connection so that connections don't # effect each other side-ways. LSpace.new({}, lspace).enter do setup_lspace @lspace = LSpace.current end self end end |
.allocate_without_lspace ⇒ Object
As EM uses a custom implementation of new, the only sane way to set up the LSpace in advance is to override allocate.
69 |
# File 'lib/lspace/eventmachine.rb', line 69 alias_method :allocate_without_lspace, :allocate |
.in_lspace ⇒ Object
Ensure that instances of this connection are run in the current LSpace
This is used by our version of EM.start_server to ensure that every instance of the server boots inside the same LSpace.
We don’t call it on client classes, so they will inherit the active LSpace when the outbound connection is created.
91 92 93 |
# File 'lib/lspace/eventmachine.rb', line 91 def self.in_lspace @lspace = LSpace.current end |
Instance Method Details
#setup_lspace ⇒ Object
Override this method to setup the LSpace in a manner which you require.
This method is called before initialize() and before post_init().
134 |
# File 'lib/lspace/eventmachine.rb', line 134 def setup_lspace; end |