angch.venice.1.12.33.source-code.test-geoip-city-lookup.venice Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of venice Show documentation
Show all versions of venice Show documentation
Venice, a sandboxed Lisp implemented in Java.
;;;; __ __ _
;;;; \ \ / /__ _ __ (_) ___ ___
;;;; \ \/ / _ \ '_ \| |/ __/ _ \
;;;; \ / __/ | | | | (_| __/
;;;; \/ \___|_| |_|_|\___\___|
;;;;
;;;;
;;;; Copyright 2017-2024 Venice
;;;;
;;;; Licensed under the Apache License, Version 2.0 (the "License");
;;;; you may not use this file except in compliance with the License.
;;;; You may obtain a copy of the License at
;;;;
;;;; http://www.apache.org/licenses/LICENSE-2.0
;;;;
;;;; Unless required by applicable law or agreed to in writing, software
;;;; distributed under the License is distributed on an "AS IS" BASIS,
;;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;;; See the License for the specific language governing permissions and
;;;; limitations under the License.
(do
(ns test)
(load-module :geoip)
;; The MaxMind city database.
(def maxmind-city-zip "resources/geoip-city.zip")
(def ip-addresses-file "resources/ip-addresses.txt")
(defn create-resolver []
; this may take some time
(println "Parsing MaxMind DB ...")
(geoip/ip-to-city-loc-resolver maxmind-city-zip))
(defn load-ip-addresses []
(->> (io/slurp ip-addresses-file :binary false)
(str/split-lines)))
(def resolver (create-resolver))
(def ip-addresses (load-ip-addresses))
(defn lookup-ip [ip]
(resolver ip))
(defn process [ip-addresses]
(map resolver ip-addresses)
nil)
(defn run []
(process ip-addresses))
(defn run-parallel []
(let [threads (max 1 (/ (cpus) 2))
work (partition threads threads [] ip-addresses)
futures (map #(future (partial process %)) work)]
(map deref futures)
nil))
; (test/lookup-ip "192.241.235.46")
)