amber.server.manager.application
Class ApplicationManager

java.lang.Object
  |
  +--amber.server.manager.application.ApplicationManager
All Implemented Interfaces:
ConnectionHandler

public class ApplicationManager
extends java.lang.Object
implements ConnectionHandler

This class handles multiple ConnectionController classes. This allows multiple types of connections to be handled in a normalised manner. The class contains multiple different profiles of connections which reflect the type of connection ie. normal, secure, administration. The class instantiates one connection controller for each type of connection and passes the connection information to the correct controller.

Version:
1.0.0
Author:
Dr. David J. Knowles
See Also:
Core, ListenerThread, ConnectionManager

Field Summary
protected  AmberInputStream dataDecoder
          The data decoding data stream that is used by all components to send information.
protected  AmberOutputStream dataEncoder
           
protected  java.io.ByteArrayOutputStream encoderBytes
          The data encoding data stream that is used by all components to send information.
 
Constructor Summary
ApplicationManager()
          Default constructor
ApplicationManager(Core parentServer, int port, DatabaseManager manager, ConnectionPool connectionPool, PropertiesHandler properties, Log logFile)
          Initialising constructor for this manager.
 
Method Summary
 void addActiveConnection(ServerConnectionInfo handler, int type)
          This function adds the input ServerConnectionInfo into the list of active connections.
 void addApplicationHandler(ServerConnectionInfo handler, int type)
          This function adds the specified ServerConnectionInfo to the manager.
 void addToCache(ServerConnectionInfo info, int type)
          This function adds a cache connection entry to the specified controller.
 void addToCache(java.util.Vector items, int type)
          This function adds multiple cache connection entries to the specified controller.
 ServerConnectionInfo checkLicense(int pageId, int pageSubId, int type)
          Checks license conditions.
protected  void connectApplication(java.net.Socket socket, Packet initPacket, AmberInputStream dataDecoder, int type)
          This function handles the connection requirements for the specified incoming connection.
protected  void connectBrowser(java.net.Socket socket, Packet initPacket, AmberInputStream dataDecoder, int type)
          This function handles the connection requirements for the specified incoming connection.
protected  void createControllers()
          This function starts the socket listener threads.
protected  AmberInputStream createDataInput(Packet packet)
          This function creates a data input stream from the data in the packet.
 ServerConnectionInfo findHandler(int pageId, int pageSubId, int type)
          Checks the system available handlers to determine if there is a matching ApplicationHandler.
 ServerConnectionInfo findInactiveHandler(java.lang.String sessionId, int type)
          Checks the system available inactive handlers to determine if there is a matching ApplicationHandler.
 java.util.Vector getActiveApplicationHandlers(int type)
          This returns a Vector of all active ApplicationHandlers in the manager.
 java.util.Vector getAllApplicationHandlers(int type)
          This returns a Vector of all ApplicationHandlers in the manager.
 ConnectionPool getConnectionPool()
          Returns the current connection pool for the amber server.
 ApplicationController getController(int type)
          Returns the controller which matches the specified type.
 DatabaseManager getDatabaseManager()
          Returns the current database manager.
protected  AmberInputStream getDataInput()
          This function returns the current data input stream.
 java.util.Vector getInactiveApplicationHandlers(int type)
          This returns a Vector of all inactive ApplicationHandlers in the manager.
 Log getLogger()
          This function returns the logging object.
 Core getParentServer()
          Returns the parent server object for this manager.
 java.util.Vector getPendingApplicationHandlers(int type)
          This returns a Vector of all pending ApplicationHandlers in the manager.
