Class: Scalaroid::PubSub

Inherits:
Object
  • Object
show all
Includes:
InternalScalarisNopClose
Defined in:
lib/scalaroid/pub_sub.rb

Overview

Publish and subscribe methods accessing Scalaris’ pubsub system

Instance Method Summary collapse

Methods included from InternalScalarisNopClose

#close_connection, #nop

Constructor Details

#initialize(conn = JSONConnection.new()) ⇒ PubSub

Create a new object using the given connection.



5
6
7
# File 'lib/scalaroid/pub_sub.rb', line 5

def initialize(conn = JSONConnection.new())
  @conn = conn
end

Instance Method Details

#get_subscribers(topic) ⇒ Object

Gets the list of all subscribers to topic.



37
38
39
40
# File 'lib/scalaroid/pub_sub.rb', line 37

def get_subscribers(topic)
  result = @conn.call(:get_subscribers, [topic])
  @conn.class.process_result_get_subscribers(result)
end

#publish(topic, content) ⇒ Object

Publishes content under topic.



10
11
12
13
14
15
16
# File 'lib/scalaroid/pub_sub.rb', line 10

def publish(topic, content)
  # note: do NOT encode the content, this is not decoded on the erlang side!
  # (only strings are allowed anyway)
  # content = @conn.class.encode_value(content)
  result = @conn.call(:publish, [topic, content])
  @conn.class.process_result_publish(result)
end

#subscribe(topic, url) ⇒ Object

Subscribes url for topic.



19
20
21
22
23
24
25
# File 'lib/scalaroid/pub_sub.rb', line 19

def subscribe(topic, url)
  # note: do NOT encode the URL, this is not decoded on the erlang side!
  # (only strings are allowed anyway)
  # url = @conn.class.encode_value(url)
  result = @conn.call(:subscribe, [topic, url])
  @conn.class.process_result_subscribe(result)
end

#unsubscribe(topic, url) ⇒ Object

Unsubscribes url from topic.



28
29
30
31
32
33
34
# File 'lib/scalaroid/pub_sub.rb', line 28

def unsubscribe(topic, url)
  # note: do NOT encode the URL, this is not decoded on the erlang side!
  # (only strings are allowed anyway)
  # url = @conn.class.encode_value(url)
  result = @conn.call(:unsubscribe, [topic, url])
  @conn.class.process_result_unsubscribe(result)
end