- Direct Known Subclasses:
TcpServer
AOServServer
accepts connections from an AoservConnector
.
Once the connection is accepted and authenticated, the server carries out all actions requested
by the client while providing the necessary security checks and data filters.
This server is completely threaded to handle multiple, simultaneous clients.
- Author:
- AO Industries, Inc.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ExecutorService
An unbounded executor for master-wide tasks.protected final String
The address that this server will bind to.protected final int
The port that this server will listen on. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AoservMaster
(String serverBind, int serverPort) Creates a new, runningAOServServer
. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
authenticate
(DatabaseAccess db, String remoteHost, User.Name connectAs, User.Name authenticateAs, UnprotectedPassword password) static void
checkAccessHostname
(DatabaseConnection conn, RequestSource source, String action, String hostname) static void
checkAccessHostname
(DatabaseConnection conn, RequestSource source, String action, String hostname, List<DomainName> tlds) Determines if this hostname may be used by the source.final String
Gets the interface address this server is listening on.static Random
A fast pseudo-random number generator for non-cryptographic purposes.static Identifier
getNextConnectorId
(AoservProtocol.Version protocolVersion) final int
getPort()
Gets the interface port this server is listening on.abstract String
static int
static long
static int
static long
static long
static SecureRandom
A single random number generator is shared by all master resources.static <T> T
getService
(Class<T> clazz) Gets a started service of the given class or interface.static <T> List<T>
getServices
(Class<T> clazz) Gets all services of the given class or interface.static <T> List<T>
getStartedServices
(Class<T> clazz) Gets all started services of the given class or interface.static long
static User
getUser
(DatabaseAccess db, User.Name name) static UserHost[]
getUserHosts
(DatabaseAccess db, User.Name user) protected static void
static void
invalidateTable
(Table.TableId tableId) static void
invalidateTables
(DatabaseAccess db, InvalidateList invalidateList, RequestSource invalidateSource) Invalidates a table by notifying all connected clients, except the client that initiated this request.static boolean
isHostAllowed
(DatabaseAccess db, User.Name user, String host) Gets the hosts that are allowed for the provided username.static void
Loads and starts allMasterService
.static void
updateAoservProtocolLastUsed
(DatabaseAccess db, AoservProtocol.Version protocolVersion) static void
writeObject
(DatabaseConnection conn, RequestSource source, StreamableOutput out, AoservObject<?, ?> obj, String sql, Object... params) Writes a single object, possibly null if there is no row, from a query.static long
writeObjects
(DatabaseConnection conn, RequestSource source, StreamableOutput out, boolean provideProgress, CursorMode cursorMode, AoservObject<?, ?> obj, String sql, Object... params) Performs a query and writes all rows of the result set.static long
writeObjects
(RequestSource source, StreamableOutput out, boolean provideProgress, Collection<? extends AoservWritable> objs) Writes all rows of a results set.static <T extends AoservObject<?,
?>>
longwriteObjects
(RequestSource source, StreamableOutput out, boolean provideProgress, T obj, ResultSet results) Writes all rows of a results set.static long
writeObjectsSynced
(RequestSource source, StreamableOutput out, boolean provideProgress, Collection<? extends AoservWritable> objs) Writes all rows of a results set while synchronizing on each object.static void
writePenniesCheckBusiness
(DatabaseConnection conn, RequestSource source, String action, Account.Name account, StreamableOutput out, String sql, String param1, String param2) The query must result in precisely one row.static void
writePenniesCheckBusiness
(DatabaseConnection conn, RequestSource source, String action, Account.Name account, StreamableOutput out, String sql, String param1, String param2, Timestamp param3) The query must result in precisely one row.
-
Field Details
-
executorService
An unbounded executor for master-wide tasks. -
serverBind
The address that this server will bind to. -
serverPort
protected final int serverPortThe port that this server will listen on.
-
-
Constructor Details
-
AoservMaster
Creates a new, runningAOServServer
.
-
-
Method Details
-
getBindAddress
Gets the interface address this server is listening on. -
getNextConnectorId
-
getPort
public final int getPort()Gets the interface port this server is listening on. -
getProtocol
-
getSecureRandom
A single random number generator is shared by all master resources.Note: This is not a strong instance to avoid blocking.
-
getFastRandom
A fast pseudo-random number generator for non-cryptographic purposes. -
getRequestConcurrency
public static int getRequestConcurrency() -
incConnectionCount
protected static void incConnectionCount() -
getRequestConnections
public static long getRequestConnections() -
getRequestMaxConcurrency
public static int getRequestMaxConcurrency() -
getRequestTotalTime
public static long getRequestTotalTime() -
getRequestTransactions
public static long getRequestTransactions() -
getStartTime
public static long getStartTime() -
invalidateTables
public static void invalidateTables(DatabaseAccess db, InvalidateList invalidateList, RequestSource invalidateSource) throws IOException, SQLException Invalidates a table by notifying all connected clients, except the client that initiated this request.TODO: We need a way to convert invalidations of current tables to old table mappings. This would be the counterpart to
TableHandler.getOldTable(com.aoapps.dbc.DatabaseConnection, com.aoindustries.aoserv.master.RequestSource, com.aoapps.hodgepodge.io.stream.StreamableOutput, boolean, java.lang.String)
.- Throws:
IOException
SQLException
-
getService
Gets a started service of the given class or interface. If more than one started service is of the given class, there is no guarantee which is returned. TODO: round-robin from the registry.- Throws:
NoServiceException
- when no services are of the given classServiceNotStartedException
- when no services of the given class are startedMasterServiceException
-
getStartedServices
Gets all started services of the given class or interface.- Returns:
- The list of services or an empty list when none found
-
getServices
Gets all services of the given class or interface.- Returns:
- The list of services or an empty list when none found
- Throws:
ServiceNotStartedException
- when a matching service is not started
-
main
Loads and starts allMasterService
. Runs all of the configured protocols ofAoservMaster
processes as configured incom/aoindustries/aoserv/master/aoserv-master.properties
. -
writeObjects
public static <T extends AoservObject<?,?>> long writeObjects(RequestSource source, StreamableOutput out, boolean provideProgress, T obj, ResultSet results) throws IOException, SQLException Writes all rows of a results set.- Returns:
- The number of rows written
- Throws:
IOException
SQLException
-
writeObjects
public static long writeObjects(RequestSource source, StreamableOutput out, boolean provideProgress, Collection<? extends AoservWritable> objs) throws IOException Writes all rows of a results set.- Returns:
- The number of rows written
- Throws:
IOException
-
writeObjectsSynced
public static long writeObjectsSynced(RequestSource source, StreamableOutput out, boolean provideProgress, Collection<? extends AoservWritable> objs) throws IOException Writes all rows of a results set while synchronizing on each object.- Returns:
- The number of rows written
- Throws:
IOException
-
authenticate
public static String authenticate(DatabaseAccess db, String remoteHost, User.Name connectAs, User.Name authenticateAs, UnprotectedPassword password) throws IOException, SQLException - Parameters:
password
- Is destroyed before this method returns. If the original password is needed, pass a clone to this method.- Throws:
IOException
SQLException
-
checkAccessHostname
public static void checkAccessHostname(DatabaseConnection conn, RequestSource source, String action, String hostname) throws IOException, SQLException - Throws:
IOException
SQLException
- See Also:
-
checkAccessHostname
public static void checkAccessHostname(DatabaseConnection conn, RequestSource source, String action, String hostname, List<DomainName> tlds) throws IOException, SQLException Determines if this hostname may be used by the source. Thedns.ForbiddenZone
,dns.Zone
,web.VirtualHostName
, andemail.Domain
tables are searched, in this order, for a match. If a match is found with an owner of this source, then access is granted. If the source is not restricted by either server or business, then access is granted and the previous checks are avoided.TODO: What about ending '.' on zones vs DomainName objects here?
- Throws:
IOException
SQLException
-
getUserHosts
public static UserHost[] getUserHosts(DatabaseAccess db, User.Name user) throws IOException, SQLException - Throws:
IOException
SQLException
-
getUsers
- Throws:
IOException
SQLException
-
getUser
- Throws:
IOException
SQLException
-
isHostAllowed
public static boolean isHostAllowed(DatabaseAccess db, User.Name user, String host) throws IOException, SQLException Gets the hosts that are allowed for the provided username.- Throws:
IOException
SQLException
-
writeObject
public static void writeObject(DatabaseConnection conn, RequestSource source, StreamableOutput out, AoservObject<?, ?> obj, String sql, Object... params) throws IOException, SQLExceptionWrites a single object, possibly null if there is no row, from a query. The query must result in either zero or one row. If zero,null
is written. If more than one row, anSQLException
is thrown.- Throws:
SQLException
- when more than one row is in the result setIOException
-
writeObjects
public static long writeObjects(DatabaseConnection conn, RequestSource source, StreamableOutput out, boolean provideProgress, CursorMode cursorMode, AoservObject<?, ?> obj, String sql, Object... params) throws IOException, SQLExceptionPerforms a query and writes all rows of the result set. Calls eitherselectObjects
orfetchObjects
based on theCursorMode
.In particular, implements the
CursorMode.AUTO
mode for cursor selection.- Returns:
- The number of rows written
- Throws:
IOException
SQLException
- See Also:
-
writePenniesCheckBusiness
public static void writePenniesCheckBusiness(DatabaseConnection conn, RequestSource source, String action, Account.Name account, StreamableOutput out, String sql, String param1, String param2, Timestamp param3) throws IOException, NoRowException, SQLException The query must result in precisely one row. If zero rows,NoRowException
is thrown. If more than one row, anSQLException
is thrown.- Throws:
NoRowException
- when no rows are in the result setSQLException
- when more than one row is in the result setIOException
-
writePenniesCheckBusiness
public static void writePenniesCheckBusiness(DatabaseConnection conn, RequestSource source, String action, Account.Name account, StreamableOutput out, String sql, String param1, String param2) throws IOException, NoRowException, SQLException The query must result in precisely one row. If zero rows,NoRowException
is thrown. If more than one row, anSQLException
is thrown.- Throws:
NoRowException
- when no rows are in the result setSQLException
- when more than one row is in the result setIOException
-
invalidateTable
-
updateAoservProtocolLastUsed
public static void updateAoservProtocolLastUsed(DatabaseAccess db, AoservProtocol.Version protocolVersion) throws IOException, SQLException - Throws:
IOException
SQLException
-