Module: LanGrove::Handler::SocketBase

Includes:
LanGrove::Handler
Included in:
HttpServlet, Socket, SocketMultiplexer, WebSocket
Defined in:
lib/langrove/handler/socket_base.rb

Constant Summary

Constants included from LanGrove::Handler

Default

Instance Attribute Summary

Attributes included from LanGrove::Handler

#capsule, #config, #key, #logger, #pending_capsule, #protocol, #scheduler, #server, #type

Instance Method Summary collapse

Methods included from LanGrove::Handler

#assign, #connect, #disconnect, #error, #event_filter, #receive, #reload, #reload_handler, #start, #start_handler, #stop, #stop_handler, #transform, #unique

Instance Method Details

#handle_connectObject



9
10
11
12
13
14
15
16
17
# File 'lib/langrove/handler/socket_base.rb', line 9

def handle_connect

  @root.trigger( self, :handler, :connect )

  connect

  @root.trigger( self, :handler, :after_connect )

end

#handle_disconnectObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/langrove/handler/socket_base.rb', line 19

def handle_disconnect

  @root.trigger( self, :handler, :disconnect )

  disconnect
  
  server.disconnect( self )

  @root.trigger( self, :handler, :after_disconnect )

end

#handle_error(err) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/langrove/handler/socket_base.rb', line 31

def handle_error( err )

  @root.trigger( self, :handler, :error )

  error( err )

end

#handle_receive_data(data) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/langrove/handler/socket_base.rb', line 50

def handle_receive_data( data )

  decoded_data = @protocol.decode( data )
  
  if @pending_capsule.nil?
    
    #
    # Creates duplicate... 
    # 
    # - To avoid potential concurrencies
    #
    @pending_capsule = decoded_data
    
    #
    # Fire the first_message event into whatever 
    # assigned Behaviours may be awaiting
    #
    
    
    # 
    # The eventing subsystem will need to be extended to support 
    # onsuccess and onfailed callbacks. 
    # 
    # Currently, this call may go to a Persistor.fetch() that 
    # collects data from a DB,file,thing. 
    # 
    # If that call takes long, it holds up the entire EventMachine 
    # reactor.
    # 
    # Ideally:
    # 
    # - In the case of a TCP based system, with a ACK based protocol, 
    #   this call should be deferred into a Proc with callbacks to
    #   on_success and on_failed
    #
    #
    #   ...to be continued.
    # 
    #
    #
    # 
    @root.trigger( self, :handler, :first_message )
    
  end
  
  #
  # These trigger calls fail in test,?
  # but work in RL 
  # 
  # Dunno why...
  #
  @root.trigger( self, :handler, :receive )
  
  #
  # Call user overridabe receive
  #
  receive( decoded_data )
  
  @root.trigger( self, :handler, :after_receive )
  
  # 
  # ?Multi-message protocol? 
  # 
  # @protocol.accumulate( multi_message_part, self )
  #
  #   ---- With protocol responding directly to source
  # 
  #   ---- With protocol then calling receive_decoded()
  #        via the self being passed in. 
  #    
  
end

#unbindObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/langrove/handler/socket_base.rb', line 39

def unbind

  #
  # eventmachine calls this
  #

  stop_handler   # one of these may fall away
  handle_disconnect

end