net.sf.uadetector.parser
Class AbstractUserAgentStringParser

java.lang.Object
  extended by net.sf.uadetector.parser.AbstractUserAgentStringParser
All Implemented Interfaces:
UserAgentStringParser
Direct Known Subclasses:
UserAgentStringParserImpl

public abstract class AbstractUserAgentStringParser
extends java.lang.Object
implements UserAgentStringParser


Constructor Summary
AbstractUserAgentStringParser()
           
 
Method Summary
protected abstract  DataStore getDataStore()
          Gets the data store of this parser.
 java.lang.String getDataVersion()
          Returns the current version information of the used UAS data.
 UserAgent parse(java.lang.String userAgent)
          Detects informations about a network client based on a user agent string.
 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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractUserAgentStringParser

public AbstractUserAgentStringParser()
Method Detail

getDataStore

protected abstract DataStore getDataStore()
Gets the data store of this parser.

Returns:
data store of this parser

getDataVersion

public java.lang.String getDataVersion()
Description copied from interface: UserAgentStringParser
Returns the current version information of the used UAS data.

The version will be set by the UAS data provider (http://user-agent-string.info/) and the version should look like this:

format: YYYYMMDD-counter (counter is two digits long)
example: 20120931-02

Specified by:
getDataVersion in interface UserAgentStringParser
Returns:
version of the current UAS data

parse

public UserAgent parse(java.lang.String userAgent)
Description copied from interface: UserAgentStringParser
Detects informations about a network client based on a user agent string.

Typically user agent string will be read by an instance of HttpServletRequest. With the method getHeader("User-Agent") you can get direct access to this string.

Specified by:
parse in interface UserAgentStringParser
Parameters:
userAgent - user agent string
Returns:
the detected information of an user agent

shutdown

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


Copyright © 2011-2014. All Rights Reserved.