Permalink
Browse files

Convert returned values for channel.* operations

  • Loading branch information...
1 parent d2308da commit a07cfbf75d058bafc5b5036669662bd3eab796b2 Michael Klishin committed Feb 27, 2013
Showing with 51 additions and 5 deletions.
  1. +9 −5 src/clojure/langohr/channel.clj
  2. +42 −0 src/java/com/novemberain/langohr/channel/FlowOk.java
@@ -8,7 +8,8 @@
;; You must not remove this notice, or any other, from this software.
(ns langohr.channel
- (:import [com.rabbitmq.client ConnectionFactory Connection Channel AMQP$Channel$FlowOk]))
+ (:import [com.rabbitmq.client ConnectionFactory Connection Channel]
+ com.novemberain.langohr.channel.FlowOk))
;;
@@ -17,8 +18,10 @@
(defn ^Channel open
"Opens a new channel on given connection using channel.open AMQP method"
- [^Connection connection]
- (.createChannel connection))
+ ([^Connection connection]
+ (.createChannel connection))
+ ([^Connection connection id]
+ (.createChannel connection id)))
(defn close
@@ -33,6 +36,7 @@
"Checks if channel is open. Consider using langohr.core/open? instead."
[^Channel channel]
(.isOpen channel))
+(def closed? (complement open?))
(defn ^Boolean flow?
@@ -41,7 +45,7 @@
(.getActive (.getFlow channel))))
-(defn ^AMQP$Channel$FlowOk flow
+(defn ^com.novemberain.langohr.channel.FlowOk flow
"Enables or disables channel flow using channel.flow AMQP method"
([^Channel channel ^Boolean on]
- (.flow channel on)))
+ (FlowOk. (.flow channel on))))
@@ -0,0 +1,42 @@
+package com.novemberain.langohr.channel;
+
+import clojure.lang.IPersistentMap;
+import clojure.lang.PersistentHashMap;
+import clojure.lang.RT;
+import com.novemberain.langohr.PersistentMapLike;
+import com.rabbitmq.client.AMQP;
+
+import java.util.HashMap;
+
+public class FlowOk extends PersistentMapLike implements AMQP.Channel.FlowOk {
+ private final AMQP.Channel.FlowOk method;
+
+ public FlowOk(AMQP.Channel.FlowOk method) {
+ this.method = method;
+
+ this.map = mapFrom(method);
+
+ }
+
+ public static IPersistentMap mapFrom(AMQP.Channel.FlowOk method) {
+ final HashMap m = new HashMap();
+ m.put(RT.keyword(null, "active"), method.getActive());
+ return PersistentHashMap.create(m);
+ }
+
+ public int protocolClassId() {
+ return method.protocolClassId();
+ }
+
+ public int protocolMethodId() {
+ return method.protocolMethodId();
+ }
+
+ public String protocolMethodName() {
+ return method.protocolMethodName();
+ }
+
+ public boolean getActive() {
+ return method.getActive();
+ }
+}

0 comments on commit a07cfbf

Please sign in to comment.