zas-client 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/zas/client.rb +31 -17
  2. metadata +1 -1
data/lib/zas/client.rb CHANGED
@@ -18,22 +18,15 @@ module Zas
18
18
  # Public: Initialize the client with the given configuration.
19
19
  #
20
20
  # config - Configuration spec for the client.
21
+ #
22
+ # Important note: when you construct the Zas::Client it is your responsibility to shut
23
+ # down cleanly. To do this call client.shutdown when your consumer exits.
21
24
  def initialize(config=ClientConfiguration.new)
22
25
  self.host = config.host
23
26
  self.port = config.port
24
27
  self.timeout = config.timeout
25
28
  self.logger = config.logger
26
29
  self.context = ZMQ::Context.new
27
-
28
- Signal.trap(:INT) {
29
- begin
30
- puts "Trapped INT in Zas client"
31
- disconnect
32
- close
33
- rescue => e
34
- puts "Error while trying to shut down zas client: #{e.message}"
35
- end
36
- }
37
30
  end
38
31
 
39
32
  # Public: Authenticate the given credentials.
@@ -67,20 +60,40 @@ module Zas
67
60
 
68
61
  # Public: Disconnect the socket.
69
62
  def disconnect
70
- if socket
71
- logger.debug "Closing socket #{socket.inspect}"
72
- socket.close
63
+ if @socket
64
+ @socket.close
65
+ logger.debug "Closed socket #{@socket.inspect}"
73
66
  end
74
67
  @socket = nil
68
+ rescue Exception => e
69
+ puts "Exception in disconnect(): #{e.message}"
70
+ raise
75
71
  end
76
72
 
77
73
  # Public: Close the context.
78
74
  def close
79
- if context
80
- logger.debug "Closing context #{context.inspect}"
81
- context.close
82
- context = nil
75
+ if @context
76
+ puts "Closing context #{@context.inspect}"
77
+ @context.close
78
+ puts "Closed context #{@context.inspect}"
83
79
  end
80
+ @context = nil
81
+ rescue Exception => e
82
+ puts "Exception is close(): #{e.message}"
83
+ raise
84
+ end
85
+
86
+ # Public: shut down the client (disconnect any open sockets
87
+ # and close the context.
88
+ def shutdown
89
+ puts "Disconnecting"
90
+ disconnect
91
+ puts "Closing"
92
+ close
93
+ puts "Done"
94
+ rescue Exception => e
95
+ puts "Exception in shutdown(): #{e.message}"
96
+ raise
84
97
  end
85
98
 
86
99
  private
@@ -102,6 +115,7 @@ module Zas
102
115
  socket
103
116
  else
104
117
  logger.info "Cannot build a new socket as there is no context"
118
+ nil
105
119
  end
106
120
  end
107
121
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zas-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: