i-net Konnekter

com.inet.jj.srv
Class JJServer

java.lang.Object
  extended bycom.inet.jj.srv.JJServer
All Implemented Interfaces:
java.lang.Runnable

public class JJServer
extends java.lang.Object
implements java.lang.Runnable

This is the i-net Konnekter(TM) server.


Field Summary
static int LOG_DEBUG
           
static int LOG_FATAL
           
static int LOG_INFO
           
static int LOG_WARNING
           
 
Constructor Summary
JJServer()
          Creates a new i-net Konnekter server on the default port (9876).
JJServer(int port)
          Creates a new i-net Konnekter server on a specified port.
JJServer(int port, java.lang.ClassLoader loader)
          Creates a new i-net Konnekter server on a specified port and with an additional classloader.
 
Method Summary
 java.lang.Object addCommand(java.lang.String name, JavaCommandFactory cmdFactory)
          Adds a new JavaCommandFactory to the command current list.
 java.lang.Object addCommand(java.lang.String name, java.lang.String sql)
          Adds a new command to the current list.
 java.util.Properties addUDS(java.lang.String name, java.lang.String driver, java.lang.String url)
          Adds a new User Data Source specified by a name and adds the driver's name and url for a certain database to the list.
 java.util.Properties addUDS(java.lang.String name, java.lang.String driver, java.lang.String url, java.util.Properties info)
          Adds a new User Data Source specified by a name and adds the driver's name, url and properties for a certain database to the list.
 java.util.Properties addUDS(java.lang.String name, java.lang.String driver, java.lang.String url, java.lang.String user, java.lang.String password)
          Adds a new User Data Source specified by a name and adds the driver's name, url, user name and password for a certain database to the list.
 java.lang.Object getCommand(java.lang.String name)
          Returns the sql statement for this command.
 int getConnectedClientCount()
          Returns the current number of the connected clients.
 java.util.Vector getConnectedHostNames()
          Returns a list of the client's host names connected to the server.
 java.util.Vector getConnectedHostNames(java.lang.String uds)
          Returns the list of the client's host names connected to the specified UDS on the server.
 java.sql.Connection getConnection(java.lang.String uds)
          Try to make a database connection for the given UserDataSource.
 java.util.Vector getCurrentExecutingCommands()
          Returns a list of current executing commands or SQL statements for all clients.
 java.util.Vector getCurrentExecutingCommands(java.lang.String host)
          Returns a list of current executing commands or SQL statements for a certain client.
 int getDBConnectionCount()
          Returns the current number of connections to the databases.
 int getDBConnectionCount(java.lang.String host)
          Returns the current number of connections to the databases for a specified host.
 int getDBFreeConnectionCount()
          Returns the number of connections to the databases which are currently not in use.
 int getInactiveTimeout()
          Returns the current inactive timeout.
 long getInitialTime(java.lang.String host)
          Returns the initial time of the client's connection.
 int getLogLevel()
          Get the log level.
 java.io.PrintStream getLogStream()
          Returns the server's log stream.
 int getMaxConnectionCount()
          Returns the number of possible maximum connections.
 boolean getOnlyCommandMode()
          Returns the current server command mode.
 int getOpenCallableStatementCount()
          Returns the current number of the callable statements opened on the server.
 int getOpenCallableStatementCount(java.lang.String host)
          Returns the current number of the callable statements opened on the server for a client.
 java.util.Vector getOpenedCommands()
          Returns a list of commands which are opened on the server for all clients.
 java.util.Vector getOpenedCommands(java.lang.String host)
          Returns a list of commands which are opened on the server for specified client.
 int getOpenJavaCommandCount()
          Returns the current number of the JavaCommands opened on the server.
 int getOpenJavaCommandCount(java.lang.String host)
          Returns the current number of the callable statements opened on the server for a client.
 int getOpenPreparedStatementCount()
          Returns the current number of the prepared statements opened on the server.
 int getOpenPreparedStatementCount(java.lang.String host)
          Returns the current number of the prepared statements opened on the server for a client.
 int getOpenResultSetCount()
          Returns the current number of the ResultSets opened on the server.
 int getOpenResultSetCount(java.lang.String host)
          Returns the current number of the ResultSets opened on the server for a client.
 int getOpenStatementCount()
          Returns the current number of the statements opened on the server.
 int getOpenStatementCount(java.lang.String host)
          Returns the current number of the statements opened on the server for a client.
 int getPoolLoginTimeout()
          Returns the maximum time in seconds that the PoolManager can wait when the maximum number of connections for a DataSource is in use.
 int getPoolTimeout()
          Returns timeout of an unused connection in the pool before the connection was closed.
 java.util.Map getQueryStatistics()
          Get the query statistic.
 java.util.Properties getUDS(java.lang.String name)
          Returns a User Data Source specified by it's name as java.util.Properties object.
 boolean isLobToStream()
          Get the flag logToStreams.
 void removeAllCommands()
          Removes all commands from the current list.
 void removeAllUDS()
          Removes all User Data Sources from the list.
 java.lang.Object removeCommand(java.lang.String name)
          Removes the command from the current list.
 java.util.Properties removeUDS(java.lang.String name)
          Removes the specified User Data Source from the list.
 void run()
          For internal use only.
 void setEnableQueryStatistics(boolean enable)
          This enable the accumulation of a query statistics.
 void setInactiveTimeout(int timeout)
          Sets the time which the server will be waiting for a client's request.
 void setLobToStream(boolean lobToStream)
          Sett the flag logToStreams.
 void setLogLevel(int level)
          Set the log level.
 void setLogStream(java.io.PrintStream out)
          Sets the PrintStream object to log the server.
 void setMaxConnectionCount(int max)
          Sets the number of maximum connections to be made for the PoolManager.
 void setOnlyCommandMode(boolean mode)
          If the "only command" mode is enabled then the server will accept commands, only.
 void setPoolLoginTimeout(int timeout)
          Sets the maximum time in seconds that the PoolManager can wait when the maximum number of connections for a DataSource is in use.
 void setPoolTimeout(int poolTimeout)
          This property sets the minimum time in seconds the PoolManager is waiting before an unused real connection to a database will be closed and removed from the pool.
 void start()
          Starts the i-net Konnekter(TM) server.
 void stop()
          Stops the i-net Konnekter(TM) server.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG_FATAL

