public class LimitedBlockingPolicy extends java.lang.Object implements BlockingPolicy
BlockingPolicy
, the blocking is limited by a maximum
waiting time. Thus, unlimited blocking is prevented.
More concretely, if no timeout is specified by the user, timeout
is
returned.
If at creation of this policy no timeout is specified, a default one is set:
DEFAULT_TIMEOUT
(= 60L seconds).
Modifier and Type | Field and Description |
---|---|
static long |
DEFAULT_TIMEOUT
Default timeout (in seconds) set by this policy at creation if none is
specified.
|
protected long |
timeout
Maximum blocking duration (in seconds).
|
Constructor and Description |
---|
LimitedBlockingPolicy()
Build a blocking policy with the default timeout
(= 60L seconds).
|
LimitedBlockingPolicy(long timeout)
Build a
BlockingPolicy which will limit blocking duration to the
given value. |
Modifier and Type | Method and Description |
---|---|
long |
block(java.lang.Thread thread,
long userDuration,
UWSJob job,
JobOwner user,
javax.servlet.http.HttpServletRequest request)
Notify this
BlockingPolicy that the given thread is going to
be blocked for the specified duration. |
void |
unblocked(java.lang.Thread unblockedThread,
UWSJob job,
JobOwner user,
javax.servlet.http.HttpServletRequest request)
Notify this
BlockingPolicy that the given thread is not blocked
anymore. |
public static final long DEFAULT_TIMEOUT
protected long timeout
DEFAULT_TIMEOUT
.public LimitedBlockingPolicy()
public LimitedBlockingPolicy(long timeout)
BlockingPolicy
which will limit blocking duration to the
given value.
IMPORTANT:
If timeout
is < 0, the default timeout
(i.e. 60L) will be set automatically by this
constructor.
timeout
- Maximum blocking duration (in seconds).public long block(java.lang.Thread thread, long userDuration, UWSJob job, JobOwner user, javax.servlet.http.HttpServletRequest request)
BlockingPolicy
BlockingPolicy
that the given thread is going to
be blocked for the specified duration. This function then decides how
long the given thread must really wait before resuming.
The parameter "userDuration" and the returned value are durations expressed in seconds. Both follow the same rules:
Since a timeout or another special behavior may be chosen by this
BlockingPolicy
, the returned value may be different from the
user's asked duration. The value that should be taken into account is
obviously the returned one.
IMPORTANT:
This function may UNblock an older request/thread, in function of
the strategy chosen/implemented by this BlockingPolicy
.
block
in interface BlockingPolicy
thread
- Thread that is going to be blocked.
MUST NOT be NULL. If NULL this function will
either do nothing and return 0 (no blocking)
or throw a NullPointerException
.userDuration
- Waiting duration (in seconds) asked by the user.
< 0 means indefinite, 0 means no wait and
> 0 means waiting for the specified amount of
seconds.job
- The job associated with the thread.
Should not be NULL.user
- The user who asked for the blocking behavior.
If NULL, the request will be concerned as
anonymous and a decision to identify the user
(e.g. use the IP address) may be chosen by the
BlockingPolicy
implementation if
required.request
- The request which is going to be blocked.
Should not be NULL.public void unblocked(java.lang.Thread unblockedThread, UWSJob job, JobOwner user, javax.servlet.http.HttpServletRequest request)
BlockingPolicy
BlockingPolicy
that the given thread is not blocked
anymore.unblocked
in interface BlockingPolicy
unblockedThread
- Thread that is not blocked any more.
MUST be NOT NULL.job
- The job associated with the unblocked Thread.
Should not be NULL.user
- The user who originally asked for the blocking
behavior.
If NULL, the request will be concerned as
anonymous and a decision to identify the user
(e.g. use the IP address) may be chosen by the
BlockingPolicy
implementation if
required.request
- The request which has been unblocked.
Should not be NULL.