com.atlassian.jira.service
Class JiraServiceContainerImpl

java.lang.Object
  extended by com.atlassian.jira.service.JiraServiceContainerImpl
All Implemented Interfaces:
ObjectConfigurable, JiraService, JiraServiceContainer, Runnable

public class JiraServiceContainerImpl
extends Object
implements JiraServiceContainer

Proxies calls to JiraService and manages delay between calls.


Field Summary
 
Fields inherited from interface com.atlassian.jira.service.JiraService
NAME_COMPARATOR
 
Constructor Summary
JiraServiceContainerImpl(JiraService service, Long id)
           
 
Method Summary
 void destroy()
          This method is called when the service is unloaded (usually when the web application or server is being shut down).
 String getDefaultProperty(String propertyKey)
          Returns the default property value for a key
 long getDelay()
          The length of delay in milliseconds between runs of this service.
 String getDescription()
          A textual description of the service.
 Long getId()
           
 String getKey()
          Return the key of this object
 long getLastRun()
          The time that this service was last run.
 Long getLongProperty(String propertyKey)
          Returns a property of this object with the specified key as a long
 String getName()
          A textual name of the service as entered by the user from the web interface.
 ObjectConfiguration getObjectConfiguration()
          Retrieves an object configuration object with properties that can be set
 com.opensymphony.module.propertyset.PropertySet getProperties()
          Retrieve all the specified Properties for this object
 String getProperty(String propertyKey)
          Returns a property of this object with the specified key
 String getServiceClass()
           
 Class getServiceClassObject()
           
 String getTextProperty(String propertyKey)
          Returns a property of this object with the specified key, the property is of type text
 boolean hasProperty(String propertyKey)
          Checks if this object has a particular property
 void init(com.opensymphony.module.propertyset.PropertySet props)
          Initialise the service.
 boolean isDueAt(long time)
          Is this service due to run at the specified time.
 boolean isInternal()
          Indicates whether administrators can delete this service from within the web interface.
 boolean isRunning()
          Whether a service is currently running.
 boolean isUnique()
          Whether this service class should be unique.
 boolean isUsable()
           
 void run()
          Perform the action of this service.
 void setDelay(long delay)
          Sets the delay between invocation of each service.
 void setLastRun()
          Set the last run time to be the current time.
 void setName(String name)
          Used to set the service's name.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JiraServiceContainerImpl

public JiraServiceContainerImpl(JiraService service,
                                Long id)
Method Detail

init

public void init(com.opensymphony.module.propertyset.PropertySet props)
          throws ObjectConfigurationException
Description copied from interface: JiraService
Initialise the service. This method is guaranteed to be called before the first call to run().

As the parameters are gained from the user's interaction with the website, it is not guaranteed to be called with the correct, or indeed with any parameters.

init() may be called multiple times during the services lifetime.

Specified by:
init in interface JiraService
Parameters:
props - initialisation parameters
Throws:
ObjectConfigurationException - in case of an error with initialisation parameters

run

public void run()
Perform the action of this service. The caller of this method assumes that no housekeeping has been done, and will call setLastRun() after the run() method.

init() is guaranteed to be called before run(), but the parameters passed to init() are not guaranteed to be correct. Any parameters expected to be set by init() should be checked in this method upon each invocation.

Specified by:
run in interface JiraService
Specified by:
run in interface Runnable
See Also:
JiraService.init(com.opensymphony.module.propertyset.PropertySet)

destroy

public void destroy()
This method is called when the service is unloaded (usually when the web application or server is being shut down).

You may wish to remove any connections that you have established, eg. database connections.

Specified by:
destroy in interface JiraService

isInternal

public boolean isInternal()
Indicates whether administrators can delete this service from within the web interface.

Generally only Atlassian services should return true from this.

Specified by:
isInternal in interface JiraService
Returns:
true if this service is internal to JIRA, false otherwise

getLastRun

public final long getLastRun()
The time that this service was last run. Generally this is called after the service has executed, to ensure that there is X delay between finish of previous run & start of the next one.

Specified by:
getLastRun in interface JiraServiceContainer
Returns:
The time in milliseconds that this service was last run.

setLastRun

public final void setLastRun()
Set the last run time to be the current time. As we do not assume that users will call this in their run method, all code that calls run() should also call this afterwards.

Specified by:
setLastRun in interface JiraServiceContainer
See Also:
run()

setDelay

public void setDelay(long delay)
Sets the delay between invocation of each service.

Specified by:
setDelay in interface JiraServiceContainer
Parameters:
delay - The time in milliseconds between runs of the service.

getDelay

public long getDelay()
The length of delay in milliseconds between runs of this service.

Specified by:
getDelay in interface JiraServiceContainer

isDueAt

public boolean isDueAt(long time)
Description copied from interface: JiraServiceContainer
Is this service due to run at the specified time.