public static final int LOG_FATAL
See Also:
Constant Field Values

LOG_WARNING

public static final int LOG_WARNING
See Also:
Constant Field Values

LOG_INFO

public static final int LOG_INFO
See Also:
Constant Field Values

LOG_DEBUG

public static final int LOG_DEBUG
See Also:
Constant Field Values
Constructor Detail

JJServer

public JJServer()
Creates a new i-net Konnekter server on the default port (9876).


JJServer

public JJServer(int port)
Creates a new i-net Konnekter server on a specified port.

Parameters:
port - the port number.

JJServer

public JJServer(int port,
                java.lang.ClassLoader loader)
Creates a new i-net Konnekter server on a specified port and with an additional classloader.

Parameters:
port - the port number.
loader - optional ClassLoader
Method Detail

start

public void start()
           throws java.lang.Exception
Starts the i-net Konnekter(TM) server. The result is that the server is listening on the specified port number.

Throws:
java.lang.Exception - if it is unable to start the server. E.g. if the specified port is in use.
See Also:
stop()

run

public void run()
For internal use only.

Specified by:
run in interface java.lang.Runnable

stop

public void stop()
Stops the i-net Konnekter(TM) server.

See Also:
start()

addUDS

public java.util.Properties addUDS(java.lang.String name,
                                   java.lang.String driver,
                                   java.lang.String url,
                                   java.util.Properties info)
Adds a new User Data Source specified by a name and adds the driver's name, url and properties for a certain database to the list. The UDS name can be used by clients to access the resource specified by this UDS.

Parameters:
name - the data source name.
driver - the driver name.
url - the driver url.
info - the driver properties.
Returns:
the previous UDS properties for this UDS or null if there was no such UDS.
See Also:
addUDS(String, String, String), addUDS(String, String, String, String, String), getUDS(String), removeUDS(String), removeAllUDS()

addUDS

public java.util.Properties addUDS(java.lang.String name,
                                   java.lang.String driver,
                                   java.lang.String url,
                                   java.lang.String user,
                                   java.lang.String password)
Adds a new User Data Source specified by a name and adds the driver's name, url, user name and password for a certain database to the list. The UDS name can be used by clients to access the resource specified by this UDS.

Parameters:
name - the data source name.
driver - the driver name.
url - the driver url.
user - the user name.
password - the password.
Returns:
the previous UDS properties for this UDS or null if there was no such UDS.
See Also:
addUDS(String, String, String), addUDS(String, String, String, Properties), getUDS(String), removeUDS(String), removeAllUDS()

addUDS

public java.util.Properties addUDS(java.lang.String name,
                                   java.lang.String driver,
                                   java.lang.String url)
Adds a new User Data Source specified by a name and adds the driver's name and url for a certain database to the list. The UDS name can be used by clients to access the resource specified by this UDS.

Parameters:
name - the data source name.
driver - the driver name.
url - the driver url.
Returns:
the previous UDS properties for this UDS or null if there was no such UDS.
See Also:
addUDS(String, String, String, Properties), addUDS(String, String, String, String, String), getUDS(String), removeUDS(String), removeAllUDS()

removeUDS

public java.util.Properties removeUDS(java.lang.String name)
Removes the specified User Data Source from the list.

Parameters:
name - the name of the user data source.
Returns:
the UDS properties for this name or null if there was no such UDS.
See Also:
removeAllUDS(), addUDS(String, String, String), addUDS(String, String, String, Properties), addUDS(String, String, String, String, String), getUDS(String)

removeAllUDS

public void removeAllUDS()
Removes all User Data Sources from the list.

See Also:
removeUDS(String), addUDS(String, String, String), addUDS(String, String, String, Properties), addUDS(String, String, String, String, String), getUDS(String)

getUDS

public java.util.Properties getUDS(java.lang.String name)
Returns a User Data Source specified by it's name as java.util.Properties object. With the get(String key) method you can get each property of the UDS, e.g. get("url") returns the url.

Parameters:
name - the data source name.
Returns:
the java.util.Properties object or null if UDS under this name not exist.
See Also:
addUDS(String, String, String), addUDS(String, String, String, String, String), addUDS(String, String, String, Properties), removeUDS(String), removeAllUDS()

setInactiveTimeout

public void setInactiveTimeout(int timeout)
Sets the time which the server will be waiting for a client's request. If the timeout has expired, the connection to the client will be closed automatically. A timeout of zero means an infinite timeout.

Parameters:
timeout - the timeout in seconds
See Also:
getInactiveTimeout()

getInactiveTimeout

public int getInactiveTimeout()
Returns the current inactive timeout. The default value is 900 sec (15 min).

Returns:
the timeout in seconds
See Also:
setInactiveTimeout(int)

setLogStream

public void setLogStream(java.io.PrintStream out)
Sets the PrintStream object to log the server.
E.g. to enable the logging to the file "server.log" use the following:
setLogStream(new PrintStream(new FileOutputStream("server.log")))
or for "standard" output: setLogStream(System.out)

Parameters:
out - the logging PrintStream object; null to disable logging.
See Also:
getLogStream()

getLogStream

public java.io.PrintStream getLogStream()
Returns the server's log stream.

Returns:
java.io.PrintStream object or null if the logging is disable.
See Also:
setLogStream(java.io.PrintStream)

setLogLevel

public void setLogLevel(int level)
Set the log level. The default value is LOG_WARNING.

Parameters:
level - the new log level
See Also:
LOG_FATAL, LOG_WARNING, LOG_INFO, LOG_DEBUG, setLogStream(java.io.PrintStream), getLogLevel()