protected  java.lang.String getTableName(int type)
          Returns the table name corresponding to the type of connection received.
 void handleNewConnection(java.net.Socket socket, Packet initPacket, int systemType, int type)
          This function matches the incomimg packet to the corresponding page handler in the pendingPages variable.
 void init(Core parentServer, int port, DatabaseManager manager, ConnectionPool connectionPool, PropertiesHandler properties, Log logFile)
          This function is used to initialise the handler.
 boolean isDatabaseAvailable()
          This function returns whether the database is available for use.
 void reactivateConnection(ServerConnectionInfo handler, int type)
          This function takes the specified ServerConnectionInfo from the list of inactive connections and places it back on the list of active connections.
 void removeAllPendingApplicationHandlers(int type)
          This function removes all pending ApplicationHandlers in the manager.
 void removeApplicationHandler(ApplicationHandler handler)
          This function removes the specified ApplicationHandler from the manager.
 void removeApplicationHandler(ApplicationHandler handler, boolean callShutDown)
          This function removes the specified ApplicationHandler from the manager.
 void removeApplicationHandler(int pageId, int pageSubId, int type)
          This function removes the specified ApplicationHandler from the manager.
 void setApplicationInactive(ApplicationHandler handler)
          This function tells the controller to set the specified ApplicationHandler as inactive.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dataDecoder

protected AmberInputStream dataDecoder
The data decoding data stream that is used by all components to send information. THIS MUST BE USED FOR DECODING INFORMATION FROM THE SERVER!! See the associated accessor/creator functions

encoderBytes

protected java.io.ByteArrayOutputStream encoderBytes
The data encoding data stream that is used by all components to send information. THIS MUST BE USED FOR ENCODING INFORMATION TO THE CLIENT!! Owing to the way Java works it is not meaningful to have a corresponding input object statically created.

dataEncoder

protected AmberOutputStream dataEncoder
Constructor Detail

ApplicationManager

public ApplicationManager()
Default constructor

ApplicationManager

public ApplicationManager(Core parentServer,
                          int port,
                          DatabaseManager manager,
                          ConnectionPool connectionPool,
                          PropertiesHandler properties,
                          Log logFile)
Initialising constructor for this manager.
Method Detail

init

public void init(Core parentServer,
                 int port,
                 DatabaseManager manager,
                 ConnectionPool connectionPool,
                 PropertiesHandler properties,
                 Log logFile)
This function is used to initialise the handler. This is used when the class is instatiated dynamically using loadInstance.
Specified by:
init in interface ConnectionHandler
Parameters:
parentServer - Core base server object.
port - The port number to use for incoming normal connections.
securePort - The port number to use for incoming secure connections.
adminPort - The port number to use for incoming administration connections.
manager - Database manager class which handles database requirements.
connectionPool - The connection pool object which relates to the amber database tables.
properties - PropertiesHandler for the server properties file.
logFile - Log object which is used to log messages.

handleNewConnection

public void handleNewConnection(java.net.Socket socket,
                                Packet initPacket,
                                int systemType,
                                int type)
                         throws java.io.IOException,
                                ApplicationException
This function matches the incomimg packet to the corresponding page handler in the pendingPages variable. A match is activated and placed in the activePages vector. If there is no match the link is dropped and the packet is ignored.
Specified by:
handleNewConnection in interface ConnectionHandler
Parameters:
socket - Socket of the incoming connection.
initPacket - The Packet which is first sent by the page when the connection is opened.
systemType - The type of remote system which is attempting to connect.
type - The type of connection that is attempting to match the packet. This matches the constants in ListenerThread.
Throws:
java.io.IOException - containing decoding errors.
ApplicationException - containing application errors.

addActiveConnection

public void addActiveConnection(ServerConnectionInfo handler,
                                int type)
This function adds the input ServerConnectionInfo into the list of active connections.
Parameters:
handler - ServerConnectionInfo containing the details on the new connection. int type. The type of connection to look for a corresponding application for. The types must match the constants in ListenerThread. connection.

reactivateConnection

public void reactivateConnection(ServerConnectionInfo handler,
                                 int type)
This function takes the specified ServerConnectionInfo from the list of inactive connections and places it back on the list of active connections.
Parameters:
handler - ServerConnectionInfo containing the details on the connection being reactivated. int type. The type of connection to look for a corresponding application for. The types must match the constants in ListenerThread. connection.

findHandler

public ServerConnectionInfo findHandler(int pageId,
                                        int pageSubId,
                                        int type)
