azure_application_insights 0.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/gem-push.yml +34 -0
  3. data/.gitignore +40 -0
  4. data/.travis.yml +22 -0
  5. data/CHANGELOG.md +17 -0
  6. data/CONTRIBUTING.md +68 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE.txt +11 -0
  9. data/README.md +161 -0
  10. data/Rakefile +15 -0
  11. data/application_insights.gemspec +30 -0
  12. data/lib/application_insights/channel/asynchronous_queue.rb +58 -0
  13. data/lib/application_insights/channel/asynchronous_sender.rb +133 -0
  14. data/lib/application_insights/channel/contracts/application.rb +14 -0
  15. data/lib/application_insights/channel/contracts/cloud.rb +14 -0
  16. data/lib/application_insights/channel/contracts/data.rb +14 -0
  17. data/lib/application_insights/channel/contracts/data_point.rb +24 -0
  18. data/lib/application_insights/channel/contracts/data_point_type.rb +7 -0
  19. data/lib/application_insights/channel/contracts/dependency_kind.rb +9 -0
  20. data/lib/application_insights/channel/contracts/dependency_source_type.rb +9 -0
  21. data/lib/application_insights/channel/contracts/device.rb +28 -0
  22. data/lib/application_insights/channel/contracts/envelope.rb +40 -0
  23. data/lib/application_insights/channel/contracts/event_data.rb +28 -0
  24. data/lib/application_insights/channel/contracts/exception_data.rb +37 -0
  25. data/lib/application_insights/channel/contracts/exception_details.rb +28 -0
  26. data/lib/application_insights/channel/contracts/internal.rb +14 -0
  27. data/lib/application_insights/channel/contracts/json_serializable.rb +59 -0
  28. data/lib/application_insights/channel/contracts/location.rb +16 -0
  29. data/lib/application_insights/channel/contracts/message_data.rb +24 -0
  30. data/lib/application_insights/channel/contracts/metric_data.rb +27 -0
  31. data/lib/application_insights/channel/contracts/operation.rb +19 -0
  32. data/lib/application_insights/channel/contracts/page_view_data.rb +30 -0
  33. data/lib/application_insights/channel/contracts/remote_dependency_data.rb +56 -0
  34. data/lib/application_insights/channel/contracts/request_data.rb +36 -0
  35. data/lib/application_insights/channel/contracts/session.rb +15 -0
  36. data/lib/application_insights/channel/contracts/severity_level.rb +13 -0
  37. data/lib/application_insights/channel/contracts/stack_frame.rb +17 -0
  38. data/lib/application_insights/channel/contracts/user.rb +19 -0
  39. data/lib/application_insights/channel/event.rb +68 -0
  40. data/lib/application_insights/channel/queue_base.rb +73 -0
  41. data/lib/application_insights/channel/sender_base.rb +88 -0
  42. data/lib/application_insights/channel/synchronous_queue.rb +45 -0
  43. data/lib/application_insights/channel/synchronous_sender.rb +17 -0
  44. data/lib/application_insights/channel/telemetry_channel.rb +131 -0
  45. data/lib/application_insights/channel/telemetry_context.rb +85 -0
  46. data/lib/application_insights/rack/track_request.rb +158 -0
  47. data/lib/application_insights/telemetry_client.rb +229 -0
  48. data/lib/application_insights/unhandled_exception.rb +49 -0
  49. data/lib/application_insights/version.rb +3 -0
  50. data/lib/application_insights.rb +9 -0
  51. data/test/application_insights/channel/contracts/test_application.rb +44 -0
  52. data/test/application_insights/channel/contracts/test_cloud.rb +44 -0
  53. data/test/application_insights/channel/contracts/test_data.rb +44 -0
  54. data/test/application_insights/channel/contracts/test_data_point.rb +109 -0
  55. data/test/application_insights/channel/contracts/test_device.rb +200 -0
  56. data/test/application_insights/channel/contracts/test_envelope.rb +209 -0
  57. data/test/application_insights/channel/contracts/test_event_data.rb +62 -0
  58. data/test/application_insights/channel/contracts/test_exception_data.rb +111 -0
  59. data/test/application_insights/channel/contracts/test_exception_details.rb +106 -0
  60. data/test/application_insights/channel/contracts/test_internal.rb +44 -0
  61. data/test/application_insights/channel/contracts/test_location.rb +70 -0
  62. data/test/application_insights/channel/contracts/test_message_data.rb +66 -0
  63. data/test/application_insights/channel/contracts/test_metric_data.rb +50 -0
  64. data/test/application_insights/channel/contracts/test_operation.rb +109 -0
  65. data/test/application_insights/channel/contracts/test_page_view_data.rb +88 -0
  66. data/test/application_insights/channel/contracts/test_remote_dependency_data.rb +209 -0
  67. data/test/application_insights/channel/contracts/test_request_data.rb +153 -0
  68. data/test/application_insights/channel/contracts/test_session.rb +57 -0
  69. data/test/application_insights/channel/contracts/test_stack_frame.rb +83 -0
  70. data/test/application_insights/channel/contracts/test_user.rb +96 -0
  71. data/test/application_insights/channel/test_asynchronous_queue.rb +47 -0
  72. data/test/application_insights/channel/test_asynchronous_sender.rb +81 -0
  73. data/test/application_insights/channel/test_event.rb +53 -0
  74. data/test/application_insights/channel/test_queue_base.rb +89 -0
  75. data/test/application_insights/channel/test_sender_base.rb +94 -0
  76. data/test/application_insights/channel/test_synchronous_queue.rb +28 -0
  77. data/test/application_insights/channel/test_synchronous_sender.rb +11 -0
  78. data/test/application_insights/channel/test_telemetry_channel.rb +167 -0
  79. data/test/application_insights/channel/test_telemetry_context.rb +83 -0
  80. data/test/application_insights/mock_sender.rb +37 -0
  81. data/test/application_insights/rack/test_track_request.rb +182 -0
  82. data/test/application_insights/test_logger.rb +10 -0
  83. data/test/application_insights/test_telemetry_client.rb +138 -0
  84. data/test/application_insights/test_unhandled_exception.rb +23 -0
  85. data/test/application_insights.rb +8 -0
  86. metadata +247 -0
