class Scalaroid::PubSub

Publish and subscribe methods accessing Scalaris’ pubsub system

Public Class Methods

new(conn = JSONConnection.new()) click to toggle source

Create a new object using the given connection.

# File lib/scalaroid/pub_sub.rb, line 5
def initialize(conn = JSONConnection.new())
  @conn = conn
end

Public Instance Methods

get_subscribers(topic) click to toggle source

Gets the list of all subscribers to topic.

# 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) click to toggle source

Publishes content under topic.

# 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) click to toggle source

Subscribes url for topic.

# 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) click to toggle source

Unsubscribes url from topic.

# 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