Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /* *********************************************************************
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0.
  * 
  * If a copy of the MPL was not distributed with this file, You can obtain
  * one at http://mozilla.org/MPL/2.0/.
  * 
  * This Source Code Form is "Incompatible With Secondary Licenses", as
  * defined by the Mozilla Public License, v. 2.0.
 * ********************************************************************* */
package fiftyone.mobile.detection;
Class Run by the Timer object in the Factory51D Object. Used to ensure that all instances have the latest data available on the file system.

Author(s):
51Degrees.mobi
Version:
2.2.8.9
public class FileAutoChecker extends java.util.TimerTask {
    
    
The factory class that created this timer task.
    protected Factory _factory = null;
    
    
The last modified data of the data currently being used.
    protected long _loadedFileModifiedDate = 0;
    
        
Constructs a new instance of the checker for the factory provided.

Parameters:
factory
    public FileAutoChecker(final Factory factory)
    {
        super();
        this. = factory;
        
    }
    
    
Creates a logger for this class
    private static final Logger _logger = LoggerFactory.getLogger(FileAutoChecker.class);
    
    
Runs the file checker.
    @Override
    public synchronized void run() 
    {
        .trace("Checking for newer data file on file system.");
        final File binaryFile = .getBinaryFilePath();
        
        // first check if the data file is newer than the one loaded
        if (binaryFile != null && binaryFile.lastModified() > 
        {
            .info(String.format("Newer data file on file system found. New file last modified at '%d'.",
                    binaryFile.lastModified())
                );
            
            // create a new provider to fill
            final Provider provider = .createProvider();
            
            if(Reader.read(providerbinaryFile.getAbsolutePath())) 
            {
                // provider was successfully filled with new data. now set as active provider
                .setActiveProvider(provider);
                .info(
                String.format("New provider set from file. Data publish date - '%s'.",
                        provider.getPublishedDate().toString())
                );
            }
            else
            {
                // error while loading data
                .info("Provider could not be set from newer data on the file system. The file may be corrupt.");
            }
             = binaryFile.lastModified();
        }
    }
New to GrepCode? Check out our FAQ X