com.wm.app.tn.db
Class DeliveryStore

java.lang.Object
  extended by com.wm.app.tn.db.DeliveryStore

public class DeliveryStore
extends java.lang.Object

API for registering/unregistering delivery service definitions and job entries in the shared database.


Constructor Summary
DeliveryStore()
           
 
Method Summary
static boolean activeJobs()
           
static boolean deleteJob(java.lang.String job_id)
          Remove a job from the database.
static int deleteJobs(DeliveryJobQuery query)
          Delete jobs from the table via a query.
static boolean deleteService(java.lang.String svc_nm)
          Remove a service from the database.
static int deleteServices(DeliveryServiceQuery query)
          Delete services from the table via a query.
static GuaranteedJob dequeueOldestJob(java.lang.String queue)
          Dequeues the oldest job on a virtual delivery queue.
static GuaranteedJob[] dequeueOldestJobs(java.lang.String queue, int jobCount)
          Dequeues jobCount no.
static java.util.Hashtable getActiveJobs()
          Get all active jobs (PENDING or NEW).
static java.util.List getAllPendingServerIds(java.lang.String partnerID)
          This method will get all the serverID's from DeliveryJob tab in which the partnerId is same as the one specified and the job status is 'PENDING'
static GuaranteedJob getAnyJob(java.lang.String id, boolean content)
          Get any job info from any server.
static java.util.Hashtable getDbUpdateFailedJobs()
          For internal use only
static long getDbUpdateRetrySweepTime()
          For internal use only
static GuaranteedJob getJob(java.lang.String id, boolean content)
          Get a job on this server.
static java.lang.Object[] getOrderedActiveJobs()
          Get all active jobs (PENDING or NEW) ordered by creation time.
static DeliveryService getService(java.lang.String name)
          Get service info.
static void init(java.lang.String serverId, boolean force)
          Fills the cache of service definitions and outstanding jobs.
static boolean insertJob(GuaranteedJob j)
          Insert a new delivery job into the database.
static boolean insertService(DeliveryService s)
          Insert a new service definition into the database.
static boolean isDbUpdateNotifyRetries()
          For internal use only
static boolean isDbUpdateRetryEnabled()
          For internal use only
static java.lang.String[] listActiveJobs()
          Returns a list of the job IDs of all ACTIVE delivery jobs marked for this server.
static java.lang.String[] listJobs()
          Returns a list of the job IDs of all delivery jobs marked for this server.
static java.lang.String[] listServices()
          Returns a list of the immediate delivery services defined.
static java.lang.String[] listServices(int type)
          Returns the names of the registered delivery services.
static int numActiveJobs()
           
static com.wm.data.IData queryJobs(DeliveryJobQuery query, int pageSize, int maxRowCount, int queryTimeout, int threshold, java.lang.String queryId)
          Get job information via a query.
static com.wm.data.IData queryServices(DeliveryServiceQuery query, int pageSize, int maxRowCount, int queryTimeout, int threshold, java.lang.String queryId)
          Get service information via a query.
static void refreshJobCache()
          Refresh the job cache due to updates in the DB (useful when in a cluster).
static void refreshServiceCache()
          Refresh the service cache due to updates in the DB (useful when in a cluster).
static void setDbUpdateNotifyRetries(java.lang.String enabled)
          For internal use only
static void setDbUpdateRetryEnabled(java.lang.String enabled)
          For internal use only
static void setDbUpdateRetrySweepTime(java.lang.String seconds)
          For internal use only
static void setUpdaterThreadStarted(boolean flag)
          For internal use only
static void startJobUpdaterThread()
          For internal use only
static boolean updateJob(GuaranteedJob j)
          Update a job in the database.
static boolean updateService(DeliveryService s)
          Update a service in the database.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DeliveryStore

public DeliveryStore()
Method Detail

init

public static void init(java.lang.String serverId,
                        boolean force)
                 throws DatastoreException
Fills the cache of service definitions and outstanding jobs. Also fills the active job cache if there are jobs that didn't complete.

Parameters:
serverId - the ID of this server (used to fetch outstanding job information)
force - forces re-initialization if this method has already been called
Throws:
DatastoreException - if a database error prevents the fetch

activeJobs

public static boolean activeJobs()
Returns:
true if there are active jobs

numActiveJobs

public static int numActiveJobs()
Returns:
number of active jobs

getDbUpdateFailedJobs

public static java.util.Hashtable getDbUpdateFailedJobs()
For internal use only


setDbUpdateRetryEnabled

public static void setDbUpdateRetryEnabled(java.lang.String enabled)
For internal use only


isDbUpdateRetryEnabled

public static boolean isDbUpdateRetryEnabled()
For internal use only


setDbUpdateRetrySweepTime

