public class BaseClient extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_CONNECT_TIMEOUT |
static int |
DEFAULT_SOCKET_TIMEOUT |
| Constructor and Description |
|---|
BaseClient()
Create a base client without establishing a connection.
|
BaseClient(String h,
int p)
Open up the service at the specified host and port, using a VinciFrame factory.
|
BaseClient(String h,
int p,
int connect_timeout)
Open up the service at the specified host and port, using a VinciFrame factory.
|
BaseClient(String h,
int p,
TransportableFactory f)
Open up the service at the specified host and port.
|
BaseClient(String h,
int p,
TransportableFactory f,
int timeout)
Open up the service at the specified host and port, using the specified connect timeout.
|
BaseClient(TransportableFactory f)
Create a base client without establishing a connection.
|
BaseClient(TransportableFactory f,
int timeout)
Create a base client without establishing a connection.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close the connection.
|
KeyValuePair |
getHeader()
Fetch the header of the last Transportable received.
|
String |
getHost()
Get the hostname/ip address to which this client is connected.
|
int |
getPort() |
protected Socket |
getSocket()
Get the socket used for the connection.
|
int |
getSocketTimeout()
Get the default timeout value for the socket (0 indicates never timeout, which is the default,
but generally NOT a good setting).
|
boolean |
isOpen() |
protected boolean |
isSocketKeepAliveEnabled()
Gets whether keepAlive should be turned on for client sockets.
|
void |
open()
(Re)connects the client to a previously specified host and port.
|
void |
open(Socket use_me)
Make this client use an already established socket connection.
|
protected void |
open(String h,
int p)
Connects the client to the specified host and port.
|
Transportable |
receive()
The other 1/2 of the split RPC.
|
protected void |
reopen(Exception e) |
VinciFrame |
rpc(Transportable query)
Same as sendAndReceive(Transportable) except for return type.
|
VinciFrame |
rpc(Transportable query,
int timeout)
Same as sendAndReceive(Transportable, timeout) except for return type.
|
static VinciFrame |
rpc(Transportable in,
String host_name,
int p)
Convenience method for "one-shot" or "single-query" connections.
|
static VinciFrame |
rpc(Transportable in,
String host_name,
int p,
int socket_timeout)
Convenience method for "one-shot" or "single-query" connections.
|
static VinciFrame |
rpc(Transportable in,
String host_name,
int p,
int socket_timeout,
int connect_timeout)
Convenience method for "one-shot" or "single-query" connections.
|
void |
send(Transportable in)
Support for 1/2 transaction RPC.
|
Transportable |
sendAndReceive(Transportable in)
Takes a transportable object, sends it across the connection, then retrieves the response and
returns it.
|
Transportable |
sendAndReceive(Transportable in,
int timeout)
Takes a transportable object, sends it across the connection, then retrieves the response and
returns it.
|
static Transportable |
sendAndReceive(Transportable in,
String host_name,
int p,
TransportableFactory f)
Convenience method for "one-shot" or "single-query" connections.
|
static Transportable |
sendAndReceive(Transportable in,
String host_name,
int p,
TransportableFactory f,
int socket_timeout)
Convenience method for "one-shot" or "single-query" connections with socket timeout support.
|
static Transportable |
sendAndReceive(Transportable in,
String host_name,
int p,
TransportableFactory f,
int socket_timeout,
int connect_timeout)
Convenience method for "one-shot" or "single-query" connections with socket timeout support
& connect timeout support.
|
Transportable |
sendAndReceive(Transportable in,
TransportableFactory f)
Same as sendAndReceive(Transportable) except the provided factory is used to create the return
document in place of the default factory.
|
Transportable |
sendAndReceive(Transportable in,
TransportableFactory f,
int timeout)
Same as sendAndReceive(Transportable, timeout) except the provided factory is used to create
the return document in place of the default factory.
|
protected Transportable |
sendAndReceiveWork(Transportable in,
TransportableFactory f) |
protected Transportable |
sendAndReceiveWork(Transportable in,
TransportableFactory f,
int timeout) |
void |
setConnectTimeout(int timeout)
Set the timeout value used for connect timeouts.
|
void |
setRetry(boolean to)
Set connection restablishment on IOException to on/off, default is ON.
|
void |
setSocketTimeout(int millis)
Set the timeout value used by the underlying socket.
|
void |
setTransportableFactory(TransportableFactory f)
Set the transportable factory used by this client.
|
public static final int DEFAULT_SOCKET_TIMEOUT
public static final int DEFAULT_CONNECT_TIMEOUT
public BaseClient(String h, int p) throws IOException
h - The hostname/ip address of the machine running the service.p - The port on which the service runs.IOException - if the underlying socket fails to connectpublic BaseClient(String h, int p, int connect_timeout) throws IOException
h - The hostname/ip address of the machine running the service.p - The port on which the service runs.connect_timeout - The number of milliseconds that will elapse before a connect attempt fails.IOException - if the underlying socket fails to connectpublic BaseClient(String h, int p, TransportableFactory f) throws IOException
h - The hostname/ip address of the machine running the service.p - The port on which the service runs.f - A factory for creating documents of the desired type.IOException - if the underlying socket fails to connect.public BaseClient(String h, int p, TransportableFactory f, int timeout) throws IOException
h - The hostname/ip address of the machine running the service.p - The port on which the service runs.f - A factory for creating documents of the desired type.timeout - The number of milliseconds that will elapse before a connect attempt fails.IOException - if the underlying socket fails to connect.public BaseClient()
public BaseClient(TransportableFactory f)
f - A factory for creating documents of the desired type.public BaseClient(TransportableFactory f, int timeout)
f - A factory for creating documents of the desired type.timeout - The number of milliseconds that will elapse before a connect attempt fails.public String getHost()
public int getPort()
protected Socket getSocket()
public int getSocketTimeout()
public void setConnectTimeout(int timeout)
timeout - The number of milliseconds that will elapse before a connect attempt fails.public void setTransportableFactory(TransportableFactory f)
f - -public Transportable sendAndReceive(Transportable in) throws IOException, ServiceException
in - The query frame.IOException - thrown by the underlying socket IO (e.g. due to connection timeout).ServiceException - thrown if the server threw ServiceException or returned an ErrorFrame.public Transportable sendAndReceive(Transportable in, int timeout) throws IOException, ServiceException
in - The query frame.timeout - The timeout value to use in place of this client's default timeout setting.IOException - thrown by the underlying socket IO (e.g. due to connection timeout).ServiceException - thrown if the server threw ServiceException or returned an ErrorFrame.public Transportable sendAndReceive(Transportable in, TransportableFactory f) throws IOException, ServiceException
in - -f - The factory to used to create the return document.IOException - -ServiceException - -public Transportable sendAndReceive(Transportable in, TransportableFactory f, int timeout) throws IOException, ServiceException
in - -f - The factory to used to create the return document.timeout - -IOException - -ServiceException - -public VinciFrame rpc(Transportable query) throws IOException, ServiceException
query - -IOException - -ServiceException - -public VinciFrame rpc(Transportable query, int timeout) throws IOException, ServiceException
query - -timeout - -IOException - -ServiceException - -public void send(Transportable in) throws IOException
in - The Transportable to send.IOException - Thrown by the underlying transport layer.public Transportable receive() throws IOException, ServiceException
IOException - Thrown by the underlying transport layer, or the socket is closed.ServiceException - Thrown if the remote server responded with an error frame.public void close()
public boolean isOpen()
public void setRetry(boolean to)
to - -public KeyValuePair getHeader()
public static Transportable sendAndReceive(Transportable in, String host_name, int p, TransportableFactory f) throws IOException, ServiceException
in - -host_name - -p - -f - -IOException - -ServiceException - -public static Transportable sendAndReceive(Transportable in, String host_name, int p, TransportableFactory f, int socket_timeout) throws IOException, ServiceException
in - -host_name - -p - -f - -socket_timeout - -IOException - -ServiceException - -public static Transportable sendAndReceive(Transportable in, String host_name, int p, TransportableFactory f, int socket_timeout, int connect_timeout) throws IOException, ServiceException
in - -host_name - -p - -f - -socket_timeout - -connect_timeout - -IOException - -ServiceException - -public static VinciFrame rpc(Transportable in, String host_name, int p) throws IOException, ServiceException
in - -host_name - -p - -IOException - -ServiceException - -public static VinciFrame rpc(Transportable in, String host_name, int p, int socket_timeout) throws IOException, ServiceException
in - -host_name - -p - -socket_timeout - -IOException - -ServiceException - -public static VinciFrame rpc(Transportable in, String host_name, int p, int socket_timeout, int connect_timeout) throws IOException, ServiceException
in - -host_name - -p - -socket_timeout - -connect_timeout - -IOException - -ServiceException - -protected Transportable sendAndReceiveWork(Transportable in, TransportableFactory f) throws IOException, ServiceException
in - -f - -IOException - -ServiceException - -protected Transportable sendAndReceiveWork(Transportable in, TransportableFactory f, int timeout) throws IOException, ServiceException
in - -f - -timeout - -IOException - -ServiceException - -protected void reopen(Exception e) throws IOException
e - -IOException - -protected final void open(String h, int p) throws IOException
h - The hostname/ip address of the server to connect to.p - The port to connect to.IOException - Thrown by underlying Socket open() call.public final void open()
throws IOException
IOException - Thrown by underlying Socket open() call.public void open(Socket use_me) throws IOException
use_me - The socket to use.IOException - Thrown by underlying Socket open() call.public void setSocketTimeout(int millis)
throws IOException
millis - -IOException - -protected boolean isSocketKeepAliveEnabled()
Copyright © 2018. All rights reserved.