Class: OMQ::Ractor::MarshalConnection

Inherits:
SimpleDelegator
  • Object
show all
Includes:
TransparentDelegator
Defined in:
lib/omq/ractor.rb

Overview

Wraps a tcp/ipc Connection with transparent Marshal serialization. Serializes/deserializes the entire parts array.

Instance Method Summary collapse

Methods included from TransparentDelegator

#is_a?

Constructor Details

#initialize(conn, cache) ⇒ MarshalConnection

Returns a new instance of MarshalConnection.

Parameters:

  • conn (Object)

    underlying connection to wrap

  • cache (SerializeCache)

    shared serialization cache



90
91
92
93
# File 'lib/omq/ractor.rb', line 90

def initialize(conn, cache)
  super(conn)
  @cache = cache
end

Instance Method Details

#receive_messageObject

Returns deserialized message.

Returns:

  • (Object)

    deserialized message



118
119
120
# File 'lib/omq/ractor.rb', line 118

def receive_message
  Marshal.load(super.first)
end

#send_message(parts) ⇒ void

This method returns an undefined value.

Parameters:

  • parts (Array<String>)

    message frames to serialize and send



98
99
100
# File 'lib/omq/ractor.rb', line 98

def send_message(parts)
  super([@cache.marshal(parts)])
end

#write_message(parts) ⇒ void

This method returns an undefined value.

Parameters:

  • parts (Array<String>)

    message frames to serialize and write



105
106
107
# File 'lib/omq/ractor.rb', line 105

def write_message(parts)
  super([@cache.marshal(parts)])
end

#write_messages(batch) ⇒ void

This method returns an undefined value.

Parameters:

  • batch (Array<Array<String>>)

    batch of message frames to serialize and write



112
113
114
# File 'lib/omq/ractor.rb', line 112

def write_messages(batch)
  super(batch.map { |parts| [@cache.marshal(parts)] })
end