public class LowLevelSocketListenerImpl extends java.lang.Object implements LowLevelSocketListener, SessionListener
Modifier and Type | Class and Description |
---|---|
private static class |
LowLevelSocketListenerImpl.ConnectListener
Start a loop in a different thread and listen for incoming connections.
|
private static class |
LowLevelSocketListenerImpl.ServerSocketData
Container of various server-socket related data.
|
Modifier and Type | Field and Description |
---|---|
private static LowLevelSocketListenerImpl |
instance
The single instance available of this class.
|
private static java.lang.String |
keyStorePassword
The password for access to server-side SSL certificate store.
|
private static java.util.logging.Logger |
LOG
Logger
|
private static java.lang.Object |
modToken
Token used to authenticate with the dispatcher when registering APIs.
|
private static ContextLocal<java.util.Map<java.lang.Integer,LowLevelSocketListenerImpl.ServerSocketData>> |
sockets
The context-local data of this class: a registry of server sockets by their ID.
|
Modifier | Constructor and Description |
---|---|
private |
LowLevelSocketListenerImpl()
Private c'tor, to not allow explicit usage of this class.
|
Modifier and Type | Method and Description |
---|---|
boolean |
disableConnections(int id)
Terminates the listening loop for this server socket.
|
int |
enableConnections(long resourceId,
int port,
int qsize)
Create a server socket and let it listen on the given port.
|
int |
enableSSLConnections(long resourceId,
int port,
int qsize,
java.lang.String keyalias,
java.lang.String keyaliaspasswd,
boolean nosessioncache,
int sessiontimeout)
Create a SSL server socket and let it listen on the given port.
|
static void |
initialize(BootstrapConfig cfg,
Session session,
boolean single)
Initialize the client-side socket support:
export the singleton instance of this class as a network server;
initialize server side SSL by setting keystore access password.
|
void |
initialize(Session session)
This callback will be called after the security context has been set up.
|
void |
terminate(Session session)
When the P2J client session is ending, terminate all active server sockets.
|
private static final java.util.logging.Logger LOG
private static java.lang.Object modToken
private static ContextLocal<java.util.Map<java.lang.Integer,LowLevelSocketListenerImpl.ServerSocketData>> sockets
private static final LowLevelSocketListenerImpl instance
private static java.lang.String keyStorePassword
private LowLevelSocketListenerImpl()
public static void initialize(BootstrapConfig cfg, Session session, boolean single)
cfg
- The configuration to use for setup of the client.session
- The P2J session. May be null
if running in embedded mode.single
- true
to startup within the server process which must bypass the
shared infrastructure initialization. Use false
for the normal client
JVM startup.public int enableConnections(long resourceId, int port, int qsize) throws java.io.IOException
enableConnections
in interface LowLevelSocketListener
resourceId
- The ID of the associated SocketImpl
resource on server side.port
- The port number.qsize
- The backlog size for this socket.LowLevelSocketListenerImpl
instance when
the connection was established.java.io.IOException
- In case of errors while starting the server.public int enableSSLConnections(long resourceId, int port, int qsize, java.lang.String keyalias, java.lang.String keyaliaspasswd, boolean nosessioncache, int sessiontimeout) throws java.io.IOException, java.security.GeneralSecurityException
Following are some findings/implementation notes:
nosessioncache
- this disables the SSL session cache. To emulate this, we use
SSLSessionContext.setSessionCacheSize(int)
to set the cache size to 1;essiontimeout
- represents "The maximum amount of time, in seconds, that the
server waits before it rejects a SSL client's request to resume a session. The
default value is 180 seconds." This parameter looks like is something which should
be set by the client and not by the server, as (CA thinking) it means "if client is
idle more than x seconds, than terminate connection". SSLSessionContext.setSessionTimeout(int)
to invalidate the the
SSLSession
object so future connections cannot resume the SSL session;<DLC>/keys
folder. These files are in ASCII PEM
format and include both the key and the certificate. Similarly, we store each alias
in separate store files, similar to 4GL, however, the format differ and the keys/
certificates must be imported (but keeping same name);default_server
key with the default password set to
password
. This is used when connecting in SSL mode, but no key alias or
password is specified in the connection string. The default values were automatically
selected on P2J server-side before calling this method;keyaliaspasswd
option in ENABLE-CONNECTIONS is
encrypted in the 4GL source code, but it was already decrypted before passing it in
as argument.enableSSLConnections
in interface LowLevelSocketListener
resourceId
- The ID of the associated SocketImpl
resource on server side.port
- The port number.qsize
- The backlog size for this socket.keyalias
- The alias for the digital certificate.keyaliaspasswd
- The password for the key of the digital certificate.nosessioncache
- Flag indicating the SSL client session cache is disabled.sessiontimeout
- The number of seconds before the SSL client request is timeout.LowLevelSocketListenerImpl
instance when
the connection was established.java.io.IOException
- In case of errors while starting the server socket.java.security.GeneralSecurityException
- In case of SSL-related errors while starting the server socket.public boolean disableConnections(int id)
disableConnections
in interface LowLevelSocketListener
id
- The ID of LowLevelSocketImpl
instance on P2J Client side.true
if no errors were encountered during disconnect.public void terminate(Session session)
terminate
in interface SessionListener
session
- The session that is ending.public void initialize(Session session)
initialize
in interface SessionListener
session
- The session that is starting.