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;
}
}
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);
}
}
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;
}
Aggregations