Class: Vertx::RecordParser

Inherits:
Object
  • Object
show all
Includes:
ReadStream
Defined in:
/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/record_parser.rb

Overview

A helper class which allows you to easily parse protocols which are delimited by a sequence of bytes, or fixed size records.

Instances of this class take as input Buffer instances containing raw bytes, and output records.

For example, if I had a simple ASCII text protocol delimited by '\n' and the input was the following:


 buffer1:HELLO\nHOW ARE Y
 buffer2:OU?\nI AM
 buffer3: DOING OK
 buffer4:\n
 
Then the output would be:


 buffer1:HELLO
 buffer2:HOW ARE YOU?
 buffer3:I AM DOING OK
 
Instances of this class can be changed between delimited mode and fixed size record mode on the fly as individual records are read, this allows you to parse protocols where, for example, the first 5 records might all be fixed size (of potentially different sizes), followed by some delimited records, followed by more fixed size records.

Instances of this class can't currently be used for protocols where the text is encoded with something other than a 1-1 byte-char mapping.

Please see the documentation for more information.

Constant Summary

@@j_api_type =
Object.new

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Boolean) accept?(obj)

Returns:

  • (Boolean)

50
51
52
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/record_parser.rb', line 50

def @@j_api_type.accept?(obj)
  obj.class == RecordParser
end

+ (Object) j_api_type


59
60
61
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/record_parser.rb', line 59

def self.j_api_type
  @@j_api_type
end

+ (Object) j_class


62
63
64
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/record_parser.rb', line 62

def self.j_class
  Java::IoVertxCoreParsetools::RecordParser.java_class
end

+ (::Vertx::RecordParser) newDelimited(delim) + (::Vertx::RecordParser) newDelimited(delim) + (::Vertx::RecordParser) newDelimited(delim, output) { ... } + (::Vertx::RecordParser) newDelimited(delim, stream) + (::Vertx::RecordParser) newDelimited(delim, output) { ... } + (::Vertx::RecordParser) newDelimited(delim, stream)

Like #new_delimited but wraps the stream. The stream handlers will be set/unset when the #handler is set.

The pause()/resume() operations are propagated to the stream.

Overloads:

Returns:

Raises:

  • (ArgumentError)

121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/record_parser.rb', line 121

def self.new_delimited(param_1=nil,param_2=nil)
  if param_1.class == String && !block_given? && param_2 == nil
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxCoreParsetools::RecordParser.java_method(:newDelimited, [Java::java.lang.String.java_class]).call(param_1),::Vertx::RecordParser)
  elsif param_1.class.method_defined?(:j_del) && !block_given? && param_2 == nil
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxCoreParsetools::RecordParser.java_method(:newDelimited, [Java::IoVertxCoreBuffer::Buffer.java_class]).call(param_1.j_del),::Vertx::RecordParser)
  elsif param_1.class == String && block_given? && param_2 == nil
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxCoreParsetools::RecordParser.java_method(:newDelimited, [Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(param_1,(Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::Buffer)) })),::Vertx::RecordParser)
  elsif param_1.class == String && param_2.class.method_defined?(:j_del) && !block_given?
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxCoreParsetools::RecordParser.java_method(:newDelimited, [Java::java.lang.String.java_class,Java::IoVertxCoreStreams::ReadStream.java_class]).call(param_1,param_2.j_del),::Vertx::RecordParser)
  elsif param_1.class.method_defined?(:j_del) && block_given? && param_2 == nil
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxCoreParsetools::RecordParser.java_method(:newDelimited, [Java::IoVertxCoreBuffer::Buffer.java_class,Java::IoVertxCore::Handler.java_class]).call(param_1.j_del,(Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::Buffer)) })),::Vertx::RecordParser)
  elsif param_1.class.method_defined?(:j_del) && param_2.class.method_defined?(:j_del) && !block_given?
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxCoreParsetools::RecordParser.java_method(:newDelimited, [Java::IoVertxCoreBuffer::Buffer.java_class,Java::IoVertxCoreStreams::ReadStream.java_class]).call(param_1.j_del,param_2.j_del),::Vertx::RecordParser)
  end
  raise ArgumentError, "Invalid arguments when calling new_delimited(#{param_1},#{param_2})"
end

+ (::Vertx::RecordParser) new_fixed(size = nil, stream = nil)

