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
Nested ClassesModifier and TypeClassDescriptionprotected static classstatic interfaceThis is the preferred mechanism for providing custom requests that have a return value.static interfaceThis is the preferred mechanism for providing custom requests.static classAn update request with a returned invalidation list. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Identifierprotected final AoservConnector.IdLockstatic final longThe maximum size of the master entropy pool in bytes.protected final String -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAoservConnector(HostAddress hostname, InetAddress localIp, Port port, User.Name connectAs, User.Name authenticateAs, String password, DomainName daemonServer) -
Method Summary
Modifier and TypeMethodDescriptionlongaddMasterEntropy(byte[] buff, int numBytes) Adds some entropy to the master server.voidClears all caches used by this connector.final booleanUses equivalence equality likeObject.equals(java.lang.Object).executeCommand(String[] args) Executes an aosh command and captures its output into aString.getAosh()protected abstract AoservConnectiongetConnection(int maxConnections) Allocates a connection to the server.static AoservConnectorGets the defaultAoservConnectoras defined in thecom/aoindustries/aoserv/client/aoserv-client.propertiesresource.static AoservConnectorgetConnector(User.Name connectAs, User.Name authenticateAs, String password, DomainName daemonServer) Gets theAoservConnectorwith the provided authentication information.static AoservConnectorgetConnector(User.Name username, String password) Gets theAoservConnectorwith the provided authentication information.final IdentifierEach 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 AdministratorGets theAdministratorwho is logged in using thisAoservConnector.getDns()getEmail()static RandomA fast pseudo-random number generator for non-cryptographic purposes.getFtp()final HostAddressGets the hostname of the server that is connected to.getLinux()final InetAddressGets the optional local IP address that connections are made from.protected final LoggerGets the logger for this connector.intgetMasterEntropy(byte[] buff, int numBytes) Gets some entropy from the master server, returns the number of bytes actually obtained.longGets the amount of entropy needed by the master server in bytes.getMysql()getNet()getPki()final PortgetPort()Gets the server port that is connected to.abstract StringGets the communication protocol being used.Gets an unmodifiable list of all of the top-level schemas in the system.getScm()static SecureRandomA 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 inthashCode()Uses equivalence hashCode likeObject.hashCode().voidinvalidateTable(int tableId, int server) Manually invalidates the system caches.abstract booleanisSecure()Determines if the connections made by this protocol are secure.final intping()Times how long it takes to make one request with the server.abstract voidprintConnectionStatsHtml(Appendable out, boolean isXhtml) static IntListprotected abstract voidrelease(AoservConnection connection) Releases a connection to the server.final voidremoveFromAllTables(TableListener listener) final booleanrequestBooleanQuery(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) final booleanrequestBooleanQueryInvalidating(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) final intrequestIntQuery(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) final intrequestIntQueryInvalidating(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) final longrequestLongQuery(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) final StringrequestLongStringQuery(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) Performs a query returning a String of any length (not limited to size <= 64k like requestStringQuery).final StringrequestNullLongStringQuery(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> TrequestResult(boolean allowRetry, AoservProtocol.CommandId commandId, AoservConnector.ResultRequest<T> resultRequest) final shortrequestShortQuery(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) final shortrequestShortQueryInvalidating(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) final StringrequestStringQuery(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) final voidrequestUpdate(boolean allowRetry, AoservProtocol.CommandId commandId, AoservConnector.UpdateRequest updateRequest) final voidrequestUpdate(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) final voidrequestUpdateInvalidating(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 AoservConnectorswitchUsers(User.Name username) final voidtablesUpdated(IntList invalidateList) final voidTests the connectivity to the server.final StringtoString()
-
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 defaultAoservConnectoras defined in thecom/aoindustries/aoserv/client/aoserv-client.propertiesresource. Each possible protocol is tried, in order, until a successful connection is made.- Returns:
- the first
AoservConnectorto 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 theAoservConnectorwith the provided authentication information. Thecom/aoindustries/aoserv/client/aoserv-client.propertiesresource 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
AoservConnectorto 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 theAoservConnectorwith the provided authentication information. Thecom/aoindustries/aoserv/client/aoserv-client.propertiesresource 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
AoservConnectorto 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
nullif 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:
getSchemasin interfaceSchemaParent
-
getTable
Each table has a unique ID, as found inSchemaTable. The actualAoservTablemay 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 theAdministratorwho 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
Administratorwho is logged in - Throws:
IOException- if unable to communicate with the serverSQLException- if unable to access the database or theAdministratorwas not found
-
invalidateTable
Manually invalidates the system caches.- Parameters:
tableId- the table IDserver- the pkey of the server or-1for all servers- Throws:
IOExceptionSQLException
-
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:
trueif 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:
IOExceptionSQLException
-
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:
IOExceptionSQLException
-
requestBooleanQuery
public final boolean requestBooleanQuery(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException - Throws:
IOExceptionSQLException
-
requestBooleanQueryInvalidating
public final boolean requestBooleanQueryInvalidating(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException - Throws:
IOExceptionSQLException
-
requestIntQuery
public final int requestIntQuery(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException - Throws:
IOExceptionSQLException
-
requestIntQueryInvalidating
public final int requestIntQueryInvalidating(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException - Throws:
IOExceptionSQLException
-
requestLongQuery
public final long requestLongQuery(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException - Throws:
IOExceptionSQLException
-
requestShortQuery
public final short requestShortQuery(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException - Throws:
IOExceptionSQLException
-
requestShortQueryInvalidating
public final short requestShortQueryInvalidating(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException - Throws:
IOExceptionSQLException
-
requestStringQuery
public final String requestStringQuery(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException - Throws:
IOExceptionSQLException
-
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:
IOExceptionSQLException
-
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:
IOExceptionSQLException
-
requestUpdate
public final void requestUpdate(boolean allowRetry, AoservProtocol.CommandId commandId, AoservConnector.UpdateRequest updateRequest) throws IOException, SQLException - Throws:
IOExceptionSQLException
-
requestUpdate
public final void requestUpdate(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException - Throws:
IOExceptionSQLException
-
requestUpdateInvalidating
public final void requestUpdateInvalidating(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params) throws IOException, SQLException - Throws:
IOExceptionSQLException
-
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:
IOExceptionSQLException
-
getMasterEntropyNeeded
Gets the amount of entropy needed by the master server in bytes.- Throws:
IOExceptionSQLException
-
addMasterEntropy
Adds some entropy to the master server.- Throws:
IOExceptionSQLException
-
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)
-
