- java.lang.Object
-
- com.aoindustries.aoserv.client.AOServConnector
-
- All Implemented Interfaces:
SchemaParent
- Direct Known Subclasses:
TCPConnector
public abstract class AOServConnector extends Object implements SchemaParent
AnAOServConnectorprovides 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 Classes Modifier and Type Class Description protected static classAOServConnector.IdLockstatic interfaceAOServConnector.ResultRequest<T>This is the preferred mechanism for providing custom requests that have a return value.static interfaceAOServConnector.UpdateRequestThis is the preferred mechanism for providing custom requests.
-
Field Summary
Fields Modifier and Type Field Description protected Identifieridprotected AOServConnector.IdLockidLockstatic longMASTER_ENTROPY_POOL_SIZEThe maximum size of the master entropy pool in bytes.protected Stringpassword
-
Constructor Summary
Constructors Modifier Constructor Description protectedAOServConnector(HostAddress hostname, InetAddress local_ip, Port port, User.Name connectAs, User.Name authenticateAs, String password, DomainName daemonServer)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description longaddMasterEntropy(byte[] buff, int numBytes)Adds some entropy to the master server.voidclearCaches()Clears all caches used by this connector.booleanequals(Object O)Uses equivalence equality likeObject.equals(java.lang.Object).StringexecuteCommand(String[] args)Executes an aosh command and captures its output into aString.SchemagetAccount()SchemagetAccounting()SchemagetAosh()SchemagetBackup()SchemagetBilling()protected abstract AOServConnectiongetConnection(int maxConnections)Allocates a connection to the server.static AOServConnectorgetConnector()Gets 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.IdentifiergetConnectorId()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.AdministratorgetCurrentAdministrator()Gets theAdministratorwho is logged in using thisAOServConnector.SchemagetDistribution()SchemagetDistribution_management()SchemagetDns()SchemagetEmail()static RandomgetFastRandom()SchemagetFtp()HostAddressgetHostname()Gets the hostname of the server that is connected to.SchemagetInfrastructure()SchemagetLinux()InetAddressgetLocalIp()Gets the optional local IP address that connections are made from.protected LoggergetLogger()Gets the logger for this connector.SchemagetMaster()intgetMasterEntropy(byte[] buff, int numBytes)Gets some entropy from the master server, returns the number of bytes actually obtained.longgetMasterEntropyNeeded()Gets the amount of entropy needed by the master server in bytes.SchemagetMysql()SchemagetNet()SchemagetPayment()SchemagetPki()PortgetPort()Gets the server port that is connected to.SchemagetPostgresql()abstract StringgetProtocol()Gets the communication protocol being used.SchemagetReseller()SchemagetSchema()List<? extends Schema>getSchemas()Gets an unmodifiable list of all of the top-level schemas in the system.SchemagetScm()static SecureRandomgetSecureRandom()SchemagetSignup()SimpleAOClientgetSimpleAOClient()AOServTable<?,?>getTable(int tableID)Each table has a unique ID, as found inSchemaTable.List<? extends AOServTable<?,?>>getTables()Gets an unmodifiable list of all of the tables in the system.SchemagetTicket()SchemagetWeb()SchemagetWeb_jboss()SchemagetWeb_tomcat()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.intping()Times how long it takes to make one request with the server.abstract voidprintConnectionStatsHTML(Appendable out, boolean isXhtml)static IntListreadInvalidateList(StreamableInput in)protected abstract voidrelease(AOServConnection connection)Releases a connection to the server.voidremoveFromAllTables(TableListener listener)booleanrequestBooleanQuery(boolean allowRetry, AoservProtocol.CommandID commID, Object... params)booleanrequestBooleanQueryIL(boolean allowRetry, AoservProtocol.CommandID commID, Object... params)intrequestIntQuery(boolean allowRetry, AoservProtocol.CommandID commID, Object... params)intrequestIntQueryIL(boolean allowRetry, AoservProtocol.CommandID commID, Object... params)longrequestLongQuery(boolean allowRetry, AoservProtocol.CommandID commID, Object... params)StringrequestLongStringQuery(boolean allowRetry, AoservProtocol.CommandID commID, Object... params)Performs a query returning a String of any length (not limited to size <= 64k like requestStringQuery).StringrequestNullLongStringQuery(boolean allowRetry, AoservProtocol.CommandID commID, Object... params)Performs a query returning a String of any length (not limited to size <= 64k like requestStringQuery) ornull.<T> TrequestResult(boolean allowRetry, AoservProtocol.CommandID commID, AOServConnector.ResultRequest<T> resultRequest)shortrequestShortQuery(boolean allowRetry, AoservProtocol.CommandID commID, Object... params)shortrequestShortQueryIL(boolean allowRetry, AoservProtocol.CommandID commID, Object... params)StringrequestStringQuery(boolean allowRetry, AoservProtocol.CommandID commID, Object... params)voidrequestUpdate(boolean allowRetry, AoservProtocol.CommandID commID, AOServConnector.UpdateRequest updateRequest)voidrequestUpdate(boolean allowRetry, AoservProtocol.CommandID commID, Object... params)voidrequestUpdateIL(boolean allowRetry, AoservProtocol.CommandID commID, 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)voidtablesUpdated(IntList invalidateList)voidtestConnect()Tests the connectivity to the server.StringtoString()
-
-
-
Field Detail
-
MASTER_ENTROPY_POOL_SIZE
public static final long MASTER_ENTROPY_POOL_SIZE
The maximum size of the master entropy pool in bytes.- See Also:
- Constant Field Values
-
idLock
protected final AOServConnector.IdLock idLock
-
id
protected Identifier id
-
password
protected final String password
-
-
Constructor Detail
-
AOServConnector
protected AOServConnector(HostAddress hostname, InetAddress local_ip, Port port, User.Name connectAs, User.Name authenticateAs, String password, DomainName daemonServer)
-
-
Method Detail
-
getAccount
public Schema getAccount()
-
getAccounting
public Schema getAccounting()
-
getAosh
public Schema getAosh()
-
getBackup
public Schema getBackup()
-
getBilling
public Schema getBilling()
-
getDistribution
public Schema getDistribution()
-
getDistribution_management
public Schema getDistribution_management()
-
getDns
public Schema getDns()
-
getEmail
public Schema getEmail()
-
getFtp
public Schema getFtp()
-
getInfrastructure
public Schema getInfrastructure()
-
getLinux
public Schema getLinux()
-
getMaster
public Schema getMaster()
-
getMysql
public Schema getMysql()
-
getNet
public Schema getNet()
-
getPayment
public Schema getPayment()
-
getPki
public Schema getPki()
-
getPostgresql
public Schema getPostgresql()
-
getReseller
public Schema getReseller()
-
getSchema
public Schema getSchema()
-
getScm
public Schema getScm()
-
getSignup
public Schema getSignup()
-
getTicket
public Schema getTicket()
-
getWeb
public Schema getWeb()
-
getWeb_jboss
public Schema getWeb_jboss()
-
getWeb_tomcat
public Schema getWeb_tomcat()
-
getSimpleAOClient
public SimpleAOClient getSimpleAOClient()
-
equals
public final boolean equals(Object O)
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
public String executeCommand(String[] args) throws IOException, SQLException
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
protected final Logger 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:
AOServConnection.close()
-
getConnector
public static AOServConnector getConnector() throws ConfigurationException
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
public final Identifier 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
public final HostAddress getHostname()
Gets the hostname of the server that is connected to.
-
getLocalIp
public final InetAddress getLocalIp()
Gets the optional local IP address that connections are made from.
-
getPort
public final Port getPort()
Gets the server port that is connected to.
-
getProtocol
public abstract String getProtocol()
Gets the communication protocol being used.
-
getSecureRandom
public static SecureRandom getSecureRandom()
-
getFastRandom
public static Random getFastRandom()
-
getSchemas
public final List<? extends Schema> getSchemas()
Gets an unmodifiable list of all of the top-level schemas in the system.- Specified by:
getSchemasin interfaceSchemaParent
-
getTable
public final AOServTable<?,?> getTable(int tableID) throws IllegalArgumentException
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:
Table
-
getTables
public final List<? extends AOServTable<?,?>> 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:
getTable(int),Table
-
getCurrentAdministrator
public final Administrator getCurrentAdministrator() throws SQLException, IOException
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
public void invalidateTable(int tableID, int server) throws IOException, SQLExceptionManually invalidates the system caches.- Parameters:
tableID- the table IDserver- the pkey of the server or-1for all servers- Throws:
IOExceptionSQLException
-
readInvalidateList
public static IntList readInvalidateList(StreamableInput in) throws IOException
- Throws:
IOException
-
isSecure
public abstract boolean isSecure() throws IOExceptionDetermines 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
public final int ping() throws IOException, SQLExceptionTimes 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
public abstract void printConnectionStatsHTML(Appendable out, boolean isXhtml) throws IOException
- Throws:
IOException
-
release
protected abstract void release(AOServConnection connection) throws IOException
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:
getConnection(int),AOServConnection.close()
-
removeFromAllTables
public final void removeFromAllTables(TableListener listener)
-
requestResult
public final <T> T requestResult(boolean allowRetry, AoservProtocol.CommandID commID, AOServConnector.ResultRequest<T> resultRequest) throws IOException, SQLException- Throws:
IOExceptionSQLException
-
requestBooleanQuery
public final boolean requestBooleanQuery(boolean allowRetry, AoservProtocol.CommandID commID, Object... params) throws IOException, SQLException- Throws:
IOExceptionSQLException
-
requestBooleanQueryIL
public final boolean requestBooleanQueryIL(boolean allowRetry, AoservProtocol.CommandID commID, Object... params) throws IOException, SQLException- Throws:
IOExceptionSQLException
-
requestIntQuery
public final int requestIntQuery(boolean allowRetry, AoservProtocol.CommandID commID, Object... params) throws IOException, SQLException- Throws:
IOExceptionSQLException
-
requestIntQueryIL
public final int requestIntQueryIL(boolean allowRetry, AoservProtocol.CommandID commID, Object... params) throws IOException, SQLException- Throws:
IOExceptionSQLException
-
requestLongQuery
public final long requestLongQuery(boolean allowRetry, AoservProtocol.CommandID commID, Object... params) throws IOException, SQLException- Throws:
IOExceptionSQLException
-
requestShortQuery
public final short requestShortQuery(boolean allowRetry, AoservProtocol.CommandID commID, Object... params) throws IOException, SQLException- Throws:
IOExceptionSQLException
-
requestShortQueryIL
public final short requestShortQueryIL(boolean allowRetry, AoservProtocol.CommandID commID, Object... params) throws IOException, SQLException- Throws:
IOExceptionSQLException
-
requestStringQuery
public final String requestStringQuery(boolean allowRetry, AoservProtocol.CommandID commID, Object... params) throws IOException, SQLException
- Throws:
IOExceptionSQLException
-
requestLongStringQuery
public final String requestLongStringQuery(boolean allowRetry, AoservProtocol.CommandID commID, 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 commID, 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 commID, AOServConnector.UpdateRequest updateRequest) throws IOException, SQLException- Throws:
IOExceptionSQLException
-
requestUpdate
public final void requestUpdate(boolean allowRetry, AoservProtocol.CommandID commID, Object... params) throws IOException, SQLException- Throws:
IOExceptionSQLException
-
requestUpdateIL
public final void requestUpdateIL(boolean allowRetry, AoservProtocol.CommandID commID, Object... params) throws IOException, SQLException- Throws:
IOExceptionSQLException
-
switchUsers
public abstract AOServConnector switchUsers(User.Name username) throws IOException
- Throws:
IOException
-
tablesUpdated
public final void tablesUpdated(IntList invalidateList)
-
testConnect
public final void testConnect() throws IOException, SQLExceptionTests 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
-
getMasterEntropy
public int getMasterEntropy(byte[] buff, int numBytes) throws IOException, SQLExceptionGets some entropy from the master server, returns the number of bytes actually obtained.- Throws:
IOExceptionSQLException
-
getMasterEntropyNeeded
public long getMasterEntropyNeeded() throws IOException, SQLExceptionGets the amount of entropy needed by the master server in bytes.- Throws:
IOExceptionSQLException
-
addMasterEntropy
public long addMasterEntropy(byte[] buff, int numBytes) throws IOException, SQLExceptionAdds some entropy to the master server.- Throws:
IOExceptionSQLException
-
sort
public <K,T extends AOServObject<K,T>> void sort(ComparisonSortAlgorithm<? super T> sortAlgorithm, T[] list, SQLExpression[] sortExpressions, boolean[] sortOrders)
-
sort
public <K,T extends AOServObject<K,T>> void sort(ComparisonSortAlgorithm<? super T> sortAlgorithm, List<T> list, SQLExpression[] sortExpressions, boolean[] sortOrders)
-
-