mirror of https://github.com/apache/nifi.git
NIFI-271
This commit is contained in:
parent
525ce7fb2d
commit
e627482734
|
@ -189,17 +189,17 @@ public class GeoEnrichIP extends AbstractProcessor {
|
|||
final Map<String, String> attrs = new HashMap<>();
|
||||
attrs.put(new StringBuilder(ipAttributeName).append(".geo.lookup.micros").toString(), String.valueOf(stopWatch.getDuration(TimeUnit.MICROSECONDS)));
|
||||
attrs.put(new StringBuilder(ipAttributeName).append(".geo.city").toString(), response.getCity().getName());
|
||||
|
||||
|
||||
final Double latitude = response.getLocation().getLatitude();
|
||||
if ( latitude != null ) {
|
||||
attrs.put(new StringBuilder(ipAttributeName).append(".geo.latitude").toString(), latitude.toString());
|
||||
if (latitude != null) {
|
||||
attrs.put(new StringBuilder(ipAttributeName).append(".geo.latitude").toString(), latitude.toString());
|
||||
}
|
||||
|
||||
|
||||
final Double longitude = response.getLocation().getLongitude();
|
||||
if ( longitude != null ) {
|
||||
attrs.put(new StringBuilder(ipAttributeName).append(".geo.longitude").toString(), longitude.toString());
|
||||
if (longitude != null) {
|
||||
attrs.put(new StringBuilder(ipAttributeName).append(".geo.longitude").toString(), longitude.toString());
|
||||
}
|
||||
|
||||
|
||||
int i = 0;
|
||||
for (final Subdivision subd : response.getSubdivisions()) {
|
||||
attrs.put(new StringBuilder(ipAttributeName).append(".geo.subdivision.").append(i).toString(), subd.getName());
|
||||
|
|
|
@ -43,17 +43,13 @@ import com.maxmind.geoip2.model.IspResponse;
|
|||
|
||||
/**
|
||||
* <p>
|
||||
* This class was copied from
|
||||
* https://raw.githubusercontent.com/maxmind/GeoIP2-java/master/src/main/java/com/maxmind/geoip2/DatabaseReader.java
|
||||
* It is written by Maxmind and it is available under Apache Software License V2
|
||||
* This class was copied from https://raw.githubusercontent.com/maxmind/GeoIP2-java/master/src/main/java/com/maxmind/geoip2/DatabaseReader.java It is written by Maxmind and it is available under
|
||||
* Apache Software License V2
|
||||
*
|
||||
* The modification we're making to the code below is to stop using exceptions
|
||||
* for mainline flow control. Specifically we don't want to throw an exception
|
||||
* simply because an address was not found.
|
||||
* The modification we're making to the code below is to stop using exceptions for mainline flow control. Specifically we don't want to throw an exception simply because an address was not found.
|
||||
* </p>
|
||||
*
|
||||
* Instances of this class provide a reader for the GeoIP2 database format. IP
|
||||
* addresses can be looked up using the <code>get</code> method.
|
||||
* Instances of this class provide a reader for the GeoIP2 database format. IP addresses can be looked up using the <code>get</code> method.
|
||||
*/
|
||||
public class DatabaseReader implements GeoIp2Provider, Closeable {
|
||||
|
||||
|
@ -84,12 +80,10 @@ public class DatabaseReader implements GeoIp2Provider, Closeable {
|
|||
|
||||
/**
|
||||
* <p>
|
||||
* Constructs a Builder for the DatabaseReader. The file passed to it must
|
||||
* be a valid GeoIP2 database file.
|
||||
* Constructs a Builder for the DatabaseReader. The file passed to it must be a valid GeoIP2 database file.
|
||||
* </p>
|
||||
* <p>
|
||||
* <code>Builder</code> creates instances of <code>DatabaseReader</code>
|
||||
* from values set by the methods.
|
||||
* <code>Builder</code> creates instances of <code>DatabaseReader</code> from values set by the methods.
|
||||
* </p>
|
||||
* <p>
|
||||
* Only the values set in the <code>Builder</code> constructor are required.
|
||||
|
@ -120,8 +114,7 @@ public class DatabaseReader implements GeoIp2Provider, Closeable {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param val List of locale codes to use in name property from most
|
||||
* preferred to least preferred.
|
||||
* @param val List of locale codes to use in name property from most preferred to least preferred.
|
||||
* @return Builder object
|
||||
*/
|
||||
public Builder locales(List<String> val) {
|
||||
|
@ -132,9 +125,7 @@ public class DatabaseReader implements GeoIp2Provider, Closeable {
|
|||
/**
|
||||
* @param val The file mode used to open the GeoIP2 database
|
||||
* @return Builder object
|
||||
* @throws java.lang.IllegalArgumentException if you initialized the
|
||||
* Builder with a URL, which uses {@link FileMode#MEMORY}, but you
|
||||
* provided a different FileMode to this method.
|
||||
* @throws java.lang.IllegalArgumentException if you initialized the Builder with a URL, which uses {@link FileMode#MEMORY}, but you provided a different FileMode to this method.
|
||||
*/
|
||||
public Builder fileMode(FileMode val) {
|
||||
if (this.stream != null && !FileMode.MEMORY.equals(val)) {
|
||||
|
@ -146,8 +137,7 @@ public class DatabaseReader implements GeoIp2Provider, Closeable {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return an instance of <code>DatabaseReader</code> created from the
|
||||
* fields set on this builder.
|
||||
* @return an instance of <code>DatabaseReader</code> created from the fields set on this builder.
|
||||
* @throws IOException if there is an error reading the database
|
||||
*/
|
||||
public DatabaseReader build() throws IOException {
|
||||
|
@ -157,10 +147,8 @@ public class DatabaseReader implements GeoIp2Provider, Closeable {
|
|||
|
||||
/**
|
||||
* @param ipAddress IPv4 or IPv6 address to lookup.
|
||||
* @return An object of type T with the data for the IP address or null if no
|
||||
* information could be found for the given IP address
|
||||
* @throws IOException if there is an error opening or reading from the
|
||||
* file.
|
||||
* @return An object of type T with the data for the IP address or null if no information could be found for the given IP address
|
||||
* @throws IOException if there is an error opening or reading from the file.
|
||||
*/
|
||||
private <T> T get(InetAddress ipAddress, Class<T> cls, boolean hasTraits,
|
||||
String type) throws IOException, AddressNotFoundException {
|
||||
|
@ -200,10 +188,8 @@ public class DatabaseReader implements GeoIp2Provider, Closeable {
|
|||
* </p>
|
||||
* <p>
|
||||
* If you are using <code>FileMode.MEMORY_MAPPED</code>, this will
|
||||
* <em>not</em> unmap the underlying file due to a limitation in Java's
|
||||
* <code>MappedByteBuffer</code>. It will however set the reference to the
|
||||
* buffer to <code>null</code>, allowing the garbage collector to collect
|
||||
* it.
|
||||
* <em>not</em> unmap the underlying file due to a limitation in Java's <code>MappedByteBuffer</code>. It will however set the reference to the buffer to <code>null</code>, allowing the garbage
|
||||
* collector to collect it.
|
||||
* </p>
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
|
|
Loading…
Reference in New Issue