@@ -0,0 +1,24 @@
1
+ require_relative 'json_serializable'
2
+ require_relative 'data_point_type'
3
+
4
+ module ApplicationInsights::Channel::Contracts
5
+ class DataPoint
6
+ include JsonSerializable
7
+
8
+ attr_accessor :name, :kind, :value, :count, :min, :max, :std_dev
9
+
10
+ attribute_mapping(
11
+ name: 'name',
12
+ kind: 'kind',
13
+ value: 'value',
14
+ count: 'count',
15
+ min: 'min',
16
+ max: 'max',
17
+ std_dev: 'stdDev'
18
+ )
19
+
20
+ def kind
21
+ @kind ||= DataPointType::MEASUREMENT
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,7 @@
1
+ module ApplicationInsights::Channel::Contracts
2
+ class DataPointType
3
+ MEASUREMENT = 0
4
+
5
+ AGGREGATION = 1
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ module ApplicationInsights::Channel::Contracts
2
+ class DependencyKind
3
+ SQL = 0
4
+
5
+ HTTP = 1
6
+
7
+ OTHER = 2
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module ApplicationInsights::Channel::Contracts
2
+ class DependencySourceType
3
+ UNDEFINED = 0
4
+
5
+ AIC = 1
6
+
7
+ APMC = 2
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'json_serializable'
2
+
3
+ module ApplicationInsights::Channel::Contracts
4
+ class Device
5
+ include JsonSerializable
6
+
7
+ attr_accessor :id, :ip, :language, :locale, :model, :network, :oem_name,
8
+ :os, :os_version, :role_instance, :role_name, :screen_resolution, :type,
9
+ :machine_name
10
+
11
+ attribute_mapping(
12
+ id: 'ai.device.id',
13
+ ip: 'ai.device.ip',
14
+ language: 'ai.device.language',
15
+ locale: 'ai.device.locale',
16
+ model: 'ai.device.model',
17
+ network: 'ai.device.network',
18
+ oem_name: 'ai.device.oemName',
19
+ os: 'ai.device.os',
20
+ os_version: 'ai.device.osVersion',
21
+ role_instance: 'ai.device.roleInstance',
22
+ role_name: 'ai.device.roleName',
23
+ screen_resolution: 'ai.device.screenResolution',
24
+ type: 'ai.device.type',
25
+ machine_name: 'ai.device.machineName'
26
+ )
27
+ end
28
+ end
@@ -0,0 +1,40 @@
1
+ require_relative 'json_serializable'
2
+
3
+ module ApplicationInsights::Channel::Contracts
4
+ class Envelope
5
+ include JsonSerializable
6
+
7
+ attr_accessor :ver, :name, :time, :sample_rate, :seq, :i_key, :flags, :device_id,
8
+ :os, :os_ver, :app_id, :app_ver, :user_id, :tags, :data
9
+
10
+ attribute_mapping(
11
+ ver: 'ver',
12
+ name: 'name',
13
+ time: 'time',
14
+ sample_rate: 'sampleRate',
15
+ seq: 'seq',
16
+ i_key: 'iKey',
17
+ flags: 'flags',
18
+ device_id: 'deviceId',
19
+ os: 'os',
20
+ os_ver: 'osVer',
21
+ app_id: 'appId',
22
+ app_ver: 'appVer',
23
+ user_id: 'userId',
24
+ tags: 'tags',
25
+ data: 'data'
26
+ )
27
+
28
+ def ver
29
+ @ver ||= 1
30
+ end
31
+
32
+ def sample_rate
33
+ @sample_rate ||= 100.0
34
+ end
35
+
36
+ def tags
37
+ @tags ||= {}
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'json_serializable'
2
+
3
+ module ApplicationInsights::Channel::Contracts
4
+ class EventData
5
+ include JsonSerializable
6
+
7
+ attr_accessor :ver, :name, :properties, :measurements
8
+
9
+ attribute_mapping(
10
+ ver: 'ver',
11
+ name: 'name',
12
+ properties: 'properties',
13
+ measurements: 'measurements'
14
+ )
15
+
16
+ def ver
17
+ @ver ||= 2
18
+ end
19
+
20
+ def properties
21
+ @properties ||= {}
22
+ end
23
+
24
+ def measurements
25
+ @measurements ||= {}
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,37 @@
1
+ require_relative 'json_serializable'
2
+
3
+ module ApplicationInsights::Channel::Contracts
4
+ class ExceptionData
5
+ include JsonSerializable
6
+
7
+ attr_accessor :ver, :handled_at, :exceptions, :severity_level, :problem_id,
8
+ :crash_thread_id, :properties, :measurements
9
+
10
+ attribute_mapping(
11
+ ver: 'ver',
12
+ handled_at: 'handledAt',
13
+ exceptions: 'exceptions',
14
+ severity_level: 'severityLevel',
15
+ problem_id: 'problemId',
16
+ crash_thread_id: 'crashThreadId',
17
+ properties: 'properties',
18
+ measurements: 'measurements'
19
+ )
20
+
21
+ def ver
22
+ @ver ||= 2
23
+ end
24
+
25
+ def exceptions
26
+ @exceptions ||= []
27
+ end
28
+
29
+ def properties
30
+ @properties ||= {}
31
+ end
32
+
33
+ def measurements
34
+ @measurements ||= {}
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'json_serializable'
2
+
3
+ module ApplicationInsights::Channel::Contracts
4
+ class ExceptionDetails
5
+ include JsonSerializable
6
+
7
+ attr_accessor :id, :outer_id, :type_name, :message, :has_full_stack, :stack,
8
+ :parsed_stack
9
+
10
+ attribute_mapping(
11
+ id: 'id',
12
+ outer_id: 'outerId',
13
+ type_name: 'typeName',
14
+ message: 'message',
15
+ has_full_stack: 'hasFullStack',
16
+ stack: 'stack',
17
+ parsed_stack: 'parsedStack'
18
+ )
19
+
20
+ def has_full_stack
21
+ @has_full_stack.nil? ? true : @has_full_stack
22
+ end
23
+
24
+ def parsed_stack
25
+ @parsed_stack ||= []
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,14 @@
1
+ require_relative 'json_serializable'
2
+
3
+ module ApplicationInsights::Channel::Contracts
4
+ class Internal
5
+ include JsonSerializable
6
+
7
+ attr_accessor :sdk_version, :agent_version
8
+
9
+ attribute_mapping(
10
+ sdk_version: 'ai.internal.sdkVersion',
11
+ agent_version: 'ai.internal.agentVersion'
12
+ )
13
+ end
14
+ end
@@ -0,0 +1,59 @@
1
+ require 'json'
2
+
3
+ module ApplicationInsights
4
+ module Channel
5
+ module Contracts
6
+ module JsonSerializable
7
+ module ClassMethods
8
+ attr_reader :json_mappings
9
+
10
+ def attribute_mapping(mappings)
11
+ @json_mappings = mappings
12
+ end
13
+ end
14
+
15
+ def self.included(klass)
16
+ klass.extend JsonSerializable::ClassMethods
17
+ end
18
+
19
+ def initialize(attributes = {})
20
+ attributes.each { |k, v| send(:"#{k}=", v) }
21
+ end
22
+
23
+ def to_h
24
+ output = {}
25
+ klass = self.class
26
+
27
+ klass.json_mappings.each do |attr, name|
28
+ value = visit self.send(attr)
29
+ is_empty = value.respond_to?(:empty?) && value.empty?
30
+
31
+ output[name] = value unless value.nil? || is_empty
32
+ end
33
+
34
+ output
35
+ end
36
+
37
+ def to_json(args = {})
38
+ JSON.generate self.to_h, args
39
+ end
40
+
41
+ private
42
+
43
+ def visit(object)
44
+ return if object.nil?
45
+
46
+ if object.is_a? Array
47
+ object.map { |e| visit e }
48
+ elsif object.is_a? Hash
49
+ Hash[object.map { |k, v| [k, visit(v)] }]
50
+ elsif object.respond_to? :to_h
51
+ object.to_h
52
+ else
53
+ object
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,16 @@
1
+ require_relative 'json_serializable'
2
+
3
+ module ApplicationInsights::Channel::Contracts
4
+ class Location
5
+ include JsonSerializable
6
+
7
+ attr_accessor :ip, :country, :province, :city
8
+
9
+ attribute_mapping(
10
+ ip: 'ai.location.ip',
11
+ country: 'ai.location.country',
12
+ province: 'ai.location.province',
13
+ city: 'ai.location.city'
14
+ )
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ require_relative 'json_serializable'
2
+
3
+ module ApplicationInsights::Channel::Contracts
4
+ class MessageData
5
+ include JsonSerializable
6
+
7
+ attr_accessor :ver, :message, :severity_level, :properties
8
+
9
+ attribute_mapping(
10
+ ver: 'ver',
11
+ message: 'message',
12
+ severity_level: 'severityLevel',
13
+ properties: 'properties'
14
+ )
15
+
16
+ def ver
17
+ @ver ||= 2
18
+ end
19
+
20
+ def properties
21
+ @properties ||= {}
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,27 @@
1
+ require_relative 'json_serializable'
2
+
3
+ module ApplicationInsights::Channel::Contracts
4
+ class MetricData
5
+ include JsonSerializable
6
+
7
+ attr_accessor :ver, :metrics, :properties
8
+
9
+ attribute_mapping(
10
+ ver: 'ver',
11
+ metrics: 'metrics',
12
+ properties: 'properties'
13
+ )
14
+
15
+ def ver
16
+ @ver ||= 2
17
+ end
18
+
19
+ def metrics
20
+ @metrics ||= []
21
+ end
22
+
23
+ def properties
24
+ @properties ||= {}
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,19 @@
1
+ require_relative 'json_serializable'
2
+
3
+ module ApplicationInsights::Channel::Contracts
4
+ class Operation
5
+ include JsonSerializable
6
+
7
+ attr_accessor :id, :name, :parent_id, :root_id, :synthetic_source, :is_synthetic, :correlation_vector
8
+
9
+ attribute_mapping(
10
+ id: 'ai.operation.id',
11
+ name: 'ai.operation.name',
12
+ parent_id: 'ai.operation.parentId',
13
+ root_id: 'ai.operation.rootId',
14
+ synthetic_source: 'ai.operation.syntheticSource',
15
+ is_synthetic: 'ai.operation.isSynthetic',
16
+ correlation_vector: 'ai.operation.correlationVector'
17
+ )
18
+ end
19
+ end
@@ -0,0 +1,30 @@
1
+ require_relative 'json_serializable'
2
+
3
+ module ApplicationInsights::Channel::Contracts
4
+ class PageViewData
5
+ include JsonSerializable
6
+
7
+ attr_accessor :ver, :url, :name, :duration, :properties, :measurements
8
+
9
+ attribute_mapping(
10
+ ver: 'ver',
11
+ url: 'url',
12
+ name: 'name',
13
+ duration: 'duration',
14
+ properties: 'properties',
15
+ measurements: 'measurements'
16
+ )
17
+
18
+ def ver
19
+ @ver ||= 2
20
+ end
21
+
22
+ def properties
23
+ @properties ||= {}
24
+ end
25
+
26
+ def measurements
27
+ @measurements ||= {}
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,56 @@
1
+ require_relative 'json_serializable'
2
+ require_relative 'data_point_type'
3
+ require_relative 'dependency_kind'
4
+ require_relative 'dependency_source_type'
5
+
6
+ module ApplicationInsights::Channel::Contracts
7
+ class RemoteDependencyData
8
+ include JsonSerializable
9
+
10
+ attr_accessor :ver, :name, :kind, :value, :count, :min, :max, :std_dev,
11
+ :dependency_kind, :success, :async, :dependency_source, :command_name,
12
+ :dependency_type_name, :properties
13
+
14
+ attribute_mapping(
15
+ ver: 'ver',
16
+ name: 'name',
17
+ kind: 'kind',
18
+ value: 'value',
19
+ count: 'count',
20
+ min: 'min',
21
+ max: 'max',
22
+ std_dev: 'stdDev',
23
+ dependency_kind: 'dependencyKind',
24
+ success: 'success',
25
+ async: 'async',
26
+ dependency_source: 'dependencySource',
27
+ command_name: 'commandName',
28
+ dependency_type_name: 'dependencyTypeName',
29
+ properties: 'properties'
30
+ )
31
+
32
+ def ver
33
+ @ver ||= 2
34
+ end
35
+
36
+ def kind
37
+ @kind ||= DataPointType::MEASUREMENT
38
+ end
39
+
40
+ def dependency_kind
41
+ @dependency_kind ||= DependencyKind::OTHER
42
+ end
43
+
44
+ def success
45
+ @success.nil? ? true : @success
46
+ end
47
+
48
+ def dependency_source
49
+ @dependency_source ||= DependencySourceType::UNDEFINED
50
+ end
51
+
52
+ def properties
53
+ @properties ||= {}
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,36 @@
1
+ require_relative 'json_serializable'
2
+
3
+ module ApplicationInsights::Channel::Contracts
4
+ class RequestData
5
+ include JsonSerializable
6
+
7
+ attr_accessor :ver, :id, :name, :start_time, :duration, :response_code,
8
+ :success, :http_method, :url, :properties, :measurements
9
+
10
+ attribute_mapping(
11
+ ver: 'ver',
12
+ id: 'id',
13
+ name: 'name',
14
+ start_time: 'startTime',
15
+ duration: 'duration',
16
+ response_code: 'responseCode',
17
+ success: 'success',
18
+ http_method: 'httpMethod',
19
+ url: 'url',
20
+ properties: 'properties',
21
+ measurements: 'measurements'
22
+ )
23
+
24
+ def ver
25
+ @ver ||= 2
26
+ end
27
+
28
+ def properties
29
+ @properties ||= {}
30
+ end
31
+
32
+ def measurements
33
+ @measurements ||= {}
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,15 @@
1
+ require_relative 'json_serializable'
2
+
3
+ module ApplicationInsights::Channel::Contracts
4
+ class Session
5
+ include JsonSerializable
6
+
7
+ attr_accessor :id, :is_first, :is_new
8
+
9
+ attribute_mapping(
10
+ id: 'ai.session.id',
11
+ is_first: 'ai.session.isFirst',
12
+ is_new: 'ai.session.isNew'
13
+ )
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ module ApplicationInsights::Channel::Contracts
2
+ class SeverityLevel
3
+ VERBOSE = 0
4
+
5
+ INFORMATION = 1
6
+
7
+ WARNING = 2
8
+
9
+ ERROR = 3
10
+
11
+ CRITICAL = 4
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ require_relative 'json_serializable'
2
+
3
+ module ApplicationInsights::Channel::Contracts
4
+ class StackFrame
5
+ include JsonSerializable
6
+
7
+ attr_accessor :level, :method, :assembly, :file_name, :line
8
+
9
+ attribute_mapping(
10
+ level: 'level',
11
+ method: 'method',
12
+ assembly: 'assembly',
13
+ file_name: 'fileName',
14
+ line: 'line'
15
+ )
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ require_relative 'json_serializable'
2
+
3
+ module ApplicationInsights::Channel::Contracts
4
+ class User
5
+ include JsonSerializable
6
+
7
+ attr_accessor :account_acquisition_date, :account_id, :auth_user_id, :user_agent, :id,
8
+ :store_region
9
+
10
+ attribute_mapping(
11
+ account_acquisition_date: 'ai.user.accountAcquisitionDate',
12
+ account_id: 'ai.user.accountId',
13
+ user_agent: 'ai.user.userAgent',
14
+ id: 'ai.user.id',
15
+ auth_user_id: 'ai.user.authUserId',
16
+ store_region: 'ai.user.storeRegion'
17
+ )
18
+ end
19
+ end
@@ -0,0 +1,68 @@
1
+ require_relative 'queue_base'
2
+ require 'thread'
3
+
4
+ module ApplicationInsights
5
+ module Channel
6
+ # An event class that allows simple cross-thread signalling.
7
+ #
8
+ # An object of this type managers an internal flag that can be set to true
9
+ # via the {#set} method and reset via the {#clear} method. Calling the
10
+ # {#wait} method will block until the flag is set to true.
11
+ #
12
+ # @example
13
+ # require 'application_insights'
14
+ # require 'thread'
15
+ # event = ApplicationInsights::Channel::Event.new
16
+ # Thread.new do
17
+ # sleep 1
18
+ # event.set
19
+ # end
20
+ # puts 'Main screen turn on.'
21
+ # result = event.wait
22
+ # puts 'All your base are belong to us.'
23
+ class Event
24
+ # Initializes a new instance of the class.
25
+ def initialize
26
+ @mutex = Mutex.new
27
+ @condition_variable = ConditionVariable.new
28
+ @signal = false
29
+ end
30
+
31
+ # The signal value for this object. Note that the value of this property is
32
+ # not synchronized with respect to {#set} and {#clear} meaning that it
33
+ # could return false positives or negatives.
34
+ # @return [Boolean] the signal value.
35
+ attr_reader :signal
36
+
37
+ # Sets the internal flag to true. Calling this method will also cause all
38
+ # waiting threads to awaken.
39
+ def set
40
+ @mutex.synchronize do
41
+ @signal = true
42
+ @condition_variable.broadcast
43
+ end
44
+ end
45
+
46
+ # Sets the internal flag to false.
47
+ def clear
48
+ @mutex.synchronize do
49
+ @signal = false
50
+ end
51
+ end
52
+
53
+ # Calling this method will block until the internal flag is set to true.
54
+ # If the flag is set to true before calling this method, we will return
55
+ # immediately. If the timeout parameter is specified, the method will
56
+ # unblock after the specified number of seconds.
57
+ # @param [Fixnum] timeout the timeout for the operation in seconds.
58
+ # @return [Boolean] the value of the internal flag on exit.
59
+ def wait(timeout=nil)
60
+ @mutex.synchronize do
61
+ @condition_variable.wait(@mutex, timeout) unless @signal
62
+ end
63
+
64
+ @signal
65
+ end
66
+ end
67
+ end
68
+ end