Skip to content

Commit b6e31bb

Browse files
committed
address lint issues and clean up code
Signed-off-by: Sean Corfield <[email protected]>
1 parent 279ab0a commit b6e31bb

File tree

1 file changed

+42
-55
lines changed

1 file changed

+42
-55
lines changed

src/durable_queue.clj

Lines changed: 42 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,29 @@
11
(ns durable-queue
22
(:require
3-
[clojure.java.io :as io]
4-
[byte-streams :as bs]
5-
[clojure.string :as str]
6-
[primitive-math :as p]
7-
[taoensso.nippy :as nippy])
3+
[clj-commons.byte-streams :as bs]
4+
[clj-commons.primitive-math :as p]
5+
[clojure.java.io :as io]
6+
[taoensso.nippy :as nippy])
87
(:import
9-
[java.lang.reflect
10-
Method
11-
Field]
12-
[java.util.concurrent
13-
LinkedBlockingQueue
14-
TimeoutException
15-
TimeUnit]
16-
[java.util.concurrent.atomic
8+
[java.io
9+
File
10+
IOException
11+
RandomAccessFile
12+
Writer]
13+
[java.lang.ref
14+
WeakReference]
15+
[java.lang.reflect
16+
Method]
17+
[java.nio ByteBuffer MappedByteBuffer]
18+
[java.nio.channels
19+
FileChannel$MapMode]
20+
[java.util.concurrent LinkedBlockingQueue TimeUnit TimeoutException]
21+
[java.util.concurrent.atomic
1722
AtomicLong]
18-
[java.util.zip
19-
CRC32]
20-
[java.util.concurrent.locks
23+
[java.util.concurrent.locks
2124
ReentrantReadWriteLock]
22-
[java.io
23-
Writer
24-
File
25-
RandomAccessFile
26-
IOException]
27-
[java.nio.channels
28-
FileChannel
29-
FileChannel$MapMode]
30-
[java.nio
31-
ByteBuffer
32-
MappedByteBuffer]
33-
[java.lang.ref
34-
WeakReference]))
25+
[java.util.zip
26+
CRC32]))
3527

3628
;;;
3729

@@ -78,7 +70,7 @@
7870
(^:private sync! [_])
7971
(^:private invalidate [_ offset len])
8072
(^:private ^ByteBuffer buffer [_])
81-
(^:private append-to-slab! [_ descriptor])
73+
(^:private append-to-slab! [_ task-descriptor])
8274
(^:private read-write-lock [_]))
8375

8476
(defmacro ^:private with-buffer [[buf slab] & body]
@@ -139,12 +131,12 @@
139131
(.invoke clean
140132
(.invoke cleaner buf nil)
141133
nil))
142-
(catch Throwable e
134+
(catch Throwable _
143135
;; not much we can do here, sadly
144136
)))))
145137

146138
(defn- force-buffer
147-
[^MappedByteBuffer buf offset length]
139+
[^MappedByteBuffer buf _offset _length]
148140
(.force buf))
149141

150142
;;;
@@ -232,8 +224,8 @@
232224
(lazy-seq
233225
(with-buffer [buf slab]
234226
(let [^ByteBuffer buf' (.position buf (p/inc pos))
235-
status (.get buf')
236-
checksum (.getLong buf')
227+
_status (.get buf')
228+
_checksum (.getLong buf')
237229
size (.getInt buf')]
238230

239231
;; this shouldn't be necessary, but let's not gratuitously
@@ -249,7 +241,7 @@
249241
(slab->task-seq
250242
slab
251243
(+ pos header-size size)))))))))
252-
(catch Throwable e
244+
(catch Throwable _
253245
;; this implies unrecoverable corruption
254246
nil
255247
)))))
@@ -268,7 +260,7 @@
268260
(read-write-lock [_]
269261
lock)
270262

271-
(buffer [this]
263+
(buffer [_]
272264
(let [buf (or @buf
273265
(swap! buf
274266
(fn [buf]
@@ -299,9 +291,9 @@
299291
(compare-and-set! dirty [start end] [Integer/MAX_VALUE 0])
300292
nil)))))
301293

302-
(append-to-slab! [this descriptor]
294+
(append-to-slab! [this task-descriptor]
303295
(with-buffer [buf this]
304-
(let [ary (nippy/freeze descriptor)
296+
(let [ary (nippy/freeze task-descriptor)
305297
cnt (count ary)
306298
pos @position
307299
^ByteBuffer buf (.position buf ^Long pos)]
@@ -515,10 +507,6 @@
515507
queue-name->current-slab (atom {})
516508

517509
;; initialize
518-
slabs (->> @queue-name->slabs vals (apply concat))
519-
slab->count (zipmap
520-
slabs
521-
(map #(atom (count (seq %))) slabs))
522510
create-new-slab (fn [q-name]
523511
(let [slab (create-slab directory q-name (queue q-name) slab-size)
524512
empty-slabs (->> (@queue-name->slabs q-name)
@@ -566,8 +554,7 @@
566554
(fsync q)
567555
(let [end (System/currentTimeMillis)]
568556
(Thread/sleep (long (max 0 (- fsync-interval (- end start)))))))
569-
(catch Throwable e
570-
)))))))
557+
(catch Throwable _)))))))
571558

572559
;; populate queues with pre-existing tasks
573560
(let [empty-slabs (atom #{})]
@@ -620,7 +607,7 @@
620607

621608
IQueues
622609

623-
(delete! [this]
610+
(delete! [_]
624611
(doseq [s (->> @queue-name->slabs vals (apply concat))]
625612
(unmap s)
626613
(delete-slab s)))
@@ -654,7 +641,7 @@
654641
(immediate-stats (queue q-name) (get @queue-name->stats q-name))))
655642
ks))))
656643

657-
(take! [this q-name timeout timeout-val]
644+
(take! [_ q-name timeout timeout-val]
658645
(let [q-name (munge (name q-name))
659646
^LinkedBlockingQueue q (queue q-name)]
660647
(try
@@ -704,8 +691,8 @@
704691

705692
(when-not task
706693
(throw
707-
(IllegalArgumentException.
708-
(str "Can't enqueue task whose serialized representation is larger than :slab-size, which is currently " slab-size))))
694+
(IllegalArgumentException.
695+
(str "Can't enqueue task whose serialized representation is larger than :slab-size, which is currently " slab-size))))
709696

710697
(when fsync-put?
711698
(sync! slab))
@@ -715,13 +702,13 @@
715702
(if (zero? timeout)
716703
(.offer q task)
717704
(.offer q task timeout TimeUnit/MILLISECONDS)))]
718-
(if-let [val (locking q
719-
(queue!
720-
(vary-meta (slab!) assoc
721-
::this this-ref
722-
::queue-name q-name
723-
::queue q
724-
::fsync? fsync-take?)))]
705+
(if (locking q
706+
(queue!
707+
(vary-meta (slab!) assoc
708+
::this this-ref
709+
::queue-name q-name
710+
::queue q
711+
::fsync? fsync-take?)))
725712
(do
726713
(populate-stats! q-name)
727714
(let [^AtomicLong counter (get-in @queue-name->stats [q-name :enqueued])]

0 commit comments

Comments
 (0)