Class: RDFbus::Transport Abstract

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

Overview

This class is abstract.

An RDFbus transport protocol.

Direct Known Subclasses

AMQP::Transport

Instance Attribute Summary

Class Method Summary

Instance Method Summary

Constructor Details

- (Transport) initialize(url, options = {})

Initializes this transport.

Parameters:

  • (RDF::URI, #to_s) url
  • (Hash{Symbol => Object}) options (defaults to: {})


50
51
52
53
54
55
56
# File 'lib/rdfbus/transport.rb', line 50

def initialize(url, options = {})
  @url = case url
    when RDF::URI then url
    else RDF::URI.new(url.to_s)
  end
  open
end

Instance Attribute Details

- (RDF::URI) url (readonly)

The transport endpoint's URL.

Returns:

  • (RDF::URI)


11
12
13
# File 'lib/rdfbus/transport.rb', line 11

def url
  @url
end

Class Method Details

+ (Class) for(protocol)

Returns the implementation class for the given transport name.

Parameters:

  • (Symbol) protocol

Returns:

  • (Class)


18
19
20
21
22
# File 'lib/rdfbus/transport.rb', line 18

def self.for(protocol)
  case protocol.to_s.to_sym
    when :amqp then RDFbus::AMQP::Transport
  end
end

+ (Transport) open(url, options = {}) {|transport| ... }

Open a connection to a transport endpoint.

Parameters:

  • (RDF::URI) url
  • (Hash{Symbol => Object}) options (defaults to: {})

Yields:

  • (transport)

Yield Parameters:

Returns:



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rdfbus/transport.rb', line 32

def self.open(url, options = {}, &block)
  protocol  = :amqp # FIXME
  transport = self.for(protocol).new(url, options)

  if !block_given?
    transport
  else
    result = block.call(transport)
    transport.close
    result
  end
end

Instance Method Details

- close

This method is abstract.

This method returns an undefined value.

Closes the connection to the transport endpoint.



70
# File 'lib/rdfbus/transport.rb', line 70

def close() end

- (String) inspect

Returns a developer-friendly representation of this object.

Returns:

  • (String)


101
102
103
# File 'lib/rdfbus/transport.rb', line 101

def inspect
  sprintf("#<%s:%#0x(%s)>", self.class.name, object_id, url.to_s)
end

- inspect!

This method returns an undefined value.

Outputs a developer-friendly representation of this object to stderr.



109
110
111
# File 'lib/rdfbus/transport.rb', line 109

def inspect!
  warn(inspect)
end

- open

This method is abstract.

This method returns an undefined value.

Opens a connection to the transport endpoint.



63
# File 'lib/rdfbus/transport.rb', line 63

def open() end

- publish(payload, options = {})

This method is abstract.

This method returns an undefined value.

Transmits a transaction over the transport connection.

Parameters:

  • (Transaction) payload
  • (Hash{Symbol => Object}) options (defaults to: {})

Raises:

  • (NotImplementedError)

    unless implemented in subclass



80
81
82
# File 'lib/rdfbus/transport.rb', line 80

def publish(payload, options = {})
  raise NotImplementedError.new("#{self.class}#publish is not implemented yet")
end

- subscribe(options = {}) {|payload| ... }

This method is abstract.

This method returns an undefined value.

Receives transactions over the transport connection.

Parameters:

  • (Hash{Symbol => Object}) options (defaults to: {})

Yields:

  • (payload)

Yield Parameters:

Raises:

  • (NotImplementedError)

    unless implemented in subclass



93
94
95
# File 'lib/rdfbus/transport.rb', line 93

def (options = {}, &block)
  raise NotImplementedError.new("#{self.class}#subscribe is not implemented yet")
end