public class JMSJobFactory extends Object implements JobFactory, AutoCloseable
JobFactory
implementation using the Java Messaging Service API (JMS).
Instances of this class will automatically establish a JMS connection at construction time. In
order to release these resources the close()
method shall be called when this instance is
not needed anymore. Since it implements AutoCloseable
it can be used in conjunction with the
try
-with-resources statement.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_PRIORITY |
static String |
DEFAULT_QUEUE_NAME
The default name of the JMS request queue.
|
static long |
DEFAULT_TIMEOUT |
static String |
PROPERTY_KEY_COMMUNICATION_TIMEOUT
Property key for the communication timeout.
|
static String |
PROPERTY_KEY_PRIORITY
Property key for the priority.
|
static String |
PROPERTY_KEY_SUBMISSION_TIMEOUT
Property key for the submission timeout.
|
PROPERTY_KEY_EXECUTION_TIMEOUT
Constructor and Description |
---|
JMSJobFactory(javax.jms.QueueConnectionFactory connectionFactory,
String queueName)
Create a new
JMSJobFactory with the given JMS QueueConnectionFactory , Credentials
and the given request queue name. |
Modifier and Type | Method and Description |
---|---|
void |
adopt(com.levigo.jadice.server.client.internal.DefaultJobInternalImpl job) |
void |
close()
Closes the JMS connection to jadice server and releases the JMS resources held by it.
|
void |
connect()
Performs all actions that are required before
Job s can be created |
Job |
createJob()
Create a job for the specified
QueueConnectionFactory and the
given default values (see the "see also" section). |
protected void |
finalize() |
long |
getCommunicationTimeout() |
Credentials |
getCredentials() |
int |
getDefaultPriority() |
long |
getSubmissionTimeout() |
void |
setCommunicationTimeout(long communicationTimeout)
Set the default communication timeout.
|
void |
setCredentials(Credentials credentials)
Set credentials that are used for establishing a JMS connection.
|
void |
setDefaultPriority(int defaultPriority)
Set the default priority for jobs.
|
void |
setSubmissionTimeout(long submissionTimeout)
Set the default job submission timeout (ms).
|
public static final long DEFAULT_TIMEOUT
public static final int DEFAULT_PRIORITY
public static final String DEFAULT_QUEUE_NAME
public static final String PROPERTY_KEY_SUBMISSION_TIMEOUT
If a job has not been accepted by a server by the specified timeout,
submission will fail. If the timeout is 0, the default timeout (as defined
by the JobFactory
) is used, if the timeout is < 0, it will wait
indefinitely for acceptance.
public static final String PROPERTY_KEY_COMMUNICATION_TIMEOUT
If there has been no JMS communication activity on a channel for the time specified by the timeout, the communication is supposed to be dead. This applies to both sides of the communication. If the timeout is <= 0, the default timeout is used.
NB: The minimum timeout accepted by the server is 1000ms.
public static final String PROPERTY_KEY_PRIORITY
public JMSJobFactory(javax.jms.QueueConnectionFactory connectionFactory, String queueName)
JMSJobFactory
with the given JMS QueueConnectionFactory
, Credentials
and the given request queue name.connectionFactory
- the JMS connection factory to use. Must not be null.queueName
- the name of the request queue, default is "JS.REQUEST". Must
not be null.javax.jms.JMSException
- if connection to JMS could not be establishedDEFAULT_QUEUE_NAME
public Job createJob() throws JobException
QueueConnectionFactory
and the
given default values (see the "see also" section).createJob
in interface JobFactory
JobException
getDefaultPriority()
,
PROPERTY_KEY_COMMUNICATION_TIMEOUT
public void adopt(com.levigo.jadice.server.client.internal.DefaultJobInternalImpl job) throws JobException
adopt
in interface JobFactory
JobException
public int getDefaultPriority()
public void setDefaultPriority(int defaultPriority)
Job.putProperty(String, java.io.Serializable)
with the key
PROPERTY_KEY_PRIORITY
and an integer value for the priority.defaultPriority
- MessageProducer.setPriority(int)
,
PROPERTY_KEY_PRIORITY
,
DEFAULT_PRIORITY
public long getSubmissionTimeout()
public void setSubmissionTimeout(long submissionTimeout)
Job.putProperty(String, java.io.Serializable)
with the key
PROPERTY_KEY_SUBMISSION_TIMEOUT
and an integer value for the
timeout.submissionTimeout
- DEFAULT_TIMEOUT
,
PROPERTY_KEY_SUBMISSION_TIMEOUT
public long getCommunicationTimeout()
public void setCommunicationTimeout(long communicationTimeout)
If there has been no JMS communication activity on a channel for the time specified by the timeout, the communication is supposed to be dead. This applies to both sides of the communication.
communicationTimeout
- DEFAULT_TIMEOUT
,
PROPERTY_KEY_COMMUNICATION_TIMEOUT
public void close()
Closes the JMS connection to jadice server and releases the JMS resources held by it.
Afterwards this JMSJobFactory
must not be used anymore. Any successive calls will throw
an IllegalStateException
.
Caveat: This method shall not be called while Job
s created by this instance
are running!
close
in interface JobFactory
close
in interface AutoCloseable
public void connect() throws ConnectionException
JobFactory
Job
s can be createdconnect
in interface JobFactory
ConnectionException
- if the connection to the underlying communication infrastructure
could not be establishedprotected void finalize() throws Throwable
public Credentials getCredentials()
ConnectionFactory.createConnection(String, String)
public void setCredentials(Credentials credentials)
jmsCredentials
- username and passwordIllegalStateException
- if the connection to JMS has already been established with connect()
.ConnectionFactory.createConnection(String, String)
Copyright © 2017 levigo holding gmbh. All rights reserved.