com.continuent.tungsten.common.cluster.resource
Class RouterURL

java.lang.Object
  extended by com.continuent.tungsten.common.cluster.resource.RouterURL
All Implemented Interfaces:
java.lang.Cloneable

public class RouterURL
extends java.lang.Object
implements java.lang.Cloneable

Implements a simple parser for SQLRouter URLs. It identifies and strips out t-router properties

Version:
1.0
Author:
Edward Archibald

Field Summary
static java.lang.String DBNAME_TOKEN
          Special tag to be replaced by a database name dynamically
static java.lang.String KEY_AFFINITY
           
static java.lang.String KEY_MAX_APPLIED_LATENCY
           
static java.lang.String KEY_PASSWORD
           
static java.lang.String KEY_QOS
           
static java.lang.String KEY_SESSION_ID
           
static java.lang.String KEY_USER
           
static double MAX_APPLIED_LATENCY_UNDEF
           
static java.lang.String SESSIONID_CONNECTION
           
static java.lang.String SESSIONID_DATABASE
           
static java.lang.String SESSIONID_PROVIDED_IN_DBNAME
           
static java.lang.String SESSIONID_USER
           
static java.lang.String URL_FULL_HEADER
           
 
Constructor Summary
RouterURL(java.lang.String url, java.util.Properties info)
          Creates a parsed URL object.
Valid driver URLs are: jdbc:t-router://service/ [?][qos={RW_STRICT|RW_RELAXED|RO_STRICT|RO_RELAXED}] [?|&][otheroptions=value...]
The default qos (Quality of service) is RW_STRICT unless specified or unless overridden by the service configuration.
Properties passed via the URL supersede the ones in the properties.
 
Method Summary
 java.lang.Object clone()
           
 boolean equals(java.lang.Object obj)
           
 java.lang.String getAffinity()
           
 java.lang.String getDataServiceName()
          Returns the dataServiceName value.
 java.lang.String getDbname()
           
 double getMaxAppliedLatency()
           
 java.util.Properties getObfuscatedPasswordPropsCopy()
           
 java.lang.String getProperty(java.lang.String key)
          Provides the property with the given key from the parsed and passed URL props.
 java.util.Properties getProps()
           
 QualityOfService getQos()
           
 java.lang.String getService()
           
 java.lang.String getSessionId()
           
 boolean isAutoSession()
           
 void parseURLOptions(java.lang.String substring)
           
 void setAffinity(java.lang.String affinityParam)
           
 void setDbname(java.lang.String dbname)
          Changes the database name.
 void setMaxAppliedLatency(double maxAppliedLatencyPrm)
           
 void setProperties(java.lang.String propsStr)
           
 void setQoS(QualityOfService qosParam)
           
 void setSessionId(java.lang.String newSessionId)
          Upon catalog change, it can be required to change the session ID
 java.lang.String toString()
           
 void transferPropertiesToRouterURLMemberVariables(java.util.Properties propsArg)
           
protected  void transferRouterPropertiesToMemberVariables()
          Iterates through all properties and removes the ones that are router- specific.
