net.sf.uadetector.parser
Class UpdatingUserAgentStringParserImpl

java.lang.Object
  extended by net.sf.uadetector.parser.AbstractUserAgentStringParser
      extended by net.sf.uadetector.parser.UserAgentStringParserImpl<RefreshableDataStore>
          extended by net.sf.uadetector.parser.UpdatingUserAgentStringParserImpl
All Implemented Interfaces:
UserAgentStringParser

public final class UpdatingUserAgentStringParserImpl
extends UserAgentStringParserImpl<RefreshableDataStore>

This parser checks once per day if newer data are available. When newer data are available, they will be loaded, read and replaced by the current one.

Author:
André Rouél

Field Summary
static long DEFAULT_UPDATE_INTERVAL
          The default interval to check for updates is once per day
 
Constructor Summary
UpdatingUserAgentStringParserImpl(RefreshableDataStore store)
          Constructs an instance of OnlineUserAgentStringParser.
 
Method Summary
 long getUpdateInterval()
          Gets the current update interval in milliseconds.
 void setUpdateInterval(long updateInterval)
          Sets a new update interval in milliseconds.
 void shutdown()
          In environments where the JVM will never shut down while reinstalling UADetector, it is necessary to manually shutdown running threads of UserAgentStringParsers with updating functionality like UADetectorServiceFactory.getCachingAndUpdatingParser() or UADetectorServiceFactory.getOnlineUpdatingParser().
 
Methods inherited from class net.sf.uadetector.parser.UserAgentStringParserImpl
getDataStore
 
Methods inherited from class net.sf.uadetector.parser.AbstractUserAgentStringParser
getDataVersion, parse
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_UPDATE_INTERVAL

public static final long DEFAULT_UPDATE_INTERVAL
The default interval to check for updates is once per day

See Also:
Constant Field Values
Constructor Detail

UpdatingUserAgentStringParserImpl

public UpdatingUserAgentStringParserImpl(RefreshableDataStore store)
Constructs an instance of OnlineUserAgentStringParser. During construction new UAS data will be queried online by the given URLs.

Parameters:
store - DataStore with reference UAS data used in fallback case
Throws:
net.sf.qualitycheck.exception.IllegalNullArgumentException - if one of the given arguments is null
Method Detail

getUpdateInterval

public long getUpdateInterval()
Gets the current update interval in milliseconds.

Returns:
current update interval in milliseconds

setUpdateInterval

public void setUpdateInterval(@Nonnegative
                              long updateInterval)
Sets a new update interval in milliseconds.

When a new update interval is set, the old update service is removed and a new one will be set.

Parameters:
updateInterval - update interval in milliseconds
Throws:
net.sf.qualitycheck.exception.IllegalNegativeArgumentException - if the given update interval is less than 0

shutdown

@PreDestroy
public void shutdown()
Description copied from interface: UserAgentStringParser
In environments where the JVM will never shut down while reinstalling UADetector, it is necessary to manually shutdown running threads of UserAgentStringParsers with updating functionality like UADetectorServiceFactory.getCachingAndUpdatingParser() or UADetectorServiceFactory.getOnlineUpdatingParser().

For example, if a web application with UADetector will be re-deployed within an Apache Tomcat you must shutdown your self-created or via UADetectorServiceFactory retrieved updating UserAgentStringParser otherwise more and more threads will be registered.

An implementation of UserAgentStringParser has updating functionality if it works with a RefreshableDataStore.

If you call shutdown on a non-updating UserAgentStringParser implementation nothing will happen.

A number of Dependency Injection containers support the annotation PreDestroy which is be useful for indicating methods that should be called when the container is shutting down. This annotation is available by default in Java SE 7 and can be made available through the external library jsr250-api-1.0.jar for earlier versions of Java.

We recommend to annotate an implementation of UserAgentStringParser.shutdown() with PreDestroy to inform a container (for example Spring Framework) to trigger the shutdown method automatically by convention during the shutdown lifecycle. This saves developers to call explicitly the shutdown method.

To shutdown all managed ExecutorService by UADetector at once, you can call also ExecutorServices.shutdownAll().

Specified by:
shutdown in interface UserAgentStringParser
Overrides:
shutdown in class AbstractUserAgentStringParser


Copyright © 2011-2014. All Rights Reserved.