Class: Farcall::Provider

Inherits:
Object
  • Object
show all
Defined in:
lib/farcall/endpoint.rb

Overview

Could be used as a base class to export its methods to the remote. You are not limited to subclassing, instead, you can set any class instance as a provider setting it to the Farcall::Endpoint#provider. The provider has only one method^ which can not be accessed remotely: #far_interface, which is used locally to object interface to call remote methods for two-way connections.

Direct Known Subclasses

EmFarcall::Provider

Instance Method Summary collapse

Constructor Details

#initialize(endpoint: nil, transport: nil, **params) ⇒ Provider

Create an instance connected to the Farcall::Transport or Farcall::Endpoint - use what suites you better.

Please remember that Farcall::Transport instance could be used with only one connected object, unlike Farcall::Endpoint, which could be connected to several consumers.

Parameters:

  • endpoint (Farcall::Endpoint) (defaults to: nil)

    to connect to (no transport should be provided). note that if endpoint is specified, transport would be ignored eeven if used

  • transport (Farcall::Transport) (defaults to: nil)

    to use (don’t use endpoint then)



265
266
267
268
269
270
271
272
273
274
275
# File 'lib/farcall/endpoint.rb', line 265

def initialize endpoint: nil, transport: nil, **params
  if endpoint || transport || params.size > 0
    @endpoint          = if endpoint
                           endpoint
                         else
                           transport ||= Farcall::Transport.create **params
                           Farcall::Endpoint.new transport
                         end
    @endpoint.provider = self
  end
end

Instance Method Details

#close_connectionObject

close connection if need



288
289
290
# File 'lib/farcall/endpoint.rb', line 288

def close_connection
  @endpoint.close
end

#far_interfaceFarcall::Interface

Get remote interface like to call other party’s methiod, it can do it cimply by:

far_interface.some_method('hello')

Returns:



283
284
285
# File 'lib/farcall/endpoint.rb', line 283

def far_interface
  @endpoint.remote
end