java.lang.Object
com.aoindustries.aoserv.client.AoservConnector
- All Implemented Interfaces:
SchemaParent
- Direct Known Subclasses:
TcpConnector
An
AoservConnector
provides the connection between the object
layer and the data. This connection may be persistent over TCP sockets, or
it may be request-based like HTTP.- Author:
- AO Industries, Inc.
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
static interface
This is the preferred mechanism for providing custom requests that have a return value.static interface
This is the preferred mechanism for providing custom requests.static class
An update request with a returned invalidation list. -
Field Summary
Modifier and TypeFieldDescriptionprotected Identifier
protected final AoservConnector.IdLock
static final long
The maximum size of the master entropy pool in bytes.protected final String
-
Constructor Summary
ModifierConstructorDescriptionprotected
AoservConnector
(HostAddress hostname, InetAddress localIp, Port port, User.Name connectAs, User.Name authenticateAs, String password, DomainName daemonServer) -
Method Summary
Modifier and TypeMethodDescriptionlong
addMasterEntropy
(byte[] buff, int numBytes) Adds some entropy to the master server.void
Clears all caches used by this connector.final boolean
Uses equivalence equality likeObject.equals(java.lang.Object)
.executeCommand
(String[] args) Executes an aosh command and captures its output into aString
.getAosh()
protected abstract AoservConnection
getConnection
(int maxConnections) Allocates a connection to the server.static AoservConnector
Gets the defaultAoservConnector
as defined in thecom/aoindustries/aoserv/client/aoserv-client.properties
resource.static AoservConnector
getConnector
(User.Name connectAs, User.Name authenticateAs, String password, DomainName daemonServer) Gets theAoservConnector
with the provided authentication information.static AoservConnector
getConnector
(User.Name username, String password) Gets theAoservConnector
with the provided authentication information.final Identifier
Each connector is assigned a unique identifier, which the server uses to not send events originating from this connector back to connections of this connector.final Administrator
Gets theAdministrator
who is logged in using thisAoservConnector
.getDns()
getEmail()
static Random
A fast pseudo-random number generator for non-cryptographic purposes.getFtp()
final HostAddress
Gets the hostname of the server that is connected to.getLinux()
final InetAddress
Gets the optional local IP address that connections are made from.protected final Logger
Gets the logger for this connector.int
getMasterEntropy
(byte[] buff, int numBytes) Gets some entropy from the master server, returns the number of bytes actually obtained.long
Gets the amount of entropy needed by the master server in bytes.getMysql()
getNet()
getPki()
final Port
getPort()
Gets the server port that is connected to.abstract String
Gets the communication protocol being used.Gets an unmodifiable list of all of the top-level schemas in the system.getScm()
static SecureRandom
A single random number generator is shared by all connector resources.final AoservTable
<?, ?> getTable
(int tableId) Each table has a unique ID, as found inSchemaTable
.final List
<? extends AoservTable<?, ?>> Gets an unmodifiable list of all of the tables in the system.getWeb()
final int
hashCode()
Uses equivalence hashCode likeObject.hashCode()
.void
invalidateTable
(int tableId, int server) Manually invalidates the system caches.abstract boolean
isSecure()
Determines if the connections made by this protocol are secure.final int
ping()
Times how long it takes to make one request with the server.abstract void
printConnectionStatsHtml
(Appendable out, boolean isXhtml) static IntList
protected abstract void
release
(AoservConnection connection) Releases a connection to the server.final void
removeFromAllTables
(TableListener listener) final boolean
requestBooleanQuery
(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) final boolean
requestBooleanQueryInvalidating
(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) final int
requestIntQuery
(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) final int
requestIntQueryInvalidating
(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) final long
requestLongQuery
(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) final String
requestLongStringQuery
(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) Performs a query returning a String of any length (not limited to size <= 64k like requestStringQuery).final String
requestNullLongStringQuery
(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) Performs a query returning a String of any length (not limited to size <= 64k like requestStringQuery) ornull
.final <T> T
requestResult
(boolean allowRetry, AoservProtocol.CommandId commandId, AoservConnector.ResultRequest<T> resultRequest) final short
requestShortQuery
(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) final short
requestShortQueryInvalidating
(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) final String
requestStringQuery
(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) final void
requestUpdate
(boolean allowRetry, AoservProtocol.CommandId commandId, AoservConnector.UpdateRequest updateRequest) final void
requestUpdate
(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) final void
requestUpdateInvalidating
(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) <K,
T extends AoservObject<K, T>>
voidsort
(ComparisonSortAlgorithm<? super T> sortAlgorithm, List<T> list, SqlExpression[] sortExpressions, boolean[] sortOrders) <K,
T extends AoservObject<K, T>>
voidsort
(ComparisonSortAlgorithm<? super T> sortAlgorithm, T[] list, SqlExpression[] sortExpressions, boolean[] sortOrders) abstract AoservConnector
switchUsers
(User.Name username) final void
tablesUpdated
(IntList invalidateList) final void
Tests the connectivity to the server.final String
toString()
-
Field Details
-
MASTER_ENTROPY_POOL_SIZE
public static final long MASTER_ENTROPY_POOL_SIZEThe maximum size of the master entropy pool in bytes.- See Also:
-
idLock
-
id
-
password
-
-
Constructor Details
-
AoservConnector
protected AoservConnector(HostAddress hostname, InetAddress localIp, Port port, User.Name connectAs, User.Name authenticateAs, String password, DomainName daemonServer)
-
-
Method Details
-
getAccount
-
getAccounting
-
getAosh
-
getBackup
-
getBilling
-
getDistribution
-
getDistribution_management
-
getDns
-
getEmail
-
getFtp
-
getInfrastructure
-
getLinux
-
getMaster
-
getMysql
-
getNet
-
getPayment
-
getPki
-
getPostgresql
-
getReseller
-
getSchema
-
getScm
-
getSignup
-
getTicket
-
getWeb
-
getWeb_jboss
-
getWeb_tomcat
-
getSimpleClient
-
equals
Uses equivalence equality likeObject.equals(java.lang.Object)
. Two connectors are considered equal only if they refer to the same object. -
hashCode
public final int hashCode()Uses equivalence hashCode likeObject.hashCode()
. -
clearCaches
public void clearCaches()Clears all caches used by this connector. -
executeCommand
Executes an aosh command and captures its output into aString
.- Parameters:
args
- the command and arguments to be processed- Returns:
- the results of the command wrapped into a
String
- Throws:
IOException
- if unable to access the serverSQLException
- if unable to access the database or data integrity checks fail
-
getLogger
Gets the logger for this connector. -
getConnection
protected abstract AoservConnection getConnection(int maxConnections) throws InterruptedIOException, IOException Allocates a connection to the server. These connections must later be released with theAoservConnection.close()
method. Connection pooling is obtained this way. These connections may be over any protocol, so they may only safely be used for one client/server exchange per allocation. Also, if connections are not always released, deadlock will quickly occur. Please use in a try-with-resources or try/finally block to make sure it is always released.- Returns:
- the connection to the server
- Throws:
InterruptedIOException
- if interrupted while connectingIOException
- if unable to connect to the server- See Also:
-
getConnector
Gets the defaultAoservConnector
as defined in thecom/aoindustries/aoserv/client/aoserv-client.properties
resource. Each possible protocol is tried, in order, until a successful connection is made.- Returns:
- the first
AoservConnector
to successfully connect to the server - Throws:
ConfigurationException
- if no connection can be established
-
getConnector
public static AoservConnector getConnector(User.Name username, String password) throws ConfigurationException Gets theAoservConnector
with the provided authentication information. Thecom/aoindustries/aoserv/client/aoserv-client.properties
resource determines which protocols will be used. Each possible protocol is tried, in order, until a successful connection is made.- Parameters:
username
- the username to connect aspassword
- the password to connect with- Returns:
- the first
AoservConnector
to successfully connect to the server - Throws:
ConfigurationException
- if no connection can be established
-
getConnector
public static AoservConnector getConnector(User.Name connectAs, User.Name authenticateAs, String password, DomainName daemonServer) throws ConfigurationException Gets theAoservConnector
with the provided authentication information. Thecom/aoindustries/aoserv/client/aoserv-client.properties
resource determines which protocols will be used. Each possible protocol is tried, in order, until a successful connection is made.- Parameters:
connectAs
- the username to connect asauthenticateAs
- the username used for authentication, if different thanconnectAs
, this username must have super user privilegespassword
- the password to connect with- Returns:
- the first
AoservConnector
to successfully connect to the server - Throws:
ConfigurationException
- if no connection can be established
-
getConnectorId
Each connector is assigned a unique identifier, which the server uses to not send events originating from this connector back to connections of this connector.- Returns:
- the globally unique identifier or
null
if the identifier has not yet been assigned
-
getHostname
Gets the hostname of the server that is connected to. -
getLocalIp
Gets the optional local IP address that connections are made from. -
getPort
Gets the server port that is connected to. -
getProtocol
Gets the communication protocol being used. -
getSecureRandom
A single random number generator is shared by all connector resources.Note: This is not a strong instance to avoid blocking.
-
getFastRandom
A fast pseudo-random number generator for non-cryptographic purposes. -
getSchemas
Gets an unmodifiable list of all of the top-level schemas in the system.- Specified by:
getSchemas
in interfaceSchemaParent
-
getTable
Each table has a unique ID, as found inSchemaTable
. The actualAoservTable
may be obtained given its identifier.- Parameters:
tableId
- the unique ID of the table- Returns:
- the appropriate subclass of
AoservTable
- Throws:
IllegalArgumentException
- if unable to find the table- See Also:
-
getTables
Gets an unmodifiable list of all of the tables in the system.- Returns:
- a
List<AoservTable>
containing all the tables. Each table is at an index corresponding to its unique ID. - See Also:
-
getCurrentAdministrator
Gets theAdministrator
who is logged in using thisAoservConnector
. Each username and password pair resolves to an always-accessibleAdministrator
. Details about permissions and capabilities may be obtained from theAdministrator
.- Returns:
- the
Administrator
who is logged in - Throws:
IOException
- if unable to communicate with the serverSQLException
- if unable to access the database or theAdministrator
was not found
-
invalidateTable
Manually invalidates the system caches.- Parameters:
tableId
- the table IDserver
- the pkey of the server or-1
for all servers- Throws:
IOException
SQLException
-
readInvalidateList
- Throws:
IOException
-
isSecure
Determines if the connections made by this protocol are secure. A connection is considered secure if it uses end-point to end-point encryption or goes over private lines.- Returns:
true
if the connection is secure- Throws:
IOException
- if unable to determine if the connection is secure
-
ping
Times how long it takes to make one request with the server. This will not retry and will return the first error encountered.- Returns:
- the connection latency in milliseconds
- Throws:
IOException
SQLException
-
printConnectionStatsHtml
- Throws:
IOException
-
release
Releases a connection to the server. This will either close the connection or allow another thread to use the connection. Connections may be of any protocol, so each connection must be released after every transaction.- Parameters:
connection
- the connection to close or release- Throws:
IOException
- if an error occurred while closing or releasing the connection- See Also:
-
removeFromAllTables
-
requestResult
public final <T> T requestResult(boolean allowRetry, AoservProtocol.CommandId commandId, AoservConnector.ResultRequest<T> resultRequest) throws IOException, SQLException - Throws:
IOException
SQLException
-
requestBooleanQuery
public final boolean requestBooleanQuery(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException - Throws:
IOException
SQLException
-
requestBooleanQueryInvalidating
public final boolean requestBooleanQueryInvalidating(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException - Throws:
IOException
SQLException
-
requestIntQuery
public final int requestIntQuery(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException - Throws:
IOException
SQLException
-
requestIntQueryInvalidating
public final int requestIntQueryInvalidating(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException - Throws:
IOException
SQLException
-
requestLongQuery
public final long requestLongQuery(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException - Throws:
IOException
SQLException
-
requestShortQuery
public final short requestShortQuery(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException - Throws:
IOException
SQLException
-
requestShortQueryInvalidating
public final short requestShortQueryInvalidating(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException - Throws:
IOException
SQLException
-
requestStringQuery
public final String requestStringQuery(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException - Throws:
IOException
SQLException
-
requestLongStringQuery
public final String requestLongStringQuery(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException Performs a query returning a String of any length (not limited to size <= 64k like requestStringQuery).- Throws:
IOException
SQLException
-
requestNullLongStringQuery
public final String requestNullLongStringQuery(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException Performs a query returning a String of any length (not limited to size <= 64k like requestStringQuery) ornull
. Supports nulls.- Throws:
IOException
SQLException
-
requestUpdate
public final void requestUpdate(boolean allowRetry, AoservProtocol.CommandId commandId, AoservConnector.UpdateRequest updateRequest) throws IOException, SQLException - Throws:
IOException
SQLException
-
requestUpdate
public final void requestUpdate(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException - Throws:
IOException
SQLException
-
requestUpdateInvalidating
public final void requestUpdateInvalidating(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException - Throws:
IOException
SQLException
-
switchUsers
- Throws:
IOException
-
tablesUpdated
-
testConnect
Tests the connectivity to the server. This test is only performed once per server per protocol. Following that, the cached results are used.- Throws:
IOException
- if unable to contact the serverSQLException
-
toString
-
getMasterEntropy
Gets some entropy from the master server, returns the number of bytes actually obtained.- Throws:
IOException
SQLException
-
getMasterEntropyNeeded
Gets the amount of entropy needed by the master server in bytes.- Throws:
IOException
SQLException
-
addMasterEntropy
Adds some entropy to the master server.- Throws:
IOException
SQLException
-
sort
public <K,T extends AoservObject<K, void sortT>> (ComparisonSortAlgorithm<? super T> sortAlgorithm, T[] list, SqlExpression[] sortExpressions, boolean[] sortOrders) -
sort
public <K,T extends AoservObject<K, void sortT>> (ComparisonSortAlgorithm<? super T> sortAlgorithm, List<T> list, SqlExpression[] sortExpressions, boolean[] sortOrders)
-