class 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

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

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
routes() click to toggle source

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' }
to_s() click to toggle source

Return a description of the handler.

# File lib/mongrel2/config/handler.rb, line 62
def to_s
        return "Handler `%s' %s <-> %s {%s}%s" % [
                self.send_ident,
                self.recv_spec,
                self.send_spec,
                self.protocol,
                self.raw_payload.nonzero? ? ' (raw)' : '',
        ]
end
validate() click to toggle source

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

before_validation() click to toggle source

Turn nil recv_ident values into the empty string before validating.

# File lib/mongrel2/config/handler.rb, line 78
def before_validation
        self.recv_ident ||= ''
end
validate_idents() click to toggle source

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 87
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_protocol() click to toggle source

Validate the handler's protocol.

# File lib/mongrel2/config/handler.rb, line 120
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_specs() click to toggle source

Validate the send_spec and recv_spec.

# File lib/mongrel2/config/handler.rb, line 104
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
validate_uniqueness() click to toggle source

Ensure that handlers are unique.

# File lib/mongrel2/config/handler.rb, line 131
def validate_uniqueness
        self.validates_unique( :send_ident, :send_spec, :recv_spec )
end

Private Instance Methods

check_0mq_spec( url ) click to toggle source

Returns true if url is a valid 0mq transport specification.

# File lib/mongrel2/config/handler.rb, line 141
def check_0mq_spec( url )
        return "must not be nil" unless url

        u = URI( url )
        return "invalid 0mq transport #{u.scheme}" unless VALID_SPEC_SCHEMES.include?( u.scheme )

        return nil
rescue URI::InvalidURIError
        return 'not a URI; should be something like "tcp://127.0.0.1:9998"'
end