Class JMSJobFactory
- java.lang.Object
-
- com.levigo.jadice.server.jms.client.JMSJobFactory
-
- All Implemented Interfaces:
JobFactory
,AutoCloseable
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 implementsAutoCloseable
it can be used in conjunction with thetry
-with-resources statement.
-
-
Field Summary
Fields Modifier and Type Field 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.
-
Constructor Summary
Constructors Constructor Description JMSJobFactory(javax.jms.QueueConnectionFactory connectionFactory, String queueName)
Create a newJMSJobFactory
with the given JMSQueueConnectionFactory
,Credentials
and the given request queue name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 beforeJob
s can be createdJob
createJob()
Create a job for the specifiedQueueConnectionFactory
and the given default values (see the "see also" section).protected void
finalize()
long
getCommunicationTimeout()
Credentials
getCredentials()
int
getDefaultPriority()
int
getKeepAliveMsgPriority()
long
getSubmissionTimeout()
boolean
isSessionAlreadyClosed()
Indicates whether the JMS QueueSession is already closed.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
setKeepAliveMsgPriority(int keepAliveMsgPriority)
void
setSubmissionTimeout(long submissionTimeout)
Set the default job submission timeout (ms).
-
-
-
Field Detail
-
DEFAULT_TIMEOUT
public static final long DEFAULT_TIMEOUT
- See Also:
- Constant Field Values
-
DEFAULT_PRIORITY
public static final int DEFAULT_PRIORITY
- See Also:
- Constant Field Values
-
DEFAULT_QUEUE_NAME
public static final String DEFAULT_QUEUE_NAME
The default name of the JMS request queue.- See Also:
- Constant Field Values
-
PROPERTY_KEY_SUBMISSION_TIMEOUT
public static final String PROPERTY_KEY_SUBMISSION_TIMEOUT
Property key for the submission timeout. Associated value must be an Integer.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.- See Also:
- Constant Field Values
-
PROPERTY_KEY_COMMUNICATION_TIMEOUT
public static final String PROPERTY_KEY_COMMUNICATION_TIMEOUT
Property key for the communication timeout. Associated value must be an Integer.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.
- See Also:
- Constant Field Values
-
PROPERTY_KEY_PRIORITY
public static final String PROPERTY_KEY_PRIORITY
Property key for the priority. Associated value must be an Integer.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JMSJobFactory
public JMSJobFactory(javax.jms.QueueConnectionFactory connectionFactory, String queueName)
Create a newJMSJobFactory
with the given JMSQueueConnectionFactory
,Credentials
and the given request queue name.- Parameters:
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.- See Also:
DEFAULT_QUEUE_NAME
-
-
Method Detail
-
isSessionAlreadyClosed
public boolean isSessionAlreadyClosed()
Indicates whether the JMS QueueSession is already closed. If closed this instance cannot be used for JMS connections anymore.- Returns:
- true if this instance cannot be used anymore since its session is already closed, false otherwise.
-
createJob
public Job createJob() throws JobException
Create a job for the specifiedQueueConnectionFactory
and the given default values (see the "see also" section).- Specified by:
createJob
in interfaceJobFactory
- Returns:
- a pre-configured job
- Throws:
JobException
- ifJob
creation failed- See Also:
getDefaultPriority()
,PROPERTY_KEY_COMMUNICATION_TIMEOUT
-
adopt
public void adopt(com.levigo.jadice.server.client.internal.DefaultJobInternalImpl job) throws JobException
- Specified by:
adopt
in interfaceJobFactory
- Throws:
JobException
-
getDefaultPriority
public int getDefaultPriority()
- Returns:
- the default priority.
-
setDefaultPriority
public void setDefaultPriority(int defaultPriority)
Set the default priority for jobs. Job priorities follow the JMS message priorities. The priority may be set on a per-job basis usingJob.putProperty(String, java.io.Serializable)
with the keyPROPERTY_KEY_PRIORITY
and an integer value for the priority.- Parameters:
defaultPriority
-numeric default priority
- See Also:
MessageProducer.setPriority(int)
,PROPERTY_KEY_PRIORITY
,DEFAULT_PRIORITY
-
getSubmissionTimeout
public long getSubmissionTimeout()
- Returns:
- the job submission timeout.
-
setSubmissionTimeout
public void setSubmissionTimeout(long submissionTimeout)
Set the default job submission timeout (ms). The submission timeout may be set on a per-job basis usingJob.putProperty(String, java.io.Serializable)
with the keyPROPERTY_KEY_SUBMISSION_TIMEOUT
and an integer value for the timeout.- Parameters:
submissionTimeout
-Job
submission timeout in milliseconds (ms)- See Also:
DEFAULT_TIMEOUT
,PROPERTY_KEY_SUBMISSION_TIMEOUT
-
getCommunicationTimeout
public long getCommunicationTimeout()
-
setCommunicationTimeout
public void setCommunicationTimeout(long communicationTimeout)
Set the default 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.
- Parameters:
communicationTimeout
- communication timeout in milliseconds (ms)- See Also:
DEFAULT_TIMEOUT
,PROPERTY_KEY_COMMUNICATION_TIMEOUT
-
close
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 anIllegalStateException
.Caveat: This method shall not be called while
Job
s created by this instance are running!- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceJobFactory
-
connect
public void connect() throws ConnectionException
Description copied from interface:JobFactory
Performs all actions that are required beforeJob
s can be created- Specified by:
connect
in interfaceJobFactory
- Throws:
ConnectionException
- if the connection to the underlying communication infrastructure could not be established
-
finalize
protected void finalize() throws Throwable
-
getCredentials
public Credentials getCredentials()
- Returns:
- Credentials that are used for establishing a JMS connection.
- Since:
- jadice server 5.4.0.0
- See Also:
ConnectionFactory.createConnection(String, String)
-
setCredentials
public void setCredentials(Credentials credentials)
Set credentials that are used for establishing a JMS connection.- Parameters:
credentials
- username and password- Throws:
IllegalStateException
- if the connection to JMS has already been established withconnect()
.- Since:
- jadice server 5.4.0.0
- See Also:
ConnectionFactory.createConnection(String, String)
-
setKeepAliveMsgPriority
public void setKeepAliveMsgPriority(int keepAliveMsgPriority)
-
getKeepAliveMsgPriority
public int getKeepAliveMsgPriority()
-
-