Class: QRPC::Locator

Inherits:
Object
  • Object
show all
Defined in:
lib/qrpc/locator.rb

Overview

Resource locator.

Constant Summary collapse

PARSER =

Parser.

/^(.+)@(.+)(?:\:(\d+))?$/
DEFAULT_PORT =

Default port.

11300

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue, host = "localhost", port = 11300) ⇒ Locator

Constructor.

Parameters:

  • queue (String, Symbol)

    queue name

  • host (String) (defaults to: "localhost")

    host name

  • port (Integer) (defaults to: 11300)

    port of the host



60
61
62
63
64
# File 'lib/qrpc/locator.rb', line 60

def initialize(queue, host = "localhost", port = 11300)
    @queue = queue.to_s
    @host = host
    @port = port
end

Instance Attribute Details

#hostString

Contains host.

Returns:

  • (String)


29
30
31
# File 'lib/qrpc/locator.rb', line 29

def host
  @host
end

#portInteger

Contains port.

Returns:

  • (Integer)


37
38
39
# File 'lib/qrpc/locator.rb', line 37

def port
  @port
end

#queueSymbol

Contains queue name.

Returns:

  • (Symbol)


21
22
23
# File 'lib/qrpc/locator.rb', line 21

def queue
  @queue
end

Class Method Details

.parse(string) ⇒ QRPC::Locator

Parses the locator. Excpects form <queue>@<host>:<port>. Port is optional.

Parameters:

  • string (String)

    locator in string form

Returns:



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/qrpc/locator.rb', line 74

def self.parse(string)
    match = string.match(self::PARSER)
    
    queue = match[1]
    host = match[2]
    
    if match.length == 3
        port = match[3]
    else
        port = self::DEFAULT_PORT
    end
    
    port = port.to_i
    
    ##
    
    return self::new(queue, host, port);
end

Instance Method Details

#to_sString

Converts back to string.

Returns:

  • (String)

    locator in string form



98
99
100
# File 'lib/qrpc/locator.rb', line 98

def to_s
    @queue.dup << "@" << @host << ":" << @port.to_s
end