Class: EventMachine::Protocols::Memcache::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/evented_memcache_client/server.rb

Constant Summary collapse

DEFAULT_PORT =
22122
DEFAULT_HOST =
'localhost'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host = nil, port = nil) ⇒ Server

Create a new memcache server listener, on the specified host and port.



40
41
42
43
44
# File 'lib/evented_memcache_client/server.rb', line 40

def initialize(host=nil, port=nil)
  @host 	= host || DEFAULT_HOST
  @port 	= port || DEFAULT_PORT
  @connections 	= []
end

Instance Attribute Details

#connectionsObject

Returns the value of attribute connections.



34
35
36
# File 'lib/evented_memcache_client/server.rb', line 34

def connections
  @connections
end

#hostObject

Returns the value of attribute host.



35
36
37
# File 'lib/evented_memcache_client/server.rb', line 35

def host
  @host
end

#portObject

Returns the value of attribute port.



36
37
38
# File 'lib/evented_memcache_client/server.rb', line 36

def port
  @port
end

Instance Method Details

#close(conn) ⇒ Object



86
87
88
# File 'lib/evented_memcache_client/server.rb', line 86

def close(conn)
  @connections.delete(conn)
end

#get(conn, data, args) ⇒ Object



98
99
100
# File 'lib/evented_memcache_client/server.rb', line 98

def get(conn, data, args)
  # we don't do nuffing
end

#open(conn) ⇒ Object

Callbacks from the connection



82
83
84
# File 'lib/evented_memcache_client/server.rb', line 82

def open(conn)
  @connections << conn
end

#set(conn, data, args) ⇒ Object Also known as: replace, prepend, append, add



90
91
92
# File 'lib/evented_memcache_client/server.rb', line 90

def set(conn, data, args)
  # we don't do nuffing
end

#startObject

Start listening for client connections.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/evented_memcache_client/server.rb', line 47

def start
  begin
    @signature = EventMachine.start_server(@host,
                                           @port.to_i,
                                           Connectable,
                                           self) { |conn|
      conn.set_handler(self)

      # Usually called from EM; we fake it out.
      conn.connection_completed
    }
  rescue => e
    return false
  else
    return true
  end
end

#stopObject

Stop listening for client connections, and close any open clients.



67
68
69
70
71
72
73
74
75
# File 'lib/evented_memcache_client/server.rb', line 67

def stop
  EventMachine.stop_server(@signature)
  unless wait_for_connections
    # Still some running
    EventMachine.add_periodic_timer(1) {
      wait_for_connections
    }
  end
end