public static void setDbUpdateRetrySweepTime(java.lang.String seconds)
For internal use only


getDbUpdateRetrySweepTime

public static long getDbUpdateRetrySweepTime()
For internal use only


setDbUpdateNotifyRetries

public static void setDbUpdateNotifyRetries(java.lang.String enabled)
For internal use only


isDbUpdateNotifyRetries

public static boolean isDbUpdateNotifyRetries()
For internal use only


setUpdaterThreadStarted

public static void setUpdaterThreadStarted(boolean flag)
For internal use only


startJobUpdaterThread

public static void startJobUpdaterThread()
For internal use only


listJobs

public static java.lang.String[] listJobs()
Returns a list of the job IDs of all delivery jobs marked for this server.

Returns:
a list of all the IDs (null if there are none)

listActiveJobs

public static java.lang.String[] listActiveJobs()
Returns a list of the job IDs of all ACTIVE delivery jobs marked for this server.

Returns:
a list of all the IDs (null if there are none)

listServices

public static java.lang.String[] listServices(int type)
Returns the names of the registered delivery services.

Parameters:
type - which type of DelvieryServices to return. Must be one of the TYPE values defined in the DeliveryService class.
Returns:
a list of all the service names (null if there are none)
See Also:
DeliveryService

listServices

public static java.lang.String[] listServices()
Returns a list of the immediate delivery services defined.

Returns:
a list of all the service names (null if there are none)

getService

public static DeliveryService getService(java.lang.String name)
Get service info.

