Class: JSparrow::Connection::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/client.rb

Overview

Cliente JMS que possibilita a conexao com o servidor de aplicacoes Java EE que prove o servico JMS.

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Client

Returns a new instance of Client.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/client.rb', line 12

def initialize(connection)
  @connection = connection
    
  # Conexoes, filas, topicos, senders e receivers que serao habilitados
  @connection_factories = {}
  @queues               = {}
  @queue_senders        = {}
  @queue_receivers      = {}
  @topics               = {}
  @topic_senders        = {}
  @topic_receivers      = {}
end

Instance Method Details

#is_started?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/client.rb', line 25

def is_started?
  @connection.is_opened?
end

#is_stoped?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/client.rb', line 35

def is_stoped?
  @connection.is_closed?
end

#queue(queue_name) ⇒ Object

Raises:

  • (NameError)


47
48
49
50
51
# File 'lib/client.rb', line 47

def queue(queue_name)
  raise NameError, "Queue '#{queue_name}' does not exist." unless queue_enabled?(queue_name)
    
  @queues[queue_name]
end

#queue_enabled?(queue_name) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/client.rb', line 43

def queue_enabled?(queue_name)
  @connection.configuration.enabled_queues.include?(queue_name)
end

#queue_receiver(queue_name) ⇒ Object



58
59
60
61
# File 'lib/client.rb', line 58

def queue_receiver(queue_name)
  @queue_receivers[queue_name] ||=
      Messaging::Receiver.new(queue_connection_factory, queue(queue_name))
end

#queue_sender(queue_name) ⇒ Object



53
54
55
56
# File 'lib/client.rb', line 53

def queue_sender(queue_name)
  @queue_senders[queue_name] ||=
      Messaging::Sender.new(queue_connection_factory, queue(queue_name))
end

#startObject



29
30
31
32
33
# File 'lib/client.rb', line 29

def start
  @connection.open
    
  @connection_factories, @queues, @topics = lookup_resources
end

#stopObject



39
40
41
# File 'lib/client.rb', line 39

def stop
  @connection.close
end

#topic(topic_name) ⇒ Object

Raises:

  • (NameError)


67
68
69
70
71
# File 'lib/client.rb', line 67

def topic(topic_name)
  raise NameError, "Topic '#{topic_name}' does not exist." unless topic_enabled?(topic_name)
    
  @topics[topic_name]
end

#topic_enabled?(topic_name) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/client.rb', line 63

def topic_enabled?(topic_name)
  @connection.configuration.enabled_topics.include?(topic_name)
end

#topic_receiver(topic_name) ⇒ Object



78
79
80
81
# File 'lib/client.rb', line 78

def topic_receiver(topic_name)
  @topic_receivers[topic_name] ||=
      Messaging::Receiver.new(topic_connection_factory, topic(topic_name))
end

#topic_sender(topic_name) ⇒ Object



73
74
75
76
# File 'lib/client.rb', line 73

def topic_sender(topic_name)
  @topic_senders[topic_name] ||=
      Messaging::Sender.new(topic_connection_factory, topic(topic_name))
end