getLogLevel

public int getLogLevel()
Get the log level.

Returns:
the current log level
See Also:
setLogLevel(int)

setPoolTimeout

public void setPoolTimeout(int poolTimeout)
This property sets the minimum time in seconds the PoolManager is waiting before an unused real connection to a database will be closed and removed from the pool. A value of zero means that the connection has never been closed. The default value is 10 minutes.

Parameters:
poolTimeout - timeout of the unused connection in seconds
See Also:
getPoolTimeout()

getPoolTimeout

public int getPoolTimeout()
Returns timeout of an unused connection in the pool before the connection was closed.

Returns:
the pool timeout in seconds.
See Also:
setPoolTimeout(int)

setMaxConnectionCount

public void setMaxConnectionCount(int max)
Sets the number of maximum connections to be made for the PoolManager. A value of zero means that the connection count is infinite.

Parameters:
max - the number of maximum connections.
See Also:
getMaxConnectionCount()

getMaxConnectionCount

public int getMaxConnectionCount()
Returns the number of possible maximum connections.

Returns:
the number of maximum connections.
See Also:
setMaxConnectionCount(int)

setPoolLoginTimeout

public void setPoolLoginTimeout(int timeout)
Sets the maximum time in seconds that the PoolManager can wait when the maximum number of connections for a DataSource is in use. The default value is 10 sec.

Parameters:
timeout - the timeout in seconds.
See Also:
getPoolLoginTimeout(), setMaxConnectionCount(int), getMaxConnectionCount()

getPoolLoginTimeout

public int getPoolLoginTimeout()
Returns the maximum time in seconds that the PoolManager can wait when the maximum number of connections for a DataSource is in use.

Returns:
the login timeout in seconds.
See Also:
setPoolLoginTimeout(int), setMaxConnectionCount(int), getMaxConnectionCount()

addCommand

public java.lang.Object addCommand(java.lang.String name,
                                   java.lang.String sql)
Adds a new command to the current list. The command is a sql statement stored on the server. The client can access it using the command's name. It allows to execute a sql statement on the client just sending the command's name to the server.
E.g. addCommand("Query 1", "select * from myTable")
or addCommand("insert 1", "insert into table1 values (?,?)")

Parameters:
name - the command's name
sql - the sql statement
Returns:
the previous object (sql statement or Java command) for this command or null if there was no such command.
See Also:
addCommand(String, JavaCommandFactory), getCommand(String), removeCommand(String), removeAllCommands(), setOnlyCommandMode(boolean), getOnlyCommandMode()

addCommand

public java.lang.Object addCommand(java.lang.String name,
                                   JavaCommandFactory cmdFactory)
Adds a new JavaCommandFactory to the command current list. With the JavaCommandFactory you can create JavaCommand(s) that can be executed from the client with the execute method.
With JavaCommand you can execute multiple statements and/or complex business logic on the server just sending the command's name from the client.

Parameters:
name - the command's name
cmdFactory - the Java Command Factory that creates the Java Command.
Returns:
the previous sql statement for this command or null if there was no such command.
See Also:
JavaCommand, JavaCommandFactory, addCommand(String, String), getCommand(String), removeCommand(String), removeAllCommands(), setOnlyCommandMode(boolean), getOnlyCommandMode()

removeCommand

public java.lang.Object removeCommand(java.lang.String name)
Removes the command from the current list.

Parameters:
name - the command's name.
Returns:
a sql statement or a JavaCommand to which this command had been mapped or null if there was no such command.

removeAllCommands

public void removeAllCommands()
Removes all commands from the current list.


getCommand

public java.lang.Object getCommand(java.lang.String name)
Returns the sql statement for this command.

Parameters:
name - the command's name.
Returns:
the sql statement or null if there is no such command.

setOnlyCommandMode

public void setOnlyCommandMode(boolean mode)
If the "only command" mode is enabled then the server will accept commands, only. An exception will be sent to the client if it is trying to use the "normal" sql statement.