Parameters:
name - the name of the service to fetch
Returns:
the service in question (null if there's no such service)

insertService

public static boolean insertService(DeliveryService s)
                             throws DatastoreException
Insert a new service definition into the database. Also adds it to the cache, if the insert was successful.

Parameters:
s - the delivery service to be added
Returns:
was the service added?
Throws:
DatastoreException - if a database error prevented the insert

updateService

public static boolean updateService(DeliveryService s)
                             throws DatastoreException
Update a service in the database. Also updates the cache.

Parameters:
s - the service being updated
Returns:
was the service updated?
Throws:
DatastoreException - if a database error prevented the update

deleteService

public static boolean deleteService(java.lang.String svc_nm)
                             throws DatastoreException
Remove a service from the database. Also updates the cache.

Parameters:
svc_nm - the name of the service to delete
Returns:
was the service deleted?
Throws:
DatastoreException - if a database error prevented the update

queryServices

public static com.wm.data.IData queryServices(DeliveryServiceQuery query,
                                              int pageSize,
                                              int maxRowCount,
                                              int queryTimeout,
                                              int threshold,
                                              java.lang.String queryId)
                                       throws DatastoreException,
                                              java.io.IOException,
                                              com.wm.app.repo.RepositoryException,
                                              com.wm.app.b2b.server.ServiceException
Get service information via a query.

Parameters:
query - the delivery service query to satisfy
pageSize - the number of rows per page; specify -1 to disable paging
maxRowCount - the maximum number of rows to return -- excess rows will be silently dropped. 0 means unlimited
queryTimeout - the maximum number of seconds to wait for the query to return. 0 means unlimited.
threshold - the number of rows to be stored in the session object; this allows you to override the tn.query.threshold parameter in properties.cnf. In a cluster, this should be disabled by setting it to -1. If the value is set to -1, its value from tn.query.threshold parameter in properties.cnf
queryId - specifies the unique identifier to store the paged query results. This is applicable only when the results are paged. If this value is not set, an Id is automatically generated
Returns:
an IData of events satisfying the query (may be empty)
Throws:
DatastoreException - if a database exception prevents getting the query results
java.io.IOException
com.wm.app.repo.RepositoryException
com.wm.app.b2b.server.ServiceException

deleteServices

public static int deleteServices(DeliveryServiceQuery query)
                          throws DatastoreException
Delete services from the table via a query.

Parameters:
query - all delivery services satisfying this query will be deleted
Returns:
how many events were deleted
Throws:
DatastoreException - if a database exception prevents the delete

getActiveJobs

public static java.util.Hashtable getActiveJobs()
Get all active jobs (PENDING or NEW).

Returns:
the active jobs (null if there aren't any)

getOrderedActiveJobs

public static java.lang.Object[] getOrderedActiveJobs()
Get all active jobs (PENDING or NEW) ordered by creation time.

Returns:
the active jobs (null if there aren't any)

getAnyJob

public static GuaranteedJob getAnyJob(java.lang.String id,
                                      boolean content)
Get any job info from any server. Intended for admin level. If checking for jobs on your own server you should use getJob.

Parameters:
id - the id of the job to fetch
content - indicate whether or not to retrieve the content of the associated bizdoc
Returns:
the job in question (null if there's no such job)

getJob

public static GuaranteedJob getJob(java.lang.String id,
                                   boolean content)
Get a job on this server. Use getAnyJob if server ID does not matter.

Parameters:
id - the id of the job to fetch
content - indicate whether or not to retrieve the content of the associated bizdoc
Returns:
the job in question (null if there's no such job on this server)

insertJob

public static boolean insertJob(GuaranteedJob j)
                         throws DatastoreException
Insert a new delivery job into the database. Also adds it to the cache, if the insert was successful.

Parameters:
j - the delivery job to be added
Returns:
was the job added?
Throws:
DatastoreException - if a database error prevented the insert

updateJob

public static boolean updateJob(GuaranteedJob j)
                         throws DatastoreException
Update a job in the database. Also updates the cache.

Parameters:
j - the job being updated
Returns:
was the job updated?
Throws:
DatastoreException - if a database error prevented the update

dequeueOldestJob

public static GuaranteedJob dequeueOldestJob(java.lang.String queue)
                                      throws DeliveryException
Dequeues the oldest job on a virtual delivery queue. This is done by changing the job status from QUEUED to DELIVERING. If the receiver is inactive, the job is FAILed and the next job is dequeued.

Parameters:
queue - the virtual queue to dequeue from
Returns:
the oldest QUEUED job on a virtual delivery queue
Throws:
com.wm.app.tn.db.DeliveryException - if a database error prevented the operation
DeliveryException

dequeueOldestJobs

public static GuaranteedJob[] dequeueOldestJobs(java.lang.String queue,
                                                int jobCount)
Dequeues jobCount no. of oldest jobs on a virtual delivery queue. This is done by changing the job status from QUEUED to DELIVERING. If the receiver is inactive, the job is FAILed and the next job is dequeued.

Parameters:
queue - the virtual queue to dequeue from
Returns:
the oldest QUEUED job on a virtual delivery queue
Throws:
com.wm.app.tn.db.DeliveryException - if a database error prevented the operation

deleteJob

public static boolean deleteJob(java.lang.String job_id)
                         throws DatastoreException
Remove a job from the database. Also updates the cache.

Parameters:
job_id - the id of the job to delete
Returns:
was the job deleted?
Throws:
DatastoreException - if a database error prevented the update

queryJobs

public static com.wm.data.IData queryJobs(DeliveryJobQuery query,
                                          int pageSize,
                                          int maxRowCount,
                                          int queryTimeout,
                                          int threshold,
                                          java.lang.String queryId)
                                   throws DatastoreException,
                                          java.io.IOException,
                                          com.wm.app.repo.RepositoryException,
                                          com.wm.app.b2b.server.ServiceException
Get job information via a query.

Parameters:
query - the delivery job query to satisfy
pageSize - the number of rows per page; specify -1 to disable paging
maxRowCount - the maximum number of rows to return -- excess rows will be silently dropped. 0 means unlimited
queryTimeout - the maximum number of seconds to wait for the query to return. 0 means unlimited.
threshold - the number of rows to be stored in the session object; this allows you to override the tn.query.threshold parameter in properties.cnf. In a cluster, this should be disabled by setting it to -1. If the value is set to -1, its value from tn.query.threshold parameter in properties.cnf
queryId - specifies the unique identifier to store the paged query results. This is applicable only when the results are paged. If this value is not set, an Id is automatically generated
Returns:
an IData of events satisfying the query (may be empty)
Throws:
DatastoreException - if a database exception prevents getting the query results
java.io.IOException
com.wm.app.repo.RepositoryException
com.wm.app.b2b.server.ServiceException

deleteJobs

public static int deleteJobs(DeliveryJobQuery query)
                      throws EXMLException
Delete jobs from the table via a query.

Parameters:
query - all delivery jobs satisfying this query will be deleted
Returns:
how many events were deleted
Throws:
DatastoreException - if a database exception prevents the delete
EXMLException

refreshJobCache

public static void refreshJobCache()
                            throws DatastoreException
Refresh the job cache due to updates in the DB (useful when in a cluster).

Throws:
DatastoreException - if a database exception prevents the refresh

refreshServiceCache

public static void refreshServiceCache()
                                throws DatastoreException
Refresh the service cache due to updates in the DB (useful when in a cluster).

Throws:
DatastoreException - if a database exception prevents the refresh

getAllPendingServerIds

public static java.util.List getAllPendingServerIds(java.lang.String partnerID)
                                             throws java.sql.SQLException
This method will get all the serverID's from DeliveryJob tab in which the partnerId is same as the one specified and the job status is 'PENDING'

Parameters:
partnerID - Id of the partner to serarch
Returns:
Throws:
java.sql.SQLException