Handler

class
Superclass
Mongrel2::Config( :handler )

Mongrel2 Handler configuration class

Associations

↑ top

Constants

VALID_PROTOCOLS

The list of valid protocols

VALID_SPEC_SCHEMES

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.

Public Instance Methods

anchor
by_send_ident( ident )
# File lib/mongrel2/config/handler.rb, line 46
def by_send_ident( ident )
        return self.filter( :send_ident => ident )
end
anchor
by_send_ident(()

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
anchor
routes()

The routes that refer to this Handler

# File lib/mongrel2/config/handler.rb, line 25
one_to_many :routes, :key => :target_id, :conditions => { target_type: 'handler' }
anchor
validate()

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

Protected Instance Methods

anchor
before_validation()

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
anchor
validate_idents()

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
anchor
validate_protocol()

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
anchor
validate_specs()

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
anchor
validate_uniqueness()

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