|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.veriplace.client.util.PollingManager
public class PollingManager
Maintains a thread that issues PollingAPI requests at regular
intervals and passes the results to a PollingHandler.
If not configured otherwise with setIntervalSeconds(int), the
polling interval will be set to the default value provided by the Veriplace
server after the first successful PollingAPI query.
By default, this class calls
GetLocationAPI.getLocationAccessToken(User) as
needed to obtain access tokens for getting users' locations, and stores the
tokens in an in-memory cache. If you have your own token caching mechanism,
you can pass your own implementation of UserTokenStore to the
constructor.
| Field Summary | |
|---|---|
protected Token |
accessToken
|
protected Client |
client
|
protected int |
intervalSeconds
|
protected boolean |
onlyNewestLocation
|
protected PollingAPI |
pollingAPI
|
protected PollingFilter |
pollingFilter
|
protected PollingHandler |
pollingHandler
|
protected UserTokenStore |
userTokenStore
|
| Constructor Summary | |
|---|---|
PollingManager()
Constructs a new PollingManager whose properties are uninitialized. |
|
PollingManager(Client client,
PollingHandler pollingHandler,
boolean startPollingNow)
Constructs a new PollingManager, using the default in-memory cache for access tokens. |
|
PollingManager(Client client,
PollingHandler pollingHandler,
PollingFilter pollingFilter,
boolean startPollingNow)
Constructs a new PollingManager, using the default in-memory cache for access tokens, and specifying a PollingFilter. |
|
PollingManager(Client client,
PollingHandler pollingHandler,
PollingFilter pollingFilter,
Token accessToken,
UserTokenStore userTokenStore,
boolean startPollingNow)
Constructs a new PollingManager, optionally specifying an alternate application token and an implementation object for access token caching. |
|
| Method Summary | |
|---|---|
protected void |
dispatchUpdate(User user,
LocationUpdateReference locRef,
java.lang.Object currentBatch)
|
Client |
getClient()
The Veriplace client instance. |
int |
getIntervalSeconds()
Returns the number of seconds between update queries. |
protected PollingAPI |
getPollingAPI(Client client)
|
PollingFilter |
getPollingFilter()
|
PollingHandler |
getPollingHandler()
|
protected Location |
getUpdateLocation(User user,
LocationUpdateReference locRef)
|
boolean |
isOnlyNewestLocation()
|
boolean |
isPolling()
Returns true if the PollingManager is running a background task to poll for location updates. |
protected void |
processUpdates(LocationUpdates updates)
|
protected void |
rescheduleAfterFirstQueryFailed(com.veriplace.client.util.PollingManager.PollingTask task)
|
void |
setAccessToken(Token accessToken)
Specifies an access token for update queries. |
void |
setClient(Client client)
|
void |
setIntervalSeconds(int intervalSeconds)
Specifies the number of seconds between update queries. |
void |
setOnlyNewestLocation(boolean onlyNewestLocation)
|
void |
setPolling(boolean polling)
Turns the background polling task on or off. |
void |
setPollingFilter(PollingFilter pollingFilter)
Specifies a filter implementation to determine which location updates are relevant. |
void |
setPollingHandler(PollingHandler pollingHandler)
Specifies the handler object that will receive location updates. |
void |
setUserTokenStore(UserTokenStore userTokenStore)
Specifies an implementation of UserTokenStore that can save and
retrieve access tokens for each user. |
void |
startPolling()
Starts a background task to poll for location updates. |
protected void |
startPolling(boolean waitForIntervalFirst)
|
void |
stopPolling()
Stops the background polling task. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected Client client
protected PollingAPI pollingAPI
protected Token accessToken
protected PollingHandler pollingHandler
protected PollingFilter pollingFilter
protected UserTokenStore userTokenStore
protected int intervalSeconds
protected boolean onlyNewestLocation
| Constructor Detail |
|---|
public PollingManager()
throws ConfigurationException
setClient(Client) and
setPollingHandler(PollingHandler).
ConfigurationException
public PollingManager(Client client,
PollingHandler pollingHandler,
boolean startPollingNow)
throws ConfigurationException
client - the Veriplace clientpollingHandler - the handler that will receive location updatesstartPollingNow - true to start polling immediately
ConfigurationException - if you attempted to start polling but
a required properties was null
public PollingManager(Client client,
PollingHandler pollingHandler,
PollingFilter pollingFilter,
boolean startPollingNow)
throws ConfigurationException
PollingFilter.
client - the Veriplace clientpollingHandler - the handler that will receive location updatespollingFilter - a filter implementation to determine which location
updates are relevantstartPollingNow - true to start polling immediately
ConfigurationException - if you attempted to start polling but
a required properties was null
public PollingManager(Client client,
PollingHandler pollingHandler,
PollingFilter pollingFilter,
Token accessToken,
UserTokenStore userTokenStore,
boolean startPollingNow)
throws ConfigurationException
client - the Veriplace clientpollingHandler - the handler that will receive location updatespollingFilter - an optional filter implementation to determine which
location updates are relevantaccessToken - the application-specific access token; null to use the
one that's in the client configuration (which you should normally do;
this parameter supports special cases such as aggregator services)userTokenStore - an implementation of UserTokenStore that
can save and retrieve access tokens for each user; if null, a simple
in-memory cache is usedstartPollingNow - true to start polling immediately
ConfigurationException - if you attempted to start polling but
a required properties was null| Method Detail |
|---|
protected PollingAPI getPollingAPI(Client client)
public Client getClient()
public void setClient(Client client)
public PollingHandler getPollingHandler()
public void setPollingHandler(PollingHandler pollingHandler)
public PollingFilter getPollingFilter()
public void setPollingFilter(PollingFilter pollingFilter)
public int getIntervalSeconds()
public void setAccessToken(Token accessToken)
public void setUserTokenStore(UserTokenStore userTokenStore)
UserTokenStore that can save and
retrieve access tokens for each user.
public void setIntervalSeconds(int intervalSeconds)
PollingAPI.setPeriodSeconds(int)
or, if that was not specified, then one-half of the default period used by
the server, which will be detected when we get our first query results.
public boolean isOnlyNewestLocation()
public void setOnlyNewestLocation(boolean onlyNewestLocation)
public boolean isPolling()
public void setPolling(boolean polling)
throws ConfigurationException
startPolling() or stopPolling().
ConfigurationException
public void startPolling()
throws ConfigurationException
ConfigurationException - if necessary properties have not been
initialized
protected void startPolling(boolean waitForIntervalFirst)
throws ConfigurationException
ConfigurationExceptionpublic void stopPolling()
protected void processUpdates(LocationUpdates updates)
protected void dispatchUpdate(User user,
LocationUpdateReference locRef,
java.lang.Object currentBatch)
protected Location getUpdateLocation(User user,
LocationUpdateReference locRef)
throws VeriplaceException
VeriplaceExceptionprotected void rescheduleAfterFirstQueryFailed(com.veriplace.client.util.PollingManager.PollingTask task)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||