Like #new_fixed but wraps the stream. The stream handlers will be set/unset when the #handler is set.

The pause()/resume() operations are propagated to the stream.

Parameters:

  • size (Fixnum) (defaults to: nil)
    the initial record size
  • stream (::Vertx::ReadStream) (defaults to: nil)
    the wrapped stream

Returns:

Raises:

  • (ArgumentError)

144
145
146
147
148
149
150
151
152
153
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/record_parser.rb', line 144

def self.new_fixed(size=nil,stream=nil)
  if size.class == Fixnum && !block_given? && stream == nil
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxCoreParsetools::RecordParser.java_method(:newFixed, [Java::int.java_class]).call(size),::Vertx::RecordParser)
  elsif size.class == Fixnum && block_given? && stream == nil
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxCoreParsetools::RecordParser.java_method(:newFixed, [Java::int.java_class,Java::IoVertxCore::Handler.java_class]).call(size,(Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::Buffer)) })),::Vertx::RecordParser)
  elsif size.class == Fixnum && stream.class.method_defined?(:j_del) && !block_given?
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxCoreParsetools::RecordParser.java_method(:newFixed, [Java::int.java_class,Java::IoVertxCoreStreams::ReadStream.java_class]).call(size,stream.j_del),::Vertx::RecordParser)
  end
  raise ArgumentError, "Invalid arguments when calling new_fixed(#{size},#{stream})"
end

+ (Object) unwrap(obj)


56
57
58
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/record_parser.rb', line 56

def @@j_api_type.unwrap(obj)
  obj.j_del
end

+ (Object) wrap(obj)


53
54
55
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/record_parser.rb', line 53

def @@j_api_type.wrap(obj)
  RecordParser.new(obj)
end

Instance Method Details

- (void) delimitedMode(delim) - (void) delimitedMode(delim)

This method returns an undefined value.

Flip the parser into delimited mode, and where the delimiter can be represented by the delimiter delim.

This method can be called multiple times with different values of delim while data is being parsed.

Overloads:

  • - (void) delimitedMode(delim)

    Parameters:

    • delim (String)
      the new delimeter
  • - (void) delimitedMode(delim)

    Parameters:

Raises:

  • (ArgumentError)

163
164
165
166
167
168
169
170
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/record_parser.rb', line 163

def delimited_mode(param_1=nil)
  if param_1.class == String && !block_given?
    return @j_del.java_method(:delimitedMode, [Java::java.lang.String.java_class]).call(param_1)
  elsif param_1.class.method_defined?(:j_del) && !block_given?
    return @j_del.java_method(:delimitedMode, [Java::IoVertxCoreBuffer::Buffer.java_class]).call(param_1.j_del)
  end
  raise ArgumentError, "Invalid arguments when calling delimited_mode(#{param_1})"
end

- (self) end_handler { ... }

Yields:

Returns:

  • (self)

Raises:

  • (ArgumentError)

249
250
251
252
253
254
255
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/record_parser.rb', line 249

def end_handler
  if block_given?
    @j_del.java_method(:endHandler, [Java::IoVertxCore::Handler.java_class]).call(Proc.new { yield })
    return self
  end
  raise ArgumentError, "Invalid arguments when calling end_handler()"
end

- (self) exception_handler { ... }

Yields:

Returns:

  • (self)

Raises:

  • (ArgumentError)

206
207
208
209
210
211
212
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/record_parser.rb', line 206

def exception_handler
  if block_given?
    @j_del.java_method(:exceptionHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.from_throwable(event)) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling exception_handler()"
end

- (self) fetch(amount = nil)

Parameters:

  • amount (Fixnum) (defaults to: nil)

Returns:

  • (self)

Raises:

  • (ArgumentError)

232
233
234
235
236
237
238
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/record_parser.rb', line 232

