Class DerbyImpl
- Author:
- Christopher Mindus
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe database name of an iiziServer and of the iiziGo designer: "iiziServer".static final StringThe Derby Client jars, relative to the JDBC drivers directory, as the pool and the probe ofstartServer(File,File,int,String)load them.static final StringThe Derby Client driver class name.static final intThe default Derby server network port: 1527.static final StringThe user the probe ofstartServer(File,File,int,String)connects as to ask a Derby network server this process did not start which database it serves (CC-FIX-DERBY-ATTACH): no password, and never the configured database user.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionstatic booleanaddServerStateListener(Runnable listener) Adds a new listener for the server state.static booleanChecks if the Derby network server can be stopped, or if it running outside of our reach.static StringGets why the Derby network server that answers on the port is not used, asstartServer(File,File,int,String)logged it (CC-FIX-DERBY-ATTACH).static ProcessHandlegetServerLeftRunning(File dbDir) Gets the Derby network server that an earlier iiziGo started in a database directory and left running for another iiziGo (CC-FIX-PORT-RANGE-A, R-D-16): thederbyserver.pidfile this class writes when it starts a server names a live process.static intGets the server port being used.static DBServerStateGets the state of the Derby network server.static DBServerStateisSocketConnectable(String host, int port, int timeout, IWebServiceEngine wsEngine) Checks if a host is Socket connectable on the specified host name and port.static booleanremoveServerStateListener(Runnable listener) Removes a listener for the server state.static DBServerStatestartServer(File jdbcDriversDir, File dbDir, int port) Starts the Derby network server with configured port if running on "localhost".static DBServerStatestartServer(File jdbcDriversDir, File dbDir, int port, String database) Starts the Derby network server with configured port if running on "localhost", for a database of another name thanDEFAULT_DATABASE_NAME: seestartServer(File,File,int).static DBServerStatestopServer(File jdbcDriversDir) Stops the Derby network server if started from this instance.static DBServerStatestopServerLeftRunning(File jdbcDriversDir, File dbDir, int port) Stops the Derby network server an earlier iiziGo started and left running, when this iiziGo is the last one out (R-D-16): the shutdown command on its port, then its PID file is removed once the process has ended.
Field Details
DERBY_DEFAULT_PORT
public static final int DERBY_DEFAULT_PORTThe default Derby server network port: 1527.- See Also:
DERBY_CLIENT_DRIVER_CLASS
DERBY_CLIENT_CLASSPATH
The Derby Client jars, relative to the JDBC drivers directory, as the pool and the probe ofstartServer(File,File,int,String)load them.- See Also:
DEFAULT_DATABASE_NAME
The database name of an iiziServer and of the iiziGo designer: "iiziServer".- See Also:
PROBE_USER
The user the probe ofstartServer(File,File,int,String)connects as to ask a Derby network server this process did not start which database it serves (CC-FIX-DERBY-ATTACH): no password, and never the configured database user. Derby accepts any user unless it is set up to require authentication.- See Also:
Constructor Details
DerbyImpl
public DerbyImpl(File jdbcDriversDir, File dir, boolean doStartDBServer, String host, int port, String database, boolean doCreateDB, String username, String password) Constructor.- Parameters:
dir- The directory to the derby Database server current directory. If the directory does not exist, it will be created.nullmeans that the database server is not started.doStartDBServer- Flag to start the Derby network database server.host- The host name of the Derby network database server. The server will not be started, regardless ofdoStartDBSeerverifhostis not "localhost", "127.0.0.1" or null.port- The port number to use, -1 or zero for default.database- The database name.doCreateDB- Flag to create database if not existing.username- The user name.password- The password.- Throws:
NullPointerException- IfjdbcDriversDirisnull.IllegalArgumentException- Ifportis not 1 to 65535, or the directoryjdbcDriversDirordirdoes not exist.
Method Details
getServerState
Gets the state of the Derby network server.- Returns:
- The state.
addServerStateListener
Adds a new listener for the server state. Calling this method multiple times with the same listener will have no effect (but to return false).- Parameters:
listener- The listener.- Returns:
- true if the listener was added, false otherwise.
- Throws:
NullPointerException- If the listener isnull.
removeServerStateListener
Removes a listener for the server state.- Parameters:
listener- The listener.- Returns:
- true if listener is successfully removed, false otherwise.
- Throws:
NullPointerException- If the listener isnull.
canStopServer
public static boolean canStopServer()Checks if the Derby network server can be stopped, or if it running outside of our reach.- Returns:
- true if it can probably be stopped, false if not, or already stopped.
getServerPort
public static int getServerPort()Gets the server port being used.- Returns:
- The port number, zero if not started/starting.
isSocketConnectable
public static DBServerState isSocketConnectable(String host, int port, int timeout, IWebServiceEngine wsEngine) Checks if a host is Socket connectable on the specified host name and port. This call does just tries to access the Socket with the specifiedhostandport, nothing else.- Parameters:
host- The host name or address.port- The port name.timeout- Specifies the timeout value, in milliseconds, to be used when opening a communications link to the specified host and port. A timeout of zero is interpreted as an infinite timeout and is NOT recommended.wsEngine- The web service engine used to resolve a proxy in case it's not a "localhost". Set tonullto useProxy.NO_PROXY.- Returns:
- One of:
startServer
Starts the Derby network server with configured port if running on "localhost". Otherwise nothing is done.If network server process failed starting, the error will be logged as SEVERE.
A Derby network server that already answers on the port is asked which database it serves before it is used (CC-FIX-DERBY-ATTACH, TP-D-3): the one of the configured directory - an earlier iiziGo's, or a server's child that outlived it - is attached to (
DBServerState.CONNECTABLE, orDBServerState.STARTEDwhen this process's own PID file names it); one that serves another directory, has no such database while the configured directory has one, cannot be asked, or is named by nothing while the configured directory has no database yet is refused with a SEVERE line naming both directories (DBServerState.OTHER_DATABASE,getRefusal()). Before, any listener on the port was used as it was, and a server then ran on another process's database - the iiziGo designer's.- Parameters:
jdbcDriversDir- The directory for the JDBC drivers.dbDir- The directory for the databases.port- The port number.- Returns:
- One of:
- Throws:
NullPointerException- Ifdirisnull.IllegalArgumentException- Ifportis not 1 to 65535, or the directorydirdoes not exist.
startServer
Starts the Derby network server with configured port if running on "localhost", for a database of another name thanDEFAULT_DATABASE_NAME: seestartServer(File,File,int).- Parameters:
jdbcDriversDir- The directory for the JDBC drivers.dbDir- The directory for the databases.port- The port number.database- The database name, the one a Derby that already answers must serve underdbDir.- Returns:
- One of:
- Throws:
NullPointerException- Ifdirordatabaseisnull.IllegalArgumentException- Ifportis not 1 to 65535, or the directorydirdoes not exist.
getRefusal
Gets why the Derby network server that answers on the port is not used, asstartServer(File,File,int,String)logged it (CC-FIX-DERBY-ATTACH).- Returns:
- The reason, naming the configured database directory and the one served; null when it is used, or this process started its own.
getServerLeftRunning
Gets the Derby network server that an earlier iiziGo started in a database directory and left running for another iiziGo (CC-FIX-PORT-RANGE-A, R-D-16): thederbyserver.pidfile this class writes when it starts a server names a live process. A Derby the user started by hand writes no such file and is never named here, and nor is the one this process started (seecanStopServer()).- Parameters:
dbDir- The database directory.- Returns:
- The process, null for none.
stopServerLeftRunning
Stops the Derby network server an earlier iiziGo started and left running, when this iiziGo is the last one out (R-D-16): the shutdown command on its port, then its PID file is removed once the process has ended.- Parameters:
jdbcDriversDir- The directory for the JDBC drivers.dbDir- The database directory.port- The port of the server.- Returns:
- The state of the server: STOPPED, or the state before when there was nothing to stop or it failed.
stopServer
Stops the Derby network server if started from this instance.- Parameters:
jdbcDriversDir- The directory for the JDBC drivers.- Returns:
- The state of the server, one of:
- STOPPED,
- CONNECTION_FAILED,
- START_FAILED,
- UNKNOWN.