class T2Server::ConnectionFactory

This is a factory for connections to a Taverna Server. It will return either a http or https connection depending on what sort of uri is passed into it. This class maintains a list of connections that it knows about and will return an already established connection if it can.

Public Class Methods

connect(uri) → Connection click to toggle source

Connect to a Taverna Server instance and return either a T2Server::HttpConnection or T2Server::HttpsConnection object to represent it.

   # File lib/t2-server/net/connection.rb
55 def ConnectionFactory.connect(uri, params = nil)
56   # we want to use URIs here
57   if !uri.is_a? URI
58     raise URI::InvalidURIError.new
59   end
60 
61   # if we're given params they must be of the right type
62   if !params.nil? && !params.is_a?(ConnectionParameters)
63     raise ArgumentError, "Parameters must be ConnectionParameters", caller
64   end
65 
66   # see if we've already got this connection
67   conn = @@connections.find {|c| c.uri == uri}
68 
69   if !conn
70     if uri.scheme == "http"
71       conn = HttpConnection.new(uri, params)
72     elsif uri.scheme == "https"
73       conn = HttpsConnection.new(uri, params)
74     else
75       raise URI::InvalidURIError.new
76     end
77 
78     @@connections << conn
79   end
80 
81   conn
82 end