public interface ServerContext
Allows a
ServerChannel
to communicate with its container.-
Method Summary
Modifier and TypeMethodDescriptionvoid
addDelayedEvent
(DeplayedEvent event) Adds a delayed event to this queue of delayed events.void
addPendingReply
(PendingReply pendingReply) Adds the supplied pending reply to a shared table that is accessible to all threads controlled by the server context of this channel.Returns next available Waiter creating one if necessary.decodePassword
(String encoded, String username, String context) Decodes an encoded password using supplied arguments.<T> T
executeJsch
(String poolName, String serverName, String execName, JschExecutor<T> executor) Allocates a connected Jsch (Java Secure Channel) session from the specified pool and then executes the supplied executor.<T> T
executeSocket
(String poolName, String serverName, String execName, SocketExecutor<T> executor) Allocates a socket from the specified pool and then executes the supplied socket executor.<T> T
executeSQL
(String poolName, String serverName, String execName, SQLExecutor<T> executor) Allocates a connection from the specified pool and then executes the supplied SQL executor.<T> T
executeTask
(String serverName, String taskName, Callable<T> task) Executes supplied task mantaining statistics indexed by tag.getExecutionStats
(String serviceName) Returns the execution statistics of the specified service.int
Returns the unique process identification of the server channel.Returns an unmodifiable map with all the properties of this context.getProperty
(String name) Returns the value of the property indexed by specified name.void
releaseWaiter
(Waiter waiter) Release the supplied Waiter and add it back to the pool.boolean
removeDelayedEvent
(DeplayedEvent event) Removes a delayed event from this queue of delayed events.void
removeExecutionStats
(String serviceName) Removes the execution statistics of the specified service.removePendingReply
(String replyKey) Removes and returns the pending reply indexed by given key.void
runAsyncTask
(Runnable task) Executes the given task asynchronously in a separate thread.void
Sends a mail message using the specified SMTP mail session.
-
Method Details
-
getProcessID
int getProcessID()Returns the unique process identification of the server channel.- Returns:
- the unique process identification of the server channel.
-
getExecutionStats
Returns the execution statistics of the specified service.- Parameters:
serviceName
- the name of the service.- Returns:
- the execution statistics of the specified service.
- Throws:
NullPointerException
- ifserviceName
isnull
.
-
removeExecutionStats
Removes the execution statistics of the specified service.- Parameters:
serviceName
- the name of the service.- Throws:
NullPointerException
- ifserviceName
isnull
.
-
getProperties
Returns an unmodifiable map with all the properties of this context.- Returns:
- an unmodifiable map with all the properties of this context.
-
getProperty
Returns the value of the property indexed by specified name. If the property is not defined, it returnsnull
.- Parameters:
name
- the name of the required property.- Returns:
- the value of the property or
null
if not defined. - Throws:
NullPointerException
- ifname
isnull
.
-
runAsyncTask
Executes the given task asynchronously in a separate thread.- Parameters:
task
- the task to be executed in a separate thread.- Throws:
NullPointerException
- iftask
isnull
.IllegalStateException
- if the thread pool is not available.RejectedExecutionException
- if the task cannot be executed.
-
allocateWaiter
Waiter allocateWaiter()Returns next available Waiter creating one if necessary.- Returns:
- the next available Waiter creating one if necessary.
-
releaseWaiter
Release the supplied Waiter and add it back to the pool.- Parameters:
waiter
- the Waiter to be returned back to the pool.- Throws:
NullPointerException
- ifwaiter
isnull
.
-
executeSQL
<T> T executeSQL(String poolName, String serverName, String execName, SQLExecutor<T> executor) throws SQLException, Exception Allocates a connection from the specified pool and then executes the supplied SQL executor. If the SQL executor returns normally, the connection is committed. If the SQL executor throws an exception, the connection is rollback. In any event, the connection is returned to the pool.- Type Parameters:
T
- the type of the value returned by theexecutor
.- Parameters:
poolName
- the name of the connection pool.serverName
- the name of the server of theexecutor
.execName
- the name of theexecutor
(can be null).executor
- an SQL statement executor.- Returns:
- the value returned by the
executor
. - Throws:
NullPointerException
- if an argument isnull
.SQLException
- if an SQL error occurs.Exception
- if another error occurs.
-
executeJsch
<T> T executeJsch(String poolName, String serverName, String execName, JschExecutor<T> executor) throws Exception Allocates a connected Jsch (Java Secure Channel) session from the specified pool and then executes the supplied executor. If the Jsch executor throws an exception, the Jsch session is closed and not returned to the pool.- Type Parameters:
T
- the type of the value returned by theexecutor
.- Parameters:
poolName
- the name of the Jsch (Java Secure Channel) pool.serverName
- the name of the server of theexecutor
.execName
- the name of theexecutor
(can be null).executor
- the Jsch executor to be executed.- Returns:
- the value returned by the
executor
. - Throws:
NullPointerException
- if an argument isnull
.Exception
- if another error occurs.
-
executeSocket
<T> T executeSocket(String poolName, String serverName, String execName, SocketExecutor<T> executor) throws IOException, Exception Allocates a socket from the specified pool and then executes the supplied socket executor. If the socket executor throws anIOException
, the socket is closed and not returned to the pool. If the socket executor terminates successfully, or if it throws any other exception, the socket is returned to the pool.- Type Parameters:
T
- the type of the value returned by theexecutor
.- Parameters:
poolName
- the name of the socket pool.serverName
- the name of the server of theexecutor
.execName
- the name of theexecutor
(can be null).executor
- the socket executor to be executed.- Returns:
- the value returned by the
executor
. - Throws:
NullPointerException
- if an argument isnull
.IOException
- if an I/O error occurs.Exception
- if another error occurs.
-
executeTask
Executes supplied task mantaining statistics indexed by tag.- Type Parameters:
T
- the type of the value returned by thetask
.- Parameters:
serverName
- the name of the server of thetask
.taskName
- the name of thetask
(can be null).task
- the task callable to be executed.- Returns:
- the value returned by the
task
. - Throws:
NullPointerException
- if an argument isnull
.Exception
- if an error occurs executingtask
.
-
addPendingReply
Adds the supplied pending reply to a shared table that is accessible to all threads controlled by the server context of this channel.- Parameters:
pendingReply
- the pending reply to be added to the table.- Throws:
NullPointerException
- ifpendingReply
isnull
.IllegalArgumentException
- if pending reply key is already defined.
-
removePendingReply
Removes and returns the pending reply indexed by given key. The returned pending reply is removed from a shared table that is accessible to all threads controlled by this context.- Parameters:
replyKey
- the globally unique identifier of the required reply.- Returns:
- a pending reply or
null
if none registered. - Throws:
NullPointerException
- ifreplyKey
isnull
.
-
addDelayedEvent
Adds a delayed event to this queue of delayed events.- Parameters:
event
- the delayed event to be added to the event queue.- Throws:
NullPointerException
- ifentry
isnull
.
-
removeDelayedEvent
Removes a delayed event from this queue of delayed events.- Parameters:
event
- the delayed event to be removed to the event queue.- Returns:
true
if the event was removed from the queue.- Throws:
NullPointerException
- ifevent
isnull
.
-
sendMail
Sends a mail message using the specified SMTP mail session.- Parameters:
serverName
- the name of the server sending mail.sessionName
- the name of the mail session.subject
- the subject of the mail message.text
- the text of the mail message.- Throws:
NullPointerException
- if an argument isnull
.Exception
- if another error occurs.
-
decodePassword
Decodes an encoded password using supplied arguments.- Parameters:
encoded
- the password to be decoded.username
- the username of the password.context
- the name of context using password.- Returns:
- the password decoded using supplied arguments.
- Throws:
NullPointerException
- if an argument isnull
.Exception
- if another error occurs.
-