com.devexperts.qd.qtp.socket
Class ClientSocketConnector

java.lang.Object
  extended by com.devexperts.qd.qtp.AbstractMessageConnector
      extended by com.devexperts.qd.qtp.socket.ClientSocketConnector
All Implemented Interfaces:
MessageConnector, MessageConnectorMBean, ClientSocketConnectorMBean, SocketHandler.CloseListener

@MessageConnectorSummary(info="Connects to some host using TCP/IP client socket.",
                         addressFormat=":",
                         properties={})
public class ClientSocketConnector
extends AbstractMessageConnector
implements SocketHandler.CloseListener, ClientSocketConnectorMBean

The ClientSocketConnector handles standard client socket using blocking API.


Field Summary
protected  com.devexperts.qd.qtp.socket.SocketHandler handler
           
protected  java.lang.String host
           
protected  int port
           
protected  java.lang.String proxyHost
           
protected  int proxyPort
           
protected  com.devexperts.qd.qtp.socket.ClientSocketSource socketSource
           
protected  javax.net.ssl.TrustManager trustManager
           
protected  boolean useTls
           
 
Fields inherited from class com.devexperts.qd.qtp.AbstractMessageConnector
DEFAULT_READ_AGGREGATION_SIZE, DEFAULT_RECONNECT_DELAY, log
 
Constructor Summary
ClientSocketConnector(com.devexperts.connector.proto.ApplicationConnectionFactory factory, java.lang.String host, int port)
          Creates new client socket connector.
ClientSocketConnector(MessageAdapter.Factory factory, java.lang.String host, int port)
          Deprecated. use ClientSocketConnector(com.devexperts.connector.proto.ApplicationConnectionFactory, String, int)
 
Method Summary
 java.lang.String getAddress()
          Returns address string of this connector.
 int getConnectionCount()
          Returns number of established connections.
 java.lang.String getCurrentHost()
           
 int getCurrentPort()
           
 com.devexperts.transport.stats.EndpointStats getEndpointStats()
          Returns statistics for this message connector.
 java.lang.String getHost()
           
 int getPort()
           
 java.lang.String getProxyHost()
           
 int getProxyPort()
           
 MessageConnectorState getState()
          Returns message connector state.
 boolean getTls()
           
 javax.net.ssl.TrustManager getTrustManager()
           
 void handlerClosed(com.devexperts.qd.qtp.socket.SocketHandler handler)
           
 boolean isActive()
          Returns true if connector is started (not stopped).
 void setHost(java.lang.String host)
          Changes connection host string and restarts connector if new host string is different from the old one and the connector was running.
 void setPort(int port)
          Changes connection port and restarts connector if new port is different from the old one and the connector was running.
 void setProxyHost(java.lang.String proxyHost)
           
 void setProxyPort(int proxyPort)
           
 void setStats(QDStats stats)
          Sets stats for this connector.
 void setTls(boolean useTls)
           
 void setTrustManager(javax.net.ssl.TrustManager trustManager)
          Sets the custom trust manager to be used by SSLSocketFactory.
 void start()
          Starts connector (connection is immediately established).
 void stop()
          Stops connector (connection is immediately dropped).
 
Methods inherited from class com.devexperts.qd.qtp.AbstractMessageConnector
addClosedConnectionStats, addMessageConnectorListener, getFactory, getLogging, getName, getReconnectDelay, getStats, getThreadPriority, notifyMessageConnectorListeners, reconfigure, removeMessageConnectorListener, restart, setName, setReconnectDelay, setThreadPriority, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.devexperts.qd.qtp.MessageConnectorMBean
getName, getReconnectDelay, getThreadPriority, restart, setName, setReconnectDelay, setThreadPriority
 

Field Detail

host

protected java.lang.String host

port

protected int port

proxyHost

protected java.lang.String proxyHost

proxyPort

protected int proxyPort

useTls

protected boolean useTls

trustManager

protected javax.net.ssl.TrustManager trustManager

handler

protected volatile com.devexperts.qd.qtp.socket.SocketHandler handler

socketSource

protected com.devexperts.qd.qtp.socket.ClientSocketSource socketSource
Constructor Detail

ClientSocketConnector

@Deprecated
public ClientSocketConnector(MessageAdapter.Factory factory,
                                        java.lang.String host,
                                        int port)
Deprecated. use ClientSocketConnector(com.devexperts.connector.proto.ApplicationConnectionFactory, String, int)

Creates new client socket connector.

Parameters:
factory - message adapter factory to use
host - host to connect to
port - TCP port to connect to
Throws:
java.lang.NullPointerException - if factory or host is null

