Permalink
Browse files

add Memcached::ATimeoutOccurred exception

  • Loading branch information...
1 parent 00189b2 commit 8c7304af49ee5be91d4751dd223dad333a9a5f2c @flyerhzm flyerhzm committed Aug 20, 2012
@@ -9,6 +9,7 @@
import net.spy.memcached.ConnectionFactoryBuilder.Protocol;
import net.spy.memcached.DefaultHashAlgorithm;
import net.spy.memcached.MemcachedClient;
+import net.spy.memcached.OperationTimeoutException;
import net.spy.memcached.transcoders.Transcoder;
import org.jruby.Ruby;
import org.jruby.RubyArray;
@@ -96,10 +97,12 @@ public IRubyObject add(ThreadContext context, IRubyObject[] args) {
throw Error.newNotStored(ruby, "not stored");
}
return context.nil;
- } catch (ExecutionException ee) {
- throw ruby.newRuntimeError(ee.getLocalizedMessage());
- } catch (InterruptedException ie) {
- throw ruby.newThreadError(ie.getLocalizedMessage());
+ } catch (OperationTimeoutException e) {
+ throw Error.newATimeoutOccurred(ruby, e.getLocalizedMessage());
+ } catch (ExecutionException e) {
+ throw ruby.newRuntimeError(e.getLocalizedMessage());
+ } catch (InterruptedException e) {
+ throw ruby.newThreadError(e.getLocalizedMessage());
}
}
@@ -115,10 +118,12 @@ public IRubyObject replace(ThreadContext context, IRubyObject [] args) {
throw Error.newNotStored(ruby, "not stored");
}
return context.nil;
- } catch (ExecutionException ee) {
- throw ruby.newRuntimeError(ee.getLocalizedMessage());
- } catch (InterruptedException ie) {
- throw ruby.newThreadError(ie.getLocalizedMessage());
+ } catch (OperationTimeoutException e) {
+ throw Error.newATimeoutOccurred(ruby, e.getLocalizedMessage());
+ } catch (ExecutionException e) {
+ throw ruby.newRuntimeError(e.getLocalizedMessage());
+ } catch (InterruptedException e) {
+ throw ruby.newThreadError(e.getLocalizedMessage());
}
}
@@ -134,10 +139,12 @@ public IRubyObject set(ThreadContext context, IRubyObject[] args) {
throw Error.newNotStored(ruby, "not stored");
}
return context.nil;
- } catch (ExecutionException ee) {
- throw ruby.newRuntimeError(ee.getLocalizedMessage());
- } catch (InterruptedException ie) {
- throw ruby.newThreadError(ie.getLocalizedMessage());
+ } catch (OperationTimeoutException e) {
+ throw Error.newATimeoutOccurred(ruby, e.getLocalizedMessage());
+ } catch (ExecutionException e) {
+ throw ruby.newRuntimeError(e.getLocalizedMessage());
+ } catch (InterruptedException e) {
+ throw ruby.newThreadError(e.getLocalizedMessage());
}
}
@@ -194,10 +201,12 @@ public IRubyObject delete(ThreadContext context, IRubyObject key) {
throw Error.newNotFound(ruby, "not found");
}
return context.nil;
- } catch (ExecutionException ee) {
- throw ruby.newRuntimeError(ee.getLocalizedMessage());
- } catch (InterruptedException ie) {
- throw ruby.newThreadError(ie.getLocalizedMessage());
+ } catch (OperationTimeoutException e) {
+ throw Error.newATimeoutOccurred(ruby, e.getLocalizedMessage());
+ } catch (ExecutionException e) {
+ throw ruby.newRuntimeError(e.getLocalizedMessage());
+ } catch (InterruptedException e) {
+ throw ruby.newThreadError(e.getLocalizedMessage());
}
}
@@ -207,10 +216,12 @@ public IRubyObject flush(ThreadContext context) {
try {
client.flush().get();
return context.nil;
- } catch (ExecutionException ee) {
- throw ruby.newRuntimeError(ee.getLocalizedMessage());
- } catch (InterruptedException ie) {
- throw ruby.newThreadError(ie.getLocalizedMessage());
+ } catch (OperationTimeoutException e) {
+ throw Error.newATimeoutOccurred(ruby, e.getLocalizedMessage());
+ } catch (ExecutionException e) {
+ throw ruby.newRuntimeError(e.getLocalizedMessage());
+ } catch (InterruptedException e) {
+ throw ruby.newThreadError(e.getLocalizedMessage());
}
}
@@ -29,6 +29,7 @@ public IRubyObject allocate(Ruby ruby, RubyClass klazz) {
memcached.defineClassUnder("NotFound", memcachedError, memcachedError.getAllocator());
memcached.defineClassUnder("NotStored", memcachedError, memcachedError.getAllocator());
memcached.defineClassUnder("NotSupport", memcachedError, memcachedError.getAllocator());
+ memcached.defineClassUnder("ATimeoutOccurred", memcachedError, memcachedError.getAllocator());
return true;
}
}
@@ -0,0 +1,7 @@
+package com.openfeint.memcached.error;
+
+import org.jruby.anno.JRubyClass;
+
+@JRubyClass(name="Memcached::ATimeoutOccurred", parent="Memcached::Error")
+public class ATimeoutOccurred extends Error {
+}
@@ -20,6 +20,10 @@ public static RaiseException newNotSupport(Ruby ruby, String message) {
return newMemcachedError(ruby, "NotSupport", message);
}
+ public static RaiseException newATimeoutOccurred(Ruby ruby, String message) {
+ return newMemcachedError(ruby, "ATimeoutOccurred", message);
+ }
+
private static RaiseException newMemcachedError(Ruby ruby, String klass, String message) {
RubyClass errorClass = ruby.getModule("Memcached").getClass(klass);
return new RaiseException(RubyException.newException(ruby, errorClass, message), true);
Binary file not shown.

0 comments on commit 8c7304a

Please sign in to comment.