def continue_transaction(txn_id, group_name, category, key)
if !@server_address
return Transaction.new(nil, nil)
elsif !txn_id || txn_id.empty?
raise ArgumentError, 'Transaction ID may not be empty'
end
Lock.new(@mutex).synchronize do |_lock|
if Time.now < @next_reconnect_time
return Transaction.new(nil, nil)
end
Lock.new(@connection.mutex).synchronize do |connection_lock|
if !@connection.connected?
begin
connect
connection_lock.reset(@connection.mutex)
rescue SystemCallError, IOError
@connection.disconnect
UnionStationHooks::Log.warn(
"Cannot connect to the UstRouter at #{@server_address}; " \
"retrying in #{@reconnect_timeout} second(s).")
@next_reconnect_time = Time.now + @reconnect_timeout
return Transaction.new(nil, nil)
rescue Exception => e
@connection.disconnect
raise e
end
end
begin
@connection.channel.write('openTransaction',
txn_id, group_name, '', category,
Utils.encoded_timestamp,
key,
true)
return Transaction.new(@connection, txn_id)
rescue SystemCallError, IOError
@connection.disconnect
UnionStationHooks::Log.warn(
"The UstRouter at #{@server_address}" \
' closed the connection; will reconnect in ' \
"#{@reconnect_timeout} second(s).")
@next_reconnect_time = Time.now + @reconnect_timeout
return Transaction.new(nil, nil)
rescue Exception => e
@connection.disconnect
raise e
end
end
end
end