Class: DRab::DRabConn

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

Constant Summary collapse

POOL_SIZE =
16

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(remote_uri) ⇒ DRabConn

Returns a new instance of DRabConn.



1083
1084
1085
1086
# File 'lib/drab/drab.rb', line 1083

def initialize(remote_uri)
  @uri = remote_uri
  @protocol = DRabProtocol.open(remote_uri, DRab.config)
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



1087
1088
1089
# File 'lib/drab/drab.rb', line 1087

def uri
  @uri
end

Class Method Details

.open(remote_uri) ⇒ Object



1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
# File 'lib/drab/drab.rb', line 1048

def self.open(remote_uri)
  begin
    conn = nil

    @mutex.synchronize do
      #FIXME
      new_pool = []
      @pool.each do |c|
        if conn.nil? and c.uri == remote_uri
          conn = c if c.alive?
        else
          new_pool.push c
        end
      end
      @pool = new_pool
    end

    conn = self.new(remote_uri) unless conn
    succ, result = yield(conn)
    return succ, result

  ensure
    if conn
      if succ
        @mutex.synchronize do
          @pool.unshift(conn)
          @pool.pop.close while @pool.size > POOL_SIZE
        end
      else
        conn.close
      end
    end
  end
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


1099
1100
1101
1102
# File 'lib/drab/drab.rb', line 1099

def alive?
  return false unless @protocol
  @protocol.alive?
end

#closeObject



1094
1095
1096
1097
# File 'lib/drab/drab.rb', line 1094

def close
  @protocol.close
  @protocol = nil
end

#send_message(ref, msg_id, arg, block) ⇒ Object



1089
1090
1091
1092
# File 'lib/drab/drab.rb', line 1089

def send_message(ref, msg_id, arg, block)
  @protocol.send_request(ref, msg_id, arg, block)
  @protocol.recv_reply
end