Parameters:
mode - true to enable "only command" mode, false to disable.
See Also:
addCommand(String, String)

getOnlyCommandMode

public boolean getOnlyCommandMode()
Returns the current server command mode.

Returns:
true if the "only command mode" is turned on, false otherwise.
See Also:
setOnlyCommandMode(boolean)

setLobToStream

public void setLobToStream(boolean lobToStream)
Sett the flag logToStreams. If this flag is true then all CLOBs and BLOBs are send us stream to the client. This can be faster because fewer network trips are needed. This is slower if you have large LOB objects in a ResultSet and you does not need the data.

Parameters:
lobToStream - the new value

isLobToStream

public boolean isLobToStream()
Get the flag logToStreams.

See Also:
setLobToStream(boolean)

getConnection

public java.sql.Connection getConnection(java.lang.String uds)
                                  throws java.sql.SQLException
Try to make a database connection for the given UserDataSource.

Parameters:
uds - the name of the User Data Source defined on the server.
Returns:
a Connection object.
Throws:
java.sql.SQLException

getDBConnectionCount

public int getDBConnectionCount()
Returns the current number of connections to the databases.

Returns:
number of connections
See Also:
getDBFreeConnectionCount()

getDBConnectionCount

public int getDBConnectionCount(java.lang.String host)
Returns the current number of connections to the databases for a specified host.

Parameters:
host - the host name
Returns:
number of connections
See Also:
getDBFreeConnectionCount()

getDBFreeConnectionCount

public int getDBFreeConnectionCount()
Returns the number of connections to the databases which are currently not in use.

Returns:
number of unused connections
See Also:
getDBConnectionCount()

getConnectedClientCount

public int getConnectedClientCount()
Returns the current number of the connected clients.

Returns:
number of connected clients

getOpenResultSetCount

public int getOpenResultSetCount()
Returns the current number of the ResultSets opened on the server.

Returns:
number of open ResultSets
See Also:
getOpenResultSetCount(String), getOpenStatementCount(), getOpenPreparedStatementCount(), getOpenCallableStatementCount(), getOpenJavaCommandCount()

getOpenResultSetCount

public int getOpenResultSetCount(java.lang.String host)
Returns the current number of the ResultSets opened on the server for a client.

Parameters:
host - the client's host name
Returns:
number of open ResultSets
See Also:
getOpenResultSetCount(), getOpenStatementCount(String), getOpenPreparedStatementCount(String), getOpenCallableStatementCount(String), getOpenJavaCommandCount(String), getConnectedHostNames()

getOpenStatementCount

public int getOpenStatementCount()
Returns the current number of the statements opened on the server.

Returns:
number of open statements
See Also:
getOpenStatementCount(String), getOpenResultSetCount(), getOpenPreparedStatementCount(), getOpenCallableStatementCount(), getOpenJavaCommandCount()

getOpenStatementCount

public int getOpenStatementCount(java.lang.String host)
Returns the current number of the statements opened on the server for a client.

Parameters:
host - the client's host name
Returns:
number of open statements
See Also:
getOpenStatementCount(), getOpenResultSetCount(String), getOpenPreparedStatementCount(String), getOpenCallableStatementCount(String), getOpenJavaCommandCount(String), getConnectedHostNames()

getOpenPreparedStatementCount

public int getOpenPreparedStatementCount()
Returns the current number of the prepared statements opened on the server.

Returns:
number of open prepared statements
See Also:
getOpenPreparedStatementCount(String), getOpenStatementCount(), getOpenResultSetCount(), getOpenCallableStatementCount(), getOpenJavaCommandCount()

getOpenPreparedStatementCount

public int getOpenPreparedStatementCount(java.lang.String host)
Returns the current number of the prepared statements opened on the server for a client.

Parameters:
host - the client's host name
Returns:
number of open prepared statements
See Also:
getOpenPreparedStatementCount(), getOpenResultSetCount(String), getOpenStatementCount(String), getOpenCallableStatementCount(String), getOpenJavaCommandCount(String), getConnectedHostNames()

