Class: QRPC::Locator::EMJackLocator

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

Overview

Locator for ‘em-jack’ (so EventMachine Beanstalk implementation) queue type.

See Also:

Since:

  • 0.9.0

Constant Summary collapse

PARSER =

Parser.

Since:

  • 0.9.0

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

Default port.

Since:

  • 0.9.0

11300

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue_name, host = "localhost", port = 11300) ⇒ EMJackLocator

Constructor.

Parameters:

  • queue_name (String, Symbol)

    queue name

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

    host name

  • port (Integer) (defaults to: 11300)

    port of the host

Since:

  • 0.9.0



88
89
90
91
92
# File 'lib/qrpc/locator/em-jack.rb', line 88

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

Instance Attribute Details

#hostString

Contains host.

Returns:

  • (String)

Since:

  • 0.9.0



57
58
59
# File 'lib/qrpc/locator/em-jack.rb', line 57

def host
  @host
end

#portInteger

Contains port.

Returns:

  • (Integer)

Since:

  • 0.9.0



65
66
67
# File 'lib/qrpc/locator/em-jack.rb', line 65

def port
  @port
end

#queue_nameString

Contains queue name.

Returns:

  • (String)

Since:

  • 0.9.0



49
50
51
# File 'lib/qrpc/locator/em-jack.rb', line 49

def queue_name
  @queue_name
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:

Since:

  • 0.9.0



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/qrpc/locator/em-jack.rb', line 102

def self.parse(string)
    match = string.match(self::PARSER)
    
    queue = match.first
    host = match.second
    
    if match.length == 3
        port = match.third
    else
        port = self::DEFAULT_PORT
    end
    
    port = port.to_i
    
    ##
    
    return self::new(queue, host, port);
end

Instance Method Details

#input_queueUnifiedQueues::Multi

Returns universal queue interface for input queue.

Returns:

  • (UnifiedQueues::Multi)

    queue

Since:

  • 0.9.0



135
136
137
138
139
140
141
# File 'lib/qrpc/locator/em-jack.rb', line 135

def input_queue
    if @input_queue.nil?
        @input_queue = UnifiedQueues::Multi::new EMJack::Connection, :host => @host, :port => @port
    else
        @input_queue
    end
end

#output_queueUnifiedQueues::Multi

Returns universal queue interface for output queue.

Returns:

  • (UnifiedQueues::Multi)

    queue

Since:

  • 0.9.0



148
149
150
151
152
153
154
# File 'lib/qrpc/locator/em-jack.rb', line 148

def output_queue
    if @output_queue.nil?
        @output_queue = UnifiedQueues::Multi::new EMJack::Connection, :host => @host, :port => @port
    else
        @output_queue
    end
end

#to_sString

Converts back to string.

Returns:

  • (String)

    locator in string form

Since:

  • 0.9.0



126
127
128
# File 'lib/qrpc/locator/em-jack.rb', line 126

def to_s
    @queue_name + "@" + @host + ":" + @port.to_s
end