Specified by:
isDueAt in interface JiraServiceContainer
Parameters:
time - the time to check whether it is due.
Returns:
true if due.

isUnique

public boolean isUnique()
Description copied from interface: JiraService
Whether this service class should be unique. Some service are fine to have multiples, and some are not.

Having multiple backup services could be fine - perhaps you want to backup once an hour, and also once a day.

With other services, you may wish to enforce their uniqueness

Specified by:
isUnique in interface JiraService
Returns:
Whether this service class should be unique.

getDescription

public String getDescription()
Description copied from interface: JiraService
A textual description of the service. You can include HTML if required, but do not use tables, or DHTML, as the description may be displayed inside tables / frames.

A good description will describe what this service does, and then explains the parameters required for configuring the service.

If no description is appropriate, return null.

Specified by:
getDescription in interface JiraService
Returns:
A HTML description of the service

getName

public String getName()
Description copied from interface: JiraService
A textual name of the service as entered by the user from the web interface.

The name should be unique to identify services of the same class.
This is enforced when adding new services via the web interface.

The value of name does not effect the service, hence can be set to null

Specified by:
getName in interface JiraService
Returns:
The name of the service

setName

public void setName(String name)
Description copied from interface: JiraService
Used to set the service's name. For details on the services name see JiraService.getName()

Specified by:
setName in interface JiraService
Parameters:
name - service name to set

getObjectConfiguration

public ObjectConfiguration getObjectConfiguration()
                                           throws ObjectConfigurationException
Description copied from interface: ObjectConfigurable
Retrieves an object configuration object with properties that can be set

Specified by:
getObjectConfiguration in interface ObjectConfigurable
Returns:
ObjectConfiguration object
Throws:
ObjectConfigurationException

hasProperty

public boolean hasProperty(String propertyKey)
                    throws ObjectConfigurationException
Description copied from interface: ObjectConfigurable
Checks if this object has a particular property

Specified by:
hasProperty in interface ObjectConfigurable
Parameters:
propertyKey - to look for
Returns:
true If there is a value
Throws:
ObjectConfigurationException

getProperty

public String getProperty(String propertyKey)
                   throws ObjectConfigurationException
Description copied from interface: ObjectConfigurable
Returns a property of this object with the specified key

Specified by:
getProperty in interface ObjectConfigurable
Parameters:
propertyKey - String key used to retrieve the property value
Returns:
Property value
Throws:
ObjectConfigurationException

getTextProperty

public String getTextProperty(String propertyKey)
                       throws ObjectConfigurationException
Description copied from interface: ObjectConfigurable
Returns a property of this object with the specified key, the property is of type text

Specified by:
getTextProperty in interface ObjectConfigurable
Parameters:
propertyKey - String key used to retrieve the property value
Returns:
Property value
Throws:
ObjectConfigurationException

getLongProperty

public Long getLongProperty(String propertyKey)
                     throws ObjectConfigurationException
Description copied from interface: ObjectConfigurable
Returns a property of this object with the specified key as a long

Specified by:
getLongProperty in interface ObjectConfigurable
Parameters:
propertyKey - String key used to retrieve the property value
Returns:
Property value
Throws:
ObjectConfigurationException

getDefaultProperty

public String getDefaultProperty(String propertyKey)
                          throws ObjectConfigurationException
Description copied from interface: ObjectConfigurable
Returns the default property value for a key

Specified by:
getDefaultProperty in interface ObjectConfigurable
Parameters:
propertyKey - String key used to retrieve the properties default value
Returns:
Default property key
Throws:
ObjectConfigurationException

getProperties

public com.opensymphony.module.propertyset.PropertySet getProperties()
                                                              throws ObjectConfigurationException
Description copied from interface: ObjectConfigurable
Retrieve all the specified Properties for this object

Specified by:
getProperties in interface ObjectConfigurable
Returns:
Set of properties for this object
Throws:
ObjectConfigurationException

isRunning

public boolean isRunning()
Whether a service is currently running. This is needed for services that may potentially run for longer than their delay period. Eg a service that is run every minute, but takes 2 mins to run.

Specified by:
isRunning in interface JiraServiceContainer

getKey

public String getKey()
Description copied from interface: ObjectConfigurable
Return the key of this object

Specified by:
getKey in interface ObjectConfigurable
Returns:
Key of object

getId

public Long getId()
Specified by:
getId in interface JiraServiceContainer

getServiceClass

public String getServiceClass()
Specified by:
getServiceClass in interface JiraServiceContainer

getServiceClassObject

@Nonnull
public Class getServiceClassObject()
Specified by:
getServiceClassObject in interface JiraServiceContainer
Returns:
the Class object of the underlying service, or null if service could not be loaded

isUsable

public boolean isUsable()
Specified by:
isUsable in interface JiraServiceContainer

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2002-2012 Atlassian. All Rights Reserved.