Class: T2Server::ConnectionFactory
- Inherits:
-
Object
- Object
- T2Server::ConnectionFactory
- Defined in:
- lib/t2-server/net/connection.rb
Overview
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.
Constant Summary collapse
- @@connections =
list of connections we know about
[]
Class Method Summary collapse
-
.connect(uri, params = nil) ⇒ Object
:call-seq: ConnectionFactory.connect(uri) -> Connection.
Class Method Details
.connect(uri, params = nil) ⇒ Object
:call-seq:
ConnectionFactory.connect(uri) -> Connection
Connect to a Taverna Server instance and return either a T2Server::HttpConnection or T2Server::HttpsConnection object to represent it.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/t2-server/net/connection.rb', line 55 def ConnectionFactory.connect(uri, params = nil) # we want to use URIs here if !uri.is_a? URI raise URI::InvalidURIError.new end # if we're given params they must be of the right type if !params.nil? && !params.is_a?(ConnectionParameters) raise ArgumentError, "Parameters must be ConnectionParameters", caller end # see if we've already got this connection conn = @@connections.find {|c| c.uri == uri} if !conn if uri.scheme == "http" conn = HttpConnection.new(uri, params) elsif uri.scheme == "https" conn = HttpsConnection.new(uri, params) else raise URI::InvalidURIError.new end @@connections << conn end conn end |