Giter Site home page Giter Site logo

tcp-driver's People

Contributors

gerritjvv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

igor-vlasov

tcp-driver's Issues

Close pool on shutdown handler

This should be configurable on default == false, but if set each connection/pool should register a shutdown hook that closes the pool on JVM shutdown

Consistent Hash rounting

Add consistent hash routing.

The default routing is random which generically works best, but for some schemes a consistent hash works better.
This does require the data to be sent via the send-op to contain some kind of format.

Requires: #2

Create generic Data wrapper for send-op

The data we send should support the following protocol:

IData
  -msg-bytes [] : byte-array ;; return the message as bytes
  -msg-key [] : byte-array  ;; get the message key, used for routing
  -clone [key:bytes, msg:bytes] : IData ;; create a new message using the same implementation

Provde default implementations using:

String
Number
byte[]

Implement conn and send-op

Require: #4

Add create conn, send-op and add retry and routing policy mechanisms.

create-conn [ bootstrap-hosts pool-conf routing-obj retry-policy conf]
   { :pool (pool
     :conf conf
     :bootstrap-hosts bootstrap-hosts
     :retry-policy retry-policy
     :routing-policy routing-obj
     :routing-env {:hosts (atom (set boostrap-hosts))}



 add-host! [ ctx host host-conf]
    (assoc-stm! (get-in ctx [:routing-env :hosts]) host)

 remove-host! [ctx host host-conf]
   (dissoc-stm! (get-in ctx [:routing-env :hosts]) host)

 send-op [ctx host i-o-f data timeout-ms]
    try:
       conn = (pool/borrow (:pool ctx) host timeout-ms)
       try:
          return (i-o-f conn data timeout-ms)
       finally:
          (pool/return pool-inst conn)

     catch Exception e
           (pool/invalidate pool-inst conn)
           return e


 send [ ctx i-o-f data timeout-ms]

   hosts = (:bootstrap-hosts ctx)
   routing-policy (:routing-policy ctx)


   loop [retry-state  nil]
        host = (routing/select-host routing-policy (:routing-env ctx) hosts)

        if host == null
           throw NoHostAvailableException

        ret-val =  (send-op ctx host i-o-f data timeout-ms)

        if ret-val == Exception
           [retry-state retry-op] = (io-retry/retry-action! (:retry-policy ctx) (:conf ctx) conn host retry-state)
           if retry-op == :recur
             (recur retry-state)
           else
              (throw ret-val)
        else
           ret-val

    NS: rounting
      Protocol IRounting
        select-host 
        add-host
        remove-host

    NS: io-retry
    multi-method retry-action! identity

    defmulti retry-action! :retry           [_ _ _ _ retry-state] 
                                                [retry-state (if (available-tries? retry-state) :retry nil)]

    defmulti retry-action! :blacklist-retry [ctx conn host e retry-state]
                                                (routing/blacklist! (:routing-policy ctx) (:routing-env ctx) conn host)
                                                [retry-state (if (hosts-left? ... ) :retry :nil)]

    defmulti retry-action! :default [ _ _ _ e _ ] nil

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.