Class: CSC::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/cache-server-connector/server.rb

Direct Known Subclasses

MemcachedServer, RedisServer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, weight = 1, port = 0) ⇒ Server

Returns a new instance of Server.

Raises:

  • (NotImplementedError)


7
8
9
# File 'lib/cache-server-connector/server.rb', line 7

def initialize(host, weight = 1, port = 0)
	raise NotImplementedError.new("#{self.class.name} is an abstract class.")
end

Instance Attribute Details

#calledObject

Returns the value of attribute called.



5
6
7
# File 'lib/cache-server-connector/server.rb', line 5

def called
  @called
end

#hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/cache-server-connector/server.rb', line 5

def host
  @host
end

#portObject

Returns the value of attribute port.



5
6
7
# File 'lib/cache-server-connector/server.rb', line 5

def port
  @port
end

#weightObject

Returns the value of attribute weight.



5
6
7
# File 'lib/cache-server-connector/server.rb', line 5

def weight
  @weight
end

#weight_calledObject

Returns the value of attribute weight_called.



5
6
7
# File 'lib/cache-server-connector/server.rb', line 5

def weight_called
  @weight_called
end

Instance Method Details

#indexedObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/cache-server-connector/server.rb', line 11

def indexed
	@mutex ||= Mutex.new

	@mutex.synchronize { 
		@called += 1
		@weight_called = (@called + 1 / @weight).to_i
	}
	
	self
end

#to_sObject



22
23
24
# File 'lib/cache-server-connector/server.rb', line 22

def to_s
	"#@host:#@port"
end