ClientSocketConnector

public ClientSocketConnector(com.devexperts.connector.proto.ApplicationConnectionFactory factory,
                             java.lang.String host,
                             int port)
Creates new client socket connector.

Parameters:
factory - application connection factory factory to use
host - host to connect to
port - TCP port to connect to
Throws:
java.lang.NullPointerException - if factory or host is null
Method Detail

getAddress

public java.lang.String getAddress()
Description copied from interface: MessageConnectorMBean
Returns address string of this connector. It is "[host1[:port1],host2[:port2],...]:port" for client socket connector and ":port" for server socket connector.

Specified by:
getAddress in interface MessageConnectorMBean
Returns:
address string of this connector

getHost

public java.lang.String getHost()
Specified by:
getHost in interface ClientSocketConnectorMBean

setHost

public void setHost(java.lang.String host)
Changes connection host string and restarts connector if new host string is different from the old one and the connector was running.

Specified by:
setHost in interface ClientSocketConnectorMBean

getPort

public int getPort()
Specified by:
getPort in interface ClientSocketConnectorMBean

setPort

public void setPort(int port)
Changes connection port and restarts connector if new port is different from the old one and the connector was running.

Specified by:
setPort in interface ClientSocketConnectorMBean

getProxyHost

public java.lang.String getProxyHost()
Specified by:
getProxyHost in interface ClientSocketConnectorMBean

setProxyHost

public void setProxyHost(java.lang.String proxyHost)
Specified by:
setProxyHost in interface ClientSocketConnectorMBean

getProxyPort

public int getProxyPort()
Specified by:
getProxyPort in interface ClientSocketConnectorMBean

setProxyPort

public void setProxyPort(int proxyPort)
Specified by:
setProxyPort in interface ClientSocketConnectorMBean

getTls

public boolean getTls()

setTls

public void setTls(boolean useTls)

getTrustManager

public javax.net.ssl.TrustManager getTrustManager()

setTrustManager

public void setTrustManager(javax.net.ssl.TrustManager trustManager)
Sets the custom trust manager to be used by SSLSocketFactory. This property has effect only when the connector is configured to use TLS.

Parameters:
trustManager - trust manager to use instead of the default one, or null in order to use default one.

setStats

public void setStats(QDStats stats)
Sets stats for this connector. Stats should be of type QDStats.SType#CLIENT_SOCKET_CONNECTOR or a suitable substitute. This method may be invoked only once.

Specified by:
setStats in interface MessageConnector
Overrides:
setStats in class AbstractMessageConnector
Throws:
java.lang.IllegalStateException - if already set.

isActive

public boolean isActive()
Description copied from interface: MessageConnectorMBean
Returns true if connector is started (not stopped).

Specified by:
isActive in interface MessageConnectorMBean
Returns:
true if connector is started (not stopped)

getState

public MessageConnectorState getState()
Description copied from interface: MessageConnectorMBean
Returns message connector state.

Specified by:
getState in interface MessageConnectorMBean
Specified by:
getState in interface ClientSocketConnectorMBean
Returns:
message connector state.

getConnectionCount

public int getConnectionCount()
Description copied from interface: MessageConnectorMBean
Returns number of established connections.

Specified by:
getConnectionCount in interface MessageConnectorMBean
Returns:
number of established connections

getEndpointStats

public com.devexperts.transport.stats.EndpointStats getEndpointStats()
Description copied from interface: MessageConnectorMBean
Returns statistics for this message connector.

Specified by:
getEndpointStats in interface MessageConnectorMBean
Overrides:
getEndpointStats in class AbstractMessageConnector
Returns:
statistics for this message connector

start

public void start()
Description copied from interface: MessageConnectorMBean
Starts connector (connection is immediately established). Does nothing if connector is already started.

Specified by:
start in interface MessageConnectorMBean
Specified by:
start in class AbstractMessageConnector

stop

public void stop()
Description copied from interface: MessageConnectorMBean
Stops connector (connection is immediately dropped). Does nothing if connector is stopped.

Specified by:
stop in interface MessageConnectorMBean
Specified by:
stop in class AbstractMessageConnector

handlerClosed

public void handlerClosed(com.devexperts.qd.qtp.socket.SocketHandler handler)
Specified by:
handlerClosed in interface SocketHandler.CloseListener

getCurrentHost

public java.lang.String getCurrentHost()
Specified by:
getCurrentHost in interface ClientSocketConnectorMBean

getCurrentPort

public int getCurrentPort()
Specified by:
getCurrentPort in interface ClientSocketConnectorMBean