Search in sources :

Example 1 with CHMCache

use of com.maxmind.db.CHMCache in project Nucleus by NucleusPowered.

the class GeoIpDatabaseHandler method onRun.

private void onRun(LoadType type) {
    try {
        isLoading = true;
        // Check in case we need it.
        downloadUpdate(type == LoadType.DOWNLOAD);
        if (databaseReader != null) {
            databaseReader.close();
        }
        InputStream inputStream = new FileInputStream(countries.toFile());
        databaseReader = new DatabaseReader.Builder(inputStream).withCache(new CHMCache()).fileMode(Reader.FileMode.MEMORY).build();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        isLoading = false;
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) CHMCache(com.maxmind.db.CHMCache) FileInputStream(java.io.FileInputStream) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) AddressNotFoundException(com.maxmind.geoip2.exception.AddressNotFoundException)

Example 2 with CHMCache

use of com.maxmind.db.CHMCache in project bender by Nextdoor.

the class GeoIpOperationFactory method setConf.

@Override
public void setConf(AbstractConfig config) {
    this.config = (GeoIpOperationConfig) config;
    AmazonS3Client client = this.s3Factory.newInstance();
    AmazonS3URI uri = new AmazonS3URI(this.config.getGeoLiteDb());
    GetObjectRequest req = new GetObjectRequest(uri.getBucket(), uri.getKey());
    S3Object obj = client.getObject(req);
    try {
        this.databaseReader = new DatabaseReader.Builder(obj.getObjectContent()).withCache(new CHMCache()).build();
    } catch (IOException e) {
        throw new ConfigurationException("Unable to read " + this.config.getGeoLiteDb(), e);
    }
}
Also used : AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) ConfigurationException(com.nextdoor.bender.config.ConfigurationException) CHMCache(com.maxmind.db.CHMCache) DatabaseReader(com.maxmind.geoip2.DatabaseReader) S3Object(com.amazonaws.services.s3.model.S3Object) IOException(java.io.IOException) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest) AmazonS3URI(com.amazonaws.services.s3.AmazonS3URI)

Example 3 with CHMCache

use of com.maxmind.db.CHMCache in project PretendYoureXyzzy by ajanata.

the class GeoIP method makeReader.

private synchronized DatabaseReader makeReader() {
    LOG.info("Attempting to create GeoIP database reader");
    initialized = true;
    if (reader != null) {
        return reader;
    }
    final String dbPath = propertiesProvider.get().getProperty("geoip.db");
    if (StringUtils.isNotBlank(dbPath)) {
        final File db = new File(dbPath);
        try {
            reader = new DatabaseReader.Builder(db).withCache(new CHMCache()).build();
        } catch (final IOException e) {
            LOG.error("Unable to create database reader", e);
            reader = null;
        }
    } else {
        reader = null;
    }
    return reader;
}
Also used : CHMCache(com.maxmind.db.CHMCache) DatabaseReader(com.maxmind.geoip2.DatabaseReader) IOException(java.io.IOException) File(java.io.File)

Aggregations

CHMCache (com.maxmind.db.CHMCache)3 IOException (java.io.IOException)3 DatabaseReader (com.maxmind.geoip2.DatabaseReader)2 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)1 AmazonS3URI (com.amazonaws.services.s3.AmazonS3URI)1 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)1 S3Object (com.amazonaws.services.s3.model.S3Object)1 AddressNotFoundException (com.maxmind.geoip2.exception.AddressNotFoundException)1 ConfigurationException (com.nextdoor.bender.config.ConfigurationException)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 TimeoutException (java.util.concurrent.TimeoutException)1 GZIPInputStream (java.util.zip.GZIPInputStream)1