def fetch(amount=nil)
  if amount.class == Fixnum && !block_given?
    @j_del.java_method(:fetch, [Java::long.java_class]).call(amount)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling fetch(#{amount})"
end

- (void) fixed_size_mode(size = nil)

This method returns an undefined value.

Flip the parser into fixed size mode, where the record size is specified by size in bytes.

This method can be called multiple times with different values of size while data is being parsed.

Parameters:

  • size (Fixnum) (defaults to: nil)
    the new record size

Raises:

  • (ArgumentError)

176
177
178
179
180
181
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/record_parser.rb', line 176

def fixed_size_mode(size=nil)
  if size.class == Fixnum && !block_given?
    return @j_del.java_method(:fixedSizeMode, [Java::int.java_class]).call(size)
  end
  raise ArgumentError, "Invalid arguments when calling fixed_size_mode(#{size})"
end

- (void) handle(buffer = nil)

This method returns an undefined value.

This method is called to provide the parser with data.

Parameters:

Raises:

  • (ArgumentError)

198
199
200
201
202
203
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/record_parser.rb', line 198

def handle(buffer=nil)
  if buffer.class.method_defined?(:j_del) && !block_given?
    return @j_del.java_method(:handle, [Java::IoVertxCoreBuffer::Buffer.java_class]).call(buffer.j_del)
  end
  raise ArgumentError, "Invalid arguments when calling handle(#{buffer})"
end

- (self) handler { ... }

Yields:

Returns:

  • (self)

Raises:

  • (ArgumentError)

215
216
217
218
219
220
221
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/record_parser.rb', line 215

def handler
  if block_given?
    @j_del.java_method(:handler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::Buffer)) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling handler()"
end

- (self) max_record_size(size = nil)

Set the maximum allowed size for a record when using the delimited mode. The delimiter itself does not count for the record size.

If a record is longer than specified, an IllegalStateException will be thrown.

Parameters:

  • size (Fixnum) (defaults to: nil)
    the maximum record size

Returns:

  • (self)

Raises:

  • (ArgumentError)

188
189
190
191
192
193
194
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/record_parser.rb', line 188

def max_record_size(size=nil)
  if size.class == Fixnum && !block_given?
    @j_del.java_method(:maxRecordSize, [Java::int.java_class]).call(size)
    return self
  end
  raise ArgumentError, "Invalid arguments when calling max_record_size(#{size})"
end

- (self) pause

Returns:

  • (self)

Raises:

  • (ArgumentError)

223
224
225
226
227
228
229
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/record_parser.rb', line 223

def pause
  if !block_given?
    @j_del.java_method(:pause, []).call()
    return self
  end
  raise ArgumentError, "Invalid arguments when calling pause()"
end

- (::Vertx::Pipe) pipe

Pause this stream and return a to transfer the elements of this stream to a destination .

The stream will be resumed when the pipe will be wired to a WriteStream.

Returns:

Raises:

  • (ArgumentError)

69
70
71
72
73
74
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/record_parser.rb', line 69

def pipe
  if !block_given?
    return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:pipe, []).call(),::Vertx::Pipe,::Vertx::Buffer.j_api_type)
  end
  raise ArgumentError, "Invalid arguments when calling pipe()"
end

- (void) pipe_to(dst = nil) { ... }

This method returns an undefined value.

Pipe this ReadStream to the WriteStream.

Elements emitted by this stream will be written to the write stream until this stream ends or fails.

Once this stream has ended or failed, the write stream will be ended and the handler will be called with the result.

Parameters:

Yields:

Raises:

  • (ArgumentError)

84
85
86
87
88
89
90
91
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/record_parser.rb', line 84

def pipe_to(dst=nil)
  if dst.class.method_defined?(:j_del) && !block_given?
    return @j_del.java_method(:pipeTo, [Java::IoVertxCoreStreams::WriteStream.java_class]).call(dst.j_del)
  elsif dst.class.method_defined?(:j_del) && block_given?
    return @j_del.java_method(:pipeTo, [Java::IoVertxCoreStreams::WriteStream.java_class,Java::IoVertxCore::Handler.java_class]).call(dst.j_del,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil) }))
  end
  raise ArgumentError, "Invalid arguments when calling pipe_to(#{dst})"
end

- (self) resume

Returns:

  • (self)

Raises:

  • (ArgumentError)

240
241
242
243
244
245
246
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/record_parser.rb', line 240

def resume
  if !block_given?
    @j_del.java_method(:resume, []).call()
    return self
  end
  raise ArgumentError, "Invalid arguments when calling resume()"
end

- (void) set_output { ... }

This method returns an undefined value.

Yields:

Raises:

  • (ArgumentError)

94
95
96
97
98
99
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx/record_parser.rb', line 94

def set_output
  if block_given?
    return @j_del.java_method(:setOutput, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::Vertx::Buffer)) }))
  end
  raise ArgumentError, "Invalid arguments when calling set_output()"
end