- java.lang.Object
-
- com.aoindustries.aoserv.client.AoservConnector
-
- All Implemented Interfaces:
SchemaParent
- Direct Known Subclasses:
TcpConnector
public abstract class AoservConnector extends Object implements SchemaParent
AnAoservConnector
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 Classes Modifier and Type Class Description protected static class
AoservConnector.IdLock
static interface
AoservConnector.ResultRequest<T>
This is the preferred mechanism for providing custom requests that have a return value.static interface
AoservConnector.UpdateRequest
This is the preferred mechanism for providing custom requests.
-
Field Summary
Fields Modifier and Type Field Description protected Identifier
id
protected AoservConnector.IdLock
idLock
static long
MASTER_ENTROPY_POOL_SIZE
The maximum size of the master entropy pool in bytes.protected String
password
-
Constructor Summary
Constructors Modifier Constructor Description protected
AoservConnector(HostAddress hostname, InetAddress localIp, 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 long
addMasterEntropy(byte[] buff, int numBytes)
Adds some entropy to the master server.void
clearCaches()
Clears all caches used by this connector.boolean
equals(Object obj)
Uses equivalence equality likeObject.equals(java.lang.Object)
.String
executeCommand(String[] args)
Executes an aosh command and captures its output into aString
.Schema
getAccount()
Schema
getAccounting()
Schema
getAosh()
Schema
getBackup()
Schema
getBilling()
protected abstract AoservConnection
getConnection(int maxConnections)
Allocates a connection to the server.static AoservConnector
getConnector()
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.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.Administrator
getCurrentAdministrator()
Gets theAdministrator
who is logged in using thisAoservConnector
.Schema
getDistribution()
Schema
getDistribution_management()
Schema
getDns()
Schema
getEmail()
static Random
getFastRandom()
A fast pseudo-random number generator for non-cryptographic purposes.Schema
getFtp()
HostAddress
getHostname()
Gets the hostname of the server that is connected to.Schema
getInfrastructure()
Schema
getLinux()
InetAddress
getLocalIp()
Gets the optional local IP address that connections are made from.protected Logger
getLogger()
Gets the logger for this connector.Schema
getMaster()
int
getMasterEntropy(byte[] buff, int numBytes)
Gets some entropy from the master server, returns the number of bytes actually obtained.long
getMasterEntropyNeeded()
Gets the amount of entropy needed by the master server in bytes.Schema
getMysql()
Schema
getNet()
Schema
getPayment()
Schema
getPki()
Port
getPort()
Gets the server port that is connected to.Schema
getPostgresql()
abstract String
getProtocol()
Gets the communication protocol being used.Schema
getReseller()
Schema
getSchema()
List<? extends Schema>
getSchemas()
Gets an unmodifiable list of all of the top-level schemas in the system.Schema
getScm()
static SecureRandom
getSecureRandom()
A single random number generator is shared by all connector resources.Schema
getSignup()
SimpleAoservClient
getSimpleClient()
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.Schema
getTicket()
Schema
getWeb()
Schema
getWeb_jboss()
Schema
getWeb_tomcat()
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.int
ping()
Times how long it takes to make one request with the server.abstract void
printConnectionStatsHtml(Appendable out, boolean isXhtml)
static IntList
readInvalidateList(StreamableInput in)
protected abstract void
release(AoservConnection connection)
Releases a connection to the server.void
removeFromAllTables(TableListener listener)
boolean
requestBooleanQuery(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params)
boolean
requestBooleanQueryInvalidating(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params)
int
requestIntQuery(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params)
int
requestIntQueryInvalidating(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params)
long
requestLongQuery(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params)
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).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
.<T> T
requestResult(boolean allowRetry, AoservProtocol.CommandId commandId, AoservConnector.ResultRequest<T> resultRequest)
short
requestShortQuery(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params)
short
requestShortQueryInvalidating(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params)
String
requestStringQuery(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params)
void
requestUpdate(boolean allowRetry, AoservProtocol.CommandId commandId, AoservConnector.UpdateRequest updateRequest)
void
requestUpdate(boolean allowRetry, AoservProtocol.CommandId commandId, Object... params)
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)
void
tablesUpdated(IntList invalidateList)
void
testConnect()
Tests the connectivity to the server.String
toString()
-
-
-
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 localIp, 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()
-
getSimpleClient
public SimpleAoservClient getSimpleClient()
-
equals
public final boolean equals(Object obj)
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 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
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
null
if 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()
A single random number generator is shared by all connector resources.Note: This is not a strong instance to avoid blocking.
-
getFastRandom
public static Random getFastRandom()
A fast pseudo-random number generator for non-cryptographic purposes.
-
getSchemas
public final List<? extends Schema> getSchemas()
Gets an unmodifiable list of all of the top-level schemas in the system.- Specified by:
getSchemas
in interfaceSchemaParent
-
getTable
public final AoservTable<?,?> getTable(int tableId) throws IllegalArgumentException
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:
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 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
public void invalidateTable(int tableId, int server) throws IOException, SQLException
Manually invalidates the system caches.- Parameters:
tableId
- the table IDserver
- the pkey of the server or-1
for all servers- Throws:
IOException
SQLException
-
readInvalidateList
public static IntList readInvalidateList(StreamableInput in) throws IOException
- Throws:
IOException
-
isSecure
public abstract boolean isSecure() throws IOException
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
public final int ping() throws IOException, SQLException
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
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 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
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, SQLException
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
-
getMasterEntropy
public int getMasterEntropy(byte[] buff, int numBytes) throws IOException, SQLException
Gets some entropy from the master server, returns the number of bytes actually obtained.- Throws:
IOException
SQLException
-
getMasterEntropyNeeded
public long getMasterEntropyNeeded() throws IOException, SQLException
Gets the amount of entropy needed by the master server in bytes.- Throws:
IOException
SQLException
-
addMasterEntropy
public long addMasterEntropy(byte[] buff, int numBytes) throws IOException, SQLException
Adds some entropy to the master server.- Throws:
IOException
SQLException
-
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)
-
-