AdoccaMemcache 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Rakefile +1 -1
  2. data/lib/am_memcache.rb +14 -60
  3. metadata +1 -1
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rubygems'
4
4
  require 'hoe'
5
5
  require './lib/adocca_memcache.rb'
6
6
 
7
- Hoe.new('AdoccaMemcache', '0.1.5') do |p|
7
+ Hoe.new('AdoccaMemcache', '0.1.6') do |p|
8
8
  p.rubyforge_name = 'adocca-plugins'
9
9
  p.author = 'adocca Entertainment AB'
10
10
  p.summary = 'A client library to simplify using memcached with Ruby on Rails projects.'
data/lib/am_memcache.rb CHANGED
@@ -2,6 +2,7 @@ require 'socket'
2
2
  require 'thread'
3
3
  require 'digest/sha1'
4
4
  require 'timeout'
5
+ require 'monitor'
5
6
 
6
7
  module Adocca
7
8
 
@@ -72,28 +73,6 @@ module Adocca
72
73
  end
73
74
  @servers = []
74
75
  @buckets = []
75
- start_validation
76
- end
77
-
78
- def start_validation
79
- Thread.new do
80
- loop do
81
- begin
82
- @servers.each do |server|
83
- server.check_liveliness if server.alive?
84
- end
85
- sleep VALIDATION_INTERVAL
86
- rescue Exception => e
87
- if defined?(RAILS_DEFAULT_LOGGER)
88
- RAILS_DEFAULT_LOGGER.error("validation got #{e}")
89
- RAILS_DEFAULT_LOGGER.error(PP.pp(e.backtrace, ""))
90
- else
91
- puts e
92
- pp e.backtrace
93
- end
94
- end
95
- end
96
- end
97
76
  end
98
77
 
99
78
  # Return a string representation of the cache object.
@@ -153,8 +132,10 @@ module Adocca
153
132
 
154
133
  sock.gets
155
134
  sock.gets
156
- rescue SystemCallError, IOError => err
157
- server.mark_dead
135
+ rescue MemCacheError => e
136
+ raise e
137
+ rescue Exception => err
138
+ server.mark_dead(err.message)
158
139
  raise MemCacheError, err.message
159
140
  end
160
141
  end
@@ -270,8 +251,8 @@ module Adocca
270
251
  value = sock.read(bytes.to_i)
271
252
  sock.gets
272
253
  sock.gets
273
- rescue SystemCallError, IOError => err
274
- server.mark_dead
254
+ rescue Exception => err
255
+ server.mark_dead(err.message)
275
256
  raise MemCacheError, err.message
276
257
  end
277
258
 
@@ -293,8 +274,8 @@ module Adocca
293
274
  begin
294
275
  sock.write "flush_all\r\n"
295
276
  sock.gets
296
- rescue SystemCallError, IOError => err
297
- server.mark_dead
277
+ rescue Exception => err
278
+ server.mark_dead(err.message)
298
279
  raise MemCacheError, err.message
299
280
  end
300
281
  end
@@ -368,6 +349,7 @@ module Adocca
368
349
 
369
350
  # This class represents a memcached server instance.
370
351
  class Server
352
+ extend Forwardable
371
353
  # The amount of time to wait to establish a connection with a
372
354
  # memcached server. If a connection cannot be established within
373
355
  # this time limit, the server will be marked as down.
@@ -415,34 +397,6 @@ module Adocca
415
397
  @status = "NOT CONNECTED"
416
398
  end
417
399
 
418
- #
419
- # Will make sure the server works and mark_dead if not.
420
- #
421
- def check_liveliness
422
- key = rand(1 << 32).to_s
423
- value = rand(1 << 32).to_s
424
- begin
425
- timeout(LIVELINESS_TIMEOUT) do
426
- socket.write("set am_memcache_check_liveliness_#{key} 0 #{LIVELINESS_TIMEOUT * 2} #{value.size}\r\n" + value + "\r\n")
427
- raise 'bad response to set' unless @sock.gets == "STORED\r\n"
428
- socket.write("get am_memcache_check_liveliness_#{key}\r\n")
429
- v, cache_key, flags, bytes = @sock.gets.split(/ /)
430
- raise 'bad response to get' unless @sock.read(bytes.to_i) == value
431
- socket.gets
432
- socket.gets
433
- end
434
- rescue Exception => e
435
- mark_dead
436
- if defined?(RAILS_DEFAULT_LOGGER)
437
- RAILS_DEFAULT_LOGGER.error("liveliness check got #{e}")
438
- RAILS_DEFAULT_LOGGER.error(PP.pp(e.backtrace, ""))
439
- else
440
- puts e
441
- pp e.backtrace
442
- end
443
- end
444
- end
445
-
446
400
  # Return a string representation of the server object.
447
401
  def inspect
448
402
  sprintf("<MemCache::Server: %s:%d [%d] (%s)>",
@@ -472,7 +426,7 @@ module Adocca
472
426
  }
473
427
  @retry = nil
474
428
  @status = "CONNECTED"
475
- rescue SystemCallError, IOError, Timeout::Error => err
429
+ rescue Exception => err
476
430
  self.mark_dead(err.message)
477
431
  end
478
432
  end
@@ -505,7 +459,7 @@ module Adocca
505
459
  ###########################################################################
506
460
 
507
461
  # Base MemCache exception class.
508
- class MemCacheError < ::Exception
462
+ class MemCacheError < ::RuntimeError
509
463
  end
510
464
 
511
465
  # MemCache internal error class. Instances of this class mean that there
@@ -557,8 +511,8 @@ module Adocca
557
511
  begin
558
512
  sock.write "#{command}\r\n"
559
513
  [sock.gets, sock, server]
560
- rescue SystemCallError, IOError => err
561
- server.mark_dead
514
+ rescue Exception => err
515
+ server.mark_dead(err.message)
562
516
  raise MemCacheError, err.message
563
517
  end
564
518
  end
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: AdoccaMemcache
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.5
6
+ version: 0.1.6
7
7
  date: 2007-02-12 00:00:00 +01:00
8
8
  summary: A client library to simplify using memcached with Ruby on Rails projects.
9
9
  require_paths: