Skip to content

Commit

Permalink
fixup! m2 init
Browse files Browse the repository at this point in the history
  • Loading branch information
mpenet committed Sep 15, 2023
1 parent 34df40d commit 7a3b5d6
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 93 deletions.
26 changes: 7 additions & 19 deletions src/s_exp/mina.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@
(WebServerConfig/builder)
options))

;; (clojure.reflect/reflect (WebServerConfig/builder))

;; (import 'io.helidon.config.Config)

;; (clojure.reflect/reflect (io.helidon.config.Config/builder))

;; (let [c (io.helidon.config.Config/create)
;; b (WebServerConfig/builder)
;; p (.buildPrototype (.config b (.get c "server")))]
;; (clojure.reflect/reflect p)
;; (.writeQueueLength p))

(defn start!
"Starts a new server.
Expand All @@ -52,13 +40,13 @@
(.stop server))

;; (def r {:status 200})
;; ;; (def h (fn [req]
;; ;; (prn (counted? (:headers req)))
;; ;; r))
;; ;; (def h (fn [_]
;; ;; ;; (prn :aasdf ((:headers _) "accept"))
;; ;; ;; (prn (:headers _))
;; ;; r))
;; (def h (fn [req]
;; (prn (counted? (:headers req)))
;; r))
;; (def h (fn [_]
;; ;; (prn :aasdf ((:headers _) "accept"))
;; ;; (prn (:headers _))
;; r))
;; (def s (start!
;; r
;; {:host "0.0.0.0" :port 8080 :default-socket {:write-queue-length 10240}}))
Expand Down
138 changes: 64 additions & 74 deletions src/s_exp/mina/options.clj
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
(ns s-exp.mina.options
(:import (io.helidon.common.socket SocketOptions$Builder)
(io.helidon.webserver ;; ListenerConfiguration$Builder
ServerListener
WebServerConfig$Builder)
(io.helidon.common.tls TlsConfig)
(io.helidon.webserver ListenerConfig$Builder
WebServerConfig$Builder)
(java.time Duration)))

;; (ServerListener/config)

(set! *warn-on-reflection* true)
(defmulti set-server-option! (fn [_builder k _v _options] k))

Expand All @@ -16,80 +14,72 @@
(defmethod set-server-option! :host
[^WebServerConfig$Builder builder _ host _]
(.host builder host))
;; io.helidon.webserver.WebServerConfig$BuilderBaseio.helidon.webserver.WebServerConfig$BuilderBase

(defmethod set-server-option! :port
[^WebServerConfig$Builder builder _ port _]
(.port builder (int port)))

#_(defn- set-connection-options!
[^SocketOptions$Builder socket-options-builder
{:keys [socket-receive-buffer-size socket-send-buffer-size
socket-reuse-address socket-keep-alive tcp-no-delay
read-timeout connect-timeout]}]
(when socket-receive-buffer-size
(.socketReceiveBufferSize socket-options-builder
(int socket-receive-buffer-size)))

(when socket-send-buffer-size
(.socketSendBufferSize socket-options-builder
(int socket-send-buffer-size)))

(when socket-reuse-address
(.socketReuseAddress socket-options-builder
(boolean socket-reuse-address)))

(when socket-keep-alive
(.socketKeepAlive socket-options-builder
(boolean socket-keep-alive)))
(when tcp-no-delay
(.tcpNoDelay socket-options-builder
(boolean tcp-no-delay)))

(when read-timeout
(.readTimeout socket-options-builder
(Duration/ofMillis read-timeout)))
(when connect-timeout
(.connectTimeout socket-options-builder
(Duration/ofMillis connect-timeout))))

#_(defn- set-listener-configuration!
[^ListenerConfiguration$Builder listener-configuration-builder
{:keys [write-queue-length backlog max-payload-size receive-buffer-size
connection-options]}]
(when backlog
(.backlog listener-configuration-builder
(int backlog)))

(when max-payload-size
(.maxPayloadSize listener-configuration-builder
(long max-payload-size)))

(when write-queue-length
(.writeQueueLength listener-configuration-builder
(int write-queue-length)))

(when receive-buffer-size
(.receiveBufferSize listener-configuration-builder
(int receive-buffer-size)))

#_(when (seq connection-options)
(.connectionOptions listener-configuration-builder
(reify java.util.function.Consumer
(accept [_ socket-options-builder]
(set-connection-options! socket-options-builder
connection-options))))))

#_(defmethod set-server-option! :default-socket
[^WebServerConfig$Builder builder _ default-socket _]
(doto builder
(.defaultSocket
(reify java.util.function.Consumer
(accept [_ listener-configuration-builder]
(set-listener-configuration! listener-configuration-builder
default-socket))))))
(defmethod set-server-option! :backlog
[^WebServerConfig$Builder builder _ backlog _]
(.backlog builder (int backlog)))

(defmethod set-server-option! :backlog
[^WebServerConfig$Builder builder _ backlog _]
(.backlog builder (int backlog)))

(defmethod set-server-option! :max-payload-size
[^WebServerConfig$Builder builder _ max-payload-size _]
(.maxPayloadSize builder (long max-payload-size)))

(defmethod set-server-option! :write-queue-length
[^WebServerConfig$Builder builder _ write-queue-length _]
(.writeQueueLength builder (long write-queue-length)))

(defmethod set-server-option! :receive-buffer-size
[^WebServerConfig$Builder builder _ receive-buffer-size _]
(.receiveBufferSize builder (int receive-buffer-size)))

(defn- set-connection-options!
[^SocketOptions$Builder socket-options-builder
{:keys [socket-receive-buffer-size socket-send-buffer-size
socket-reuse-address socket-keep-alive tcp-no-delay
read-timeout connect-timeout]}]
(when socket-receive-buffer-size
(.socketReceiveBufferSize socket-options-builder
(int socket-receive-buffer-size)))

(when socket-send-buffer-size
(.socketSendBufferSize socket-options-builder
(int socket-send-buffer-size)))

(when socket-reuse-address
(.socketReuseAddress socket-options-builder
(boolean socket-reuse-address)))

(when socket-keep-alive
(.socketKeepAlive socket-options-builder
(boolean socket-keep-alive)))
(when tcp-no-delay
(.tcpNoDelay socket-options-builder
(boolean tcp-no-delay)))

(when read-timeout
(.readTimeout socket-options-builder
(Duration/ofMillis read-timeout)))
(when connect-timeout
(.connectTimeout socket-options-builder
(Duration/ofMillis connect-timeout))))

(defmethod set-server-option! :connection-options
[^WebServerConfig$Builder builder _ connection-options _]
(.connectionOptions builder
(reify java.util.function.Consumer
(accept [_ socket-options-builder]
(set-connection-options! socket-options-builder
connection-options)))))

(defmethod set-server-option! :tls
[^WebServerConfig$Builder builder _ tls _]
(doto builder (.tls tls)))
[^WebServerConfig$Builder builder _ ^TlsConfig tls-config _]
(doto builder (.tls tls-config)))


0 comments on commit 7a3b5d6

Please sign in to comment.