Checks the system available handlers to determine if there is a matching ApplicationHandler. int pageId. Application identifying primary ID number. int pageSubId. Application identifying secondary ID number. int type. The type of connection to look for a corresponding application for. The types must match the constants in ListenerThread.
Returns:
ServerConnectionInfo containing the required application details or null if there is no match.

findInactiveHandler

public ServerConnectionInfo findInactiveHandler(java.lang.String sessionId,
                                                int type)
Checks the system available inactive handlers to determine if there is a matching ApplicationHandler. String sessionId. The session ID the application was started with. This should be unique for an application. int type. The type of connection to look for a corresponding application for. The types must match the constants in ListenerThread.
Returns:
ServerConnectionInfo containing the required application details or null if there is no match.

checkLicense

public ServerConnectionInfo checkLicense(int pageId,
                                         int pageSubId,
                                         int type)
                                  throws java.io.IOException
Checks license conditions. If they are violated a LicenseViolatedApplicationHandler is returned in the ServerConnectionInfo. int pageId. Application identifying primary ID number. int pageSubId. Application identifying secondary ID number. int type. The type of connection to look for a corresponding application for. The types must match the constants in ListenerThread.
Returns:
ServerConnectionInfo containing the required application details or null if there is no match.

getTableName

protected java.lang.String getTableName(int type)
Returns the table name corresponding to the type of connection received. int type. The type of connection to look for a corresponding application for. The types must match the constants in ListenerThread.
Returns:
String table name to use.

connectBrowser

protected void connectBrowser(java.net.Socket socket,
                              Packet initPacket,
                              AmberInputStream dataDecoder,
                              int type)
                       throws java.io.IOException
This function handles the connection requirements for the specified incoming connection. In this case the connection is from a Browser based system.
Parameters:
socket - Socket of the incoming connection.
initPacket - The Packet which is first sent by the page when the connection is opened.
dataDecoder - AmberInputStream with the packet parameters.
type - The type of connection that is attempting to match the packet. This matches the constants in ListenerThread.
Throws:
java.io.IOException - containing decoding errors.

connectApplication

protected void connectApplication(java.net.Socket socket,
                                  Packet initPacket,
                                  AmberInputStream dataDecoder,
                                  int type)
                           throws java.io.IOException
This function handles the connection requirements for the specified incoming connection. In this case the connection is from a Browser based system.
Parameters:
socket - Socket of the incoming connection.
initPacket - The Packet which is first sent by the page when the connection is opened.
dataDecoder - AmberInputStream with the packet parameters.
type - The type of connection that is attempting to match the packet. This matches the constants in ListenerThread.
Throws:
java.io.IOException - containing decoding errors.

getController

public ApplicationController getController(int type)
Returns the controller which matches the specified type.
Parameters:
type - The type of connection that is attempting to match the packet. This matches the constants in ListenerThread.
Returns:
ApplicationController matching the type or null if no such type exists.

addToCache

public void addToCache(java.util.Vector items,
                       int type)
This function adds multiple cache connection entries to the specified controller. Transient connections will not be cached.
Parameters:
items - Vector of ServerConnectionInfo containing the information to cache.
type - The type of connection that is attempting to match the packet. This matches the constants in ListenerThread.

addToCache

public void addToCache(ServerConnectionInfo info,
                       int type)
This function adds a cache connection entry to the specified controller. Transient connections will not be cached.
Parameters:
info - ServerConnectionInfo containing the information of the connection to cache.
type - The type of connection that is attempting to match the packet. This matches the constants in ListenerThread.

removeAllPendingApplicationHandlers

public void removeAllPendingApplicationHandlers(int type)
This function removes all pending ApplicationHandlers in the manager.
Parameters:
type - The type of connection that is attempting to match the packet. This matches the constants in ListenerThread.

addApplicationHandler

public void addApplicationHandler(ServerConnectionInfo handler,
                                  int type)
                           throws ManagerException
This function adds the specified ServerConnectionInfo to the manager.
Parameters:
handler - ServerConnectionInfo handle of the page to add.
type - The type of connection that is attempting to match the packet. This matches the constants in ListenerThread.
Throws:
ManagerException - containing any errors.

removeApplicationHandler

