- 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 ExecutorServiceAn unbounded executor for master-wide tasks.protected final StringThe address that this server will bind to.protected final intThe port that this server will listen on. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAoservMaster(String serverBind, int serverPort) Creates a new, runningAOServServer. -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringauthenticate(DatabaseAccess db, String remoteHost, User.Name connectAs, User.Name authenticateAs, UnprotectedPassword password) static voidcheckAccessHostname(DatabaseConnection conn, RequestSource source, String action, String hostname) static voidcheckAccessHostname(DatabaseConnection conn, RequestSource source, String action, String hostname, List<DomainName> tlds) Determines if this hostname may be used by the source.final StringGets the interface address this server is listening on.static RandomA fast pseudo-random number generator for non-cryptographic purposes.static IdentifiergetNextConnectorId(AoservProtocol.Version protocolVersion) final intgetPort()Gets the interface port this server is listening on.abstract Stringstatic intstatic longstatic intstatic longstatic longstatic SecureRandomA single random number generator is shared by all master resources.static <T> TgetService(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 longstatic UsergetUser(DatabaseAccess db, User.Name name) static UserHost[]getUserHosts(DatabaseAccess db, User.Name user) protected static voidstatic voidinvalidateTable(Table.TableId tableId) static voidinvalidateTables(DatabaseAccess db, InvalidateList invalidateList, RequestSource invalidateSource) Invalidates a table by notifying all connected clients, except the client that initiated this request.static booleanisHostAllowed(DatabaseAccess db, User.Name user, String host) Gets the hosts that are allowed for the provided username.static voidLoads and starts allMasterService.static voidupdateAoservProtocolLastUsed(DatabaseAccess db, AoservProtocol.Version protocolVersion) static voidwriteObject(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 longwriteObjects(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 longwriteObjects(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 longwriteObjectsSynced(RequestSource source, StreamableOutput out, boolean provideProgress, Collection<? extends AoservWritable> objs) Writes all rows of a results set while synchronizing on each object.static voidwritePenniesCheckBusiness(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 voidwritePenniesCheckBusiness(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:
IOExceptionSQLException
-
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 ofAoservMasterprocesses 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:
IOExceptionSQLException
-
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:
IOExceptionSQLException
-
checkAccessHostname
public static void checkAccessHostname(DatabaseConnection conn, RequestSource source, String action, String hostname) throws IOException, SQLException - Throws:
IOExceptionSQLException- 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.Domaintables 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:
IOExceptionSQLException
-
getUserHosts
public static UserHost[] getUserHosts(DatabaseAccess db, User.Name user) throws IOException, SQLException - Throws:
IOExceptionSQLException
-
getUsers
- Throws:
IOExceptionSQLException
-
getUser
- Throws:
IOExceptionSQLException
-
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:
IOExceptionSQLException
-
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,nullis written. If more than one row, anSQLExceptionis 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 eitherselectObjectsorfetchObjectsbased on theCursorMode.In particular, implements the
CursorMode.AUTOmode for cursor selection.- Returns:
- The number of rows written
- Throws:
IOExceptionSQLException- 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, ExtraRowException, SQLException The query must result in precisely one row. If zero rows,NoRowExceptionis thrown. If more than one row, anExtraRowExceptionis thrown.- Throws:
NoRowException- when no rows are in the result setExtraRowException- when more than one row is in the result setIOExceptionSQLException
-
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, ExtraRowException, SQLException The query must result in precisely one row. If zero rows,NoRowExceptionis thrown. If more than one row, anExtraRowExceptionis thrown.- Throws:
NoRowException- when no rows are in the result setExtraRowException- when more than one row is in the result setIOExceptionSQLException
-
invalidateTable
-
updateAoservProtocolLastUsed
public static void updateAoservProtocolLastUsed(DatabaseAccess db, AoservProtocol.Version protocolVersion) throws IOException, SQLException - Throws:
IOExceptionSQLException
-