static void urlOptionsToProperties(java.lang.String urlOptions, java.util.Properties p)
          Given a string of URL options (eg.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

URL_FULL_HEADER

public static final java.lang.String URL_FULL_HEADER
See Also:
Constant Field Values

KEY_MAX_APPLIED_LATENCY

public static final java.lang.String KEY_MAX_APPLIED_LATENCY
See Also:
Constant Field Values

KEY_QOS

public static final java.lang.String KEY_QOS
See Also:
Constant Field Values

KEY_SESSION_ID

public static final java.lang.String KEY_SESSION_ID
See Also:
Constant Field Values

KEY_AFFINITY

public static final java.lang.String KEY_AFFINITY
See Also:
Constant Field Values

KEY_USER

public static final java.lang.String KEY_USER
See Also:
Constant Field Values

KEY_PASSWORD

public static final java.lang.String KEY_PASSWORD
See Also:
Constant Field Values

SESSIONID_CONNECTION

public static final java.lang.String SESSIONID_CONNECTION
See Also:
Constant Field Values

SESSIONID_DATABASE

public static final java.lang.String SESSIONID_DATABASE
See Also:
Constant Field Values

SESSIONID_USER

public static final java.lang.String SESSIONID_USER
See Also:
Constant Field Values

SESSIONID_PROVIDED_IN_DBNAME

public static final java.lang.String SESSIONID_PROVIDED_IN_DBNAME
See Also:
Constant Field Values

DBNAME_TOKEN

public static final java.lang.String DBNAME_TOKEN
Special tag to be replaced by a database name dynamically

See Also:
Constant Field Values

MAX_APPLIED_LATENCY_UNDEF

public static double MAX_APPLIED_LATENCY_UNDEF
Constructor Detail

RouterURL

public RouterURL(java.lang.String url,
                 java.util.Properties info)
          throws java.sql.SQLException
Creates a parsed URL object.
Valid driver URLs are: jdbc:t-router://service/ [?][qos={RW_STRICT|RW_RELAXED|RO_STRICT|RO_RELAXED}] [?|&][otheroptions=value...]
The default qos (Quality of service) is RW_STRICT unless specified or unless overridden by the service configuration.
Properties passed via the URL supersede the ones in the properties. Last property defined in the URL wins.

Parameters:
url - SQL router URL
info - Properties for URL
Throws:
java.sql.SQLException - if the URL cannot be parsed or misses the data service name or database name
Method Detail

parseURLOptions

public void parseURLOptions(java.lang.String substring)
                     throws java.sql.SQLException
Throws:
java.sql.SQLException

urlOptionsToProperties

public static void urlOptionsToProperties(java.lang.String urlOptions,
                                          java.util.Properties p)
                                   throws java.sql.SQLException
Given a string of URL options (eg. affinity=blah&maxAppliedLatency=2), extracts each option and add them to the given Properties parameter TODO: urlOptionsToProperties definition.

Parameters:
urlOptions - string to parse
p - output properties to which options will be added, overwriting them if already in
Throws:
java.sql.SQLException - in case of parsing error

transferRouterPropertiesToMemberVariables

protected void transferRouterPropertiesToMemberVariables()
                                                  throws java.sql.SQLException
Iterates through all properties and removes the ones that are router- specific. Sets the member variables with these values

Throws:
java.sql.SQLException - upon illegal values

transferPropertiesToRouterURLMemberVariables

public void transferPropertiesToRouterURLMemberVariables(java.util.Properties propsArg)
                                                  throws java.sql.SQLException
Throws:
java.sql.SQLException

setProperties

public void setProperties(java.lang.String propsStr)
                   throws java.sql.SQLException
Throws:
java.sql.SQLException

getDataServiceName

public java.lang.String getDataServiceName()
Returns the dataServiceName value.

Returns:
Returns the dataServiceName.

setDbname

public void setDbname(java.lang.String dbname)
Changes the database name. This triggers a replacement of the database name in the URL string as well

Parameters:
dbname - The dbname to set.

getMaxAppliedLatency

public double getMaxAppliedLatency()

setMaxAppliedLatency

public void setMaxAppliedLatency(double maxAppliedLatencyPrm)

setSessionId

public void setSessionId(java.lang.String newSessionId)
Upon catalog change, it can be required to change the session ID

Parameters:
newSessionId -

getSessionId

public java.lang.String getSessionId()

getService

public java.lang.String getService()

getDbname

public java.lang.String getDbname()

getProps

public java.util.Properties getProps()

getQos

public QualityOfService getQos()

setQoS

public void setQoS(QualityOfService qosParam)

getAffinity

public java.lang.String getAffinity()

setAffinity

public void setAffinity(java.lang.String affinityParam)

getProperty

public java.lang.String getProperty(java.lang.String key)
Provides the property with the given key from the parsed and passed URL props. If the property is not set, returns null

Parameters:
key - the property key to retrieve
Returns:
the given property or null if no such property exists

getObfuscatedPasswordPropsCopy

public java.util.Properties getObfuscatedPasswordPropsCopy()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

isAutoSession

public boolean isAutoSession()

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException