The list of valid protocols
The list of 0mq transports Mongrel2
can use; “You need to use the ZeroMQ syntax for configuring them, but this means with one configuration format you can use handlers that are using UDP, TCP, Unix, or PGM transports.” Note that I'm assuming by 'udp' Zed means 'epgm', as I can't find any udp 0mq transport.
# File lib/mongrel2/config/handler.rb, line 46
def by_send_ident( ident )
return self.filter( :send_ident => ident )
end
Look up a Handler
by its send_ident, which should be a uuid
or similar String.
# File lib/mongrel2/config/handler.rb, line 45
dataset_module do
def by_send_ident( ident )
return self.filter( :send_ident => ident )
end
end
Validate the object prior to saving it.
# File lib/mongrel2/config/handler.rb, line 53
def validate
self.validate_idents
self.validate_specs
self.validate_protocol
self.validate_uniqueness
end
Turn nil recv_ident values into the empty string before validating.
# File lib/mongrel2/config/handler.rb, line 66
def before_validation
self.recv_ident ||= ''
end
Validate the send_ident and recv_ident – :FIXME: I'm not sure if this is actually necessary, but it seems like
the ident should at least be UUID-like like the server ident.
# File lib/mongrel2/config/handler.rb, line 75
def validate_idents
unless self.send_ident =~ /^\w[\w\-]+$/
errmsg = "[%p]: invalid sender identity (should be UUID-like)" % [ self.send_ident ]
self.log.error( 'send_ident: ' + errmsg )
self.errors.add( :send_ident, errmsg )
end
unless self.recv_ident == '' || self.send_ident =~ /^\w[\w\-]+$/
errmsg = "[%p]: invalid receiver identity (should be empty string or UUID-like)" %
[ self.recv_ident ]
self.log.error( 'send_ident: ' + errmsg )
self.errors.add( :send_ident, errmsg )
end
end
Validate the handler's protocol.
# File lib/mongrel2/config/handler.rb, line 108
def validate_protocol
return unless self.protocol # nil == default
unless VALID_PROTOCOLS.include?( self.protocol )
errmsg = "[%p]: invalid" % [ self.protocol ]
self.log.error( 'protocol: ' + errmsg )
self.errors.add( :protocol, errmsg )
end
end
Validate the send_spec and recv_spec.
# File lib/mongrel2/config/handler.rb, line 92
def validate_specs
if err = check_0mq_spec( self.send_spec )
errmsg = "[%p]: %s" % [ self.send_spec, err ]
self.log.error( 'send_spec: ' + errmsg )
self.errors.add( :recv_spec, errmsg )
end
if err = check_0mq_spec( self.recv_spec )
errmsg = "[%p]: %s" % [ self.recv_spec, err ]
self.log.error( 'recv_spec: ' + errmsg )
self.errors.add( :recv_spec, errmsg )
end
end
Ensure that handlers are unique.
# File lib/mongrel2/config/handler.rb, line 119
def validate_uniqueness
self.validates_unique( :send_ident, :send_spec, :recv_spec )
end