Hive
Roman Klochkov <kalimehtar@mail.ru>
Hive is the framework for a client-server application with persistent object storage on server side.
(require hive/common) | package: hive-common |
This package provides functions, that will be used both on client and server sides of the hive application.
1 Network read and write
(require hive/common/read-write) | package: hive-common |
This library provides read and write for network streams. The connection is unreliable. I know, that TCP is considered reliable, but in fact, when network infrastucture drops part of packets, it may recover too slow. So, Hive uses keepalive packets and tools to control read timeout.
procedure
(write/flush data out) → void?
data : any/c out : output-port?
procedure
(read/timeout [in timeout]) → any
in : input-port? = (current-input-port)
timeout : (or/c #f (and/c real? (not/c negative?)) (-> any)) = 30
2 Serializable objects
(require hive/common/serialize) | package: hive-common |
This library provide serializable objects. It differs from racket/serialize in that it doesn’t deep copy of the object. It rather replaces all field values, that references to other objects to special ref structure. This way the library may be used to send object by network or save to file without saving all linked objects.
struct
(struct object (id) #:extra-constructor-name make-object) id : exact-nonnegative-integer?
struct
(struct ref (typename id) #:extra-constructor-name make-ref) typename : symbol? id : exact-nonnegative-integer?
procedure
(find-by-ref id objects) → (or/c #f object?)
id : exact-nonnegative-integer? objects : (listof object?)
> (find-by-ref 2 (list (object 5) (object 6))) #f
> (find-by-ref 5 (list (object 5) (object 6))) #<object>
syntax
(struct/serialize name rest ...)
procedure
(serializable? obj) → boolean?
obj : any/c
procedure
obj : serializable? prepare : (serializable? . -> . serializable?) = identity
> (struct/serialize test (a b) #:transparent) > (define data (test (object 3) 5)) > (serialize data) '(#s(ref object 3) 5)
procedure
(deserialize data deref) → any/c
data : any/c deref : (ref? . -> . any/c)
3 Users
(require hive/common/users) | package: hive-common |
struct
(struct users object (name password role online) #:extra-constructor-name make-users #:mutable) name : string? password : string? role : symbol? online : #f
name - user name, any unicode characters allowed;
password - user password;
role - user role. Hive accepts 'admin and 'user, but application may invent it’s own;
online - #t, iff user is logged on and sending keepalive packets.