public void removeApplicationHandler(ApplicationHandler handler)
This function removes the specified ApplicationHandler from the manager. This function will not delete from the database as there is no instantiated ApplicationHandler This function will call the shutDown method on the ApplicationHandler to ensure it cleans up properly.
Parameters:
handler - ApplicationHandler handle of the page to remove.

removeApplicationHandler

public void removeApplicationHandler(ApplicationHandler handler,
                                     boolean callShutDown)
This function removes the specified ApplicationHandler from the manager. This function will not delete from the database as there is no instantiated ApplicationHandler
Parameters:
handler - ApplicationHandler handle of the page to remove.
callShutDown - boolean true if the shut down function on the ApplicationHandler is to be called first.

removeApplicationHandler

public void removeApplicationHandler(int pageId,
                                     int pageSubId,
                                     int type)
This function removes the specified ApplicationHandler from the manager.
Parameters:
pageId - int containing the Page identifier of the page to terminate.
pageSubId - int containing the Page Sub identifier of the page to terminate.
type - The type of connection that is attempting to match the packet. This matches the constants in ListenerThread.

setApplicationInactive

public void setApplicationInactive(ApplicationHandler handler)
This function tells the controller to set the specified ApplicationHandler as inactive. Should the client not reconnect the server will clean up the application after a delay specified in the Controller.
Parameters:
handler - ApplicationHandler handle of the page to set inactive.
See Also:
ApplicationController.setApplicationInactive(amber.server.application.ApplicationHandler)

getActiveApplicationHandlers

public java.util.Vector getActiveApplicationHandlers(int type)
This returns a Vector of all active ApplicationHandlers in the manager.
Parameters:
type - The type of connection that is attempting to match the packet. This matches the constants in ListenerThread.
Returns:
Vector of amber.type.server.ServerConnectionInfo containing the required information.

getInactiveApplicationHandlers

public java.util.Vector getInactiveApplicationHandlers(int type)
This returns a Vector of all inactive ApplicationHandlers in the manager.
Parameters:
type - The type of connection that is attempting to match the packet. This matches the constants in ListenerThread.
Returns:
Vector of amber.type.server.ServerConnectionInfo containing the required information.

getPendingApplicationHandlers

public java.util.Vector getPendingApplicationHandlers(int type)
This returns a Vector of all pending ApplicationHandlers in the manager. This includes the pending ApplicationHandlers in the database or in the RMI list.
Parameters:
type - The type of connection that is attempting to match the packet. This matches the constants in ListenerThread.
Returns:
Vector of amber.type.server.ServerConnectionInfo containing the required information.

getAllApplicationHandlers

public java.util.Vector getAllApplicationHandlers(int type)
This returns a Vector of all ApplicationHandlers in the manager. This includes the pending ApplicationHandlers in the database or in the RMI lists.
Parameters:
type - The type of connection that is attempting to match the packet. This matches the constants in ListenerThread.
Returns:
Vector of amber.type.server.ServerConnectionInfo containing the required information.

isDatabaseAvailable

public boolean isDatabaseAvailable()
This function returns whether the database is available for use.
Returns:
true should the database manager exist.

getDatabaseManager

public DatabaseManager getDatabaseManager()
Returns the current database manager.
Returns:
DatabaseManager for the server.

getConnectionPool

public ConnectionPool getConnectionPool()
Returns the current connection pool for the amber server.
Returns:
ConnectionPool pointing to the database used by the server itself.

getParentServer

public Core getParentServer()
Returns the parent server object for this manager.
Returns:
Core server object.

getLogger

public Log getLogger()
This function returns the logging object.
Returns:
Log object which is the primary server logging object.

createControllers

protected void createControllers()
This function starts the socket listener threads.

createDataInput

protected AmberInputStream createDataInput(Packet packet)
This function creates a data input stream from the data in the packet.
Parameters:
packet - Packet containing the data to decode.
Returns:
AmberInputStream object for the corresponding data.

getDataInput

protected AmberInputStream getDataInput()
This function returns the current data input stream.
Returns:
AmberInputStream object for the current packet data.


Copyright © 2002 Clearfield Research Ltd. All Rights Reserved.