getOpenCallableStatementCount

public int getOpenCallableStatementCount()
Returns the current number of the callable statements opened on the server.

Returns:
number of open callable statements
See Also:
getOpenCallableStatementCount(String), getOpenStatementCount(), getOpenResultSetCount(), getOpenPreparedStatementCount(), getOpenJavaCommandCount()

getOpenCallableStatementCount

public int getOpenCallableStatementCount(java.lang.String host)
Returns the current number of the callable statements opened on the server for a client.

Parameters:
host - the client's host name
Returns:
number of open callable statements
See Also:
getOpenCallableStatementCount(), getOpenResultSetCount(String), getOpenStatementCount(String), getOpenPreparedStatementCount(String), getOpenJavaCommandCount(String), getConnectedHostNames()

getOpenJavaCommandCount

public int getOpenJavaCommandCount()
Returns the current number of the JavaCommands opened on the server.

Returns:
number of open JavaCommands
See Also:
getOpenStatementCount(), getOpenResultSetCount(), getOpenPreparedStatementCount(), getOpenJavaCommandCount(String)

getOpenJavaCommandCount

public int getOpenJavaCommandCount(java.lang.String host)
Returns the current number of the callable statements opened on the server for a client.

Parameters:
host - the client's host name
Returns:
number of open callable statements
See Also:
getOpenJavaCommandCount(), getOpenCallableStatementCount(String), getOpenResultSetCount(String), getOpenStatementCount(String), getOpenPreparedStatementCount(String), getConnectedHostNames()

getCurrentExecutingCommands

public java.util.Vector getCurrentExecutingCommands()
Returns a list of current executing commands or SQL statements for all clients.

Returns:
a java.util.Vector object containing command names or SQL statements.

getCurrentExecutingCommands

public java.util.Vector getCurrentExecutingCommands(java.lang.String host)
Returns a list of current executing commands or SQL statements for a certain client.

Parameters:
host - the client's host name
Returns:
a java.util.Vector object containing command names or SQL statements.

getOpenedCommands

public java.util.Vector getOpenedCommands()
Returns a list of commands which are opened on the server for all clients. The server logs opened commands only in debug mode.

Returns:
a java.util.Vector object containing command names or SQL statements. If there is no commands opened then an empty vector will be returned.
See Also:
setLogStream(java.io.PrintStream)

getOpenedCommands

public java.util.Vector getOpenedCommands(java.lang.String host)
Returns a list of commands which are opened on the server for specified client. The server logs opened commands only in debug mode.

Parameters:
host - the client's host name
Returns:
a java.util.Vector object containing command names or SQL statements. If there is no commands opened then an empty vector will be returned.
See Also:
getConnectedHostNames(), setLogStream(java.io.PrintStream)

getInitialTime

public long getInitialTime(java.lang.String host)
Returns the initial time of the client's connection.

Parameters:
host - the client's host name.
Returns:
the difference, measured in milliseconds, between the initial time and midnight, January 1, 1970 UTC.

getConnectedHostNames

public java.util.Vector getConnectedHostNames()
Returns a list of the client's host names connected to the server.

Returns:
a java.util.Vector object containing client host names as strings.
See Also:
getConnectedHostNames(String)

getConnectedHostNames

public java.util.Vector getConnectedHostNames(java.lang.String uds)
Returns the list of the client's host names connected to the specified UDS on the server.

Parameters:
uds - the name of the User Data Source to which the client's are connected.
Returns:
a java.util.Vector object contained client's host names as Strings.
See Also:
getConnectedHostNames()

setEnableQueryStatistics

public void setEnableQueryStatistics(boolean enable)
This enable the accumulation of a query statistics. This required Java 1.5. If already enabled then it delete the current statistics.

Parameters:
enable - true to enable.

getQueryStatistics

public java.util.Map getQueryStatistics()
Get the query statistic. A Map of SQL to QueryStatistic

Returns:
the map or null if not enabled

i-net Konnekter


copyright by i-net software