Documentation ¶
Overview ¶
stadis provide distributed system layer on top of localhost on a single machine
Index ¶
- Variables
- func Listen(network, addr, name string) (l net.Listener, err error)
- func NewDialFunc(clientName string, timeout time.Duration) func(network, addr string) (conn net.Conn, err error)
- func NewListener(ol net.Listener, name string) (l net.Listener, err error)
- type ApiClient
- func (client *ApiClient) ClientConnected(name, port string) error
- func (client *ApiClient) ClientDisconnected(port string) error
- func (client *ApiClient) ConnState(clientPort, serverPort string, oldState *ConnState) (state *ConnState, err error)
- func (client *ApiClient) DialState(clientName, serverPort string) (state ConnState, err error)
- func (client *ApiClient) NodeState(name string) (nodeState NodeState, err error)
- func (client *ApiClient) ServerStarted(name, port string) error
- func (client *ApiClient) ServerStopped(name, port string) error
- func (client *ApiClient) StartProxy(clientName, proxyName, proxyPort, originAddr string) (err error)
- func (client *ApiClient) StopProxy(proxyPort string) (err error)
- func (client *ApiClient) UpdateConfig(reader io.Reader) (err error)
- func (client *ApiClient) UpdateNodeState(name string, nodeState NodeState) (err error)
- func (client *ApiClient) UpdateProxy(clientName, proxyPort string) (err error)
- type ApiServer
- type Config
- type ConnState
- type DataCenter
- type Host
- type NodeState
- type Rack
Constants ¶
This section is empty.
Variables ¶
var Cli = &ApiClient{ApiAddr: "localhost:8989"}
Default API client
var DefaultConfig = []byte(`
{
"DcDefault":{"Latency":100000000},
"RackDefault":{"Latency":10000000},
"HostDefault":{"Latency":1000000},
"DataCenters":[
{
"Name":"animal",
"Racks":[
{
"Name":"land",
"Hosts":[{"Name":"tiger"},{"Name":"lion"},{"Name":"wolf"}]
},
{
"Name":"sea",
"Hosts":[{"Name":"shark"},{"Name":"whale"},{"Name":"cod"}]
},
{
"Name":"air",
"Hosts":[{"Name":"eagle"},{"Name":"crow"},{"Name":"owl"}]
}
]
},
{
"Name":"plant",
"Racks":[
{
"Name":"fruit",
"Hosts":[{"Name":"apple"},{"Name":"pear"},{"Name":"grape"}]
},
{
"Name":"crop",
"Hosts":[{"Name":"corn"},{"Name":"rice"},{"Name":"wheat"}]
},
{
"Name":"flower",
"Hosts":[{"Name":"rose"},{"Name":"lily"},{"Name":"lotus"}]
}
]
},
{
"Name":"matter",
"Racks":[
{
"Name":"metal",
"Hosts":[{"Name":"gold"},{"Name":"silver"},{"Name":"iron"}]
},
{
"Name":"gem",
"Hosts":[{"Name":"ruby"},{"Name":"ivory"},{"Name":"pearl"}]
},
{
"Name":"liquid",
"Hosts":[{"Name":"water"},{"Name":"oil"},{"Name":"wine"}]
}
]
}
]
}
`)
var NumOfPackets = 128
Each packet is 4KB, so buffer size is 4KB*NumOfPackets which by default is 512KB, Larger buffer size gets more throughput, consume more memory.
Functions ¶
func NewDialFunc ¶
Types ¶
type ApiClient ¶
type ApiClient struct {
ApiAddr string
}
func (*ApiClient) ClientConnected ¶
Register client port at API server. Should be called after client created a connection.
func (*ApiClient) ClientDisconnected ¶
Unregister client port at API server. Should be called after client closed a connection.
func (*ApiClient) ConnState ¶
func (client *ApiClient) ConnState(clientPort, serverPort string, oldState *ConnState) (state *ConnState, err error)
Get the current connection state for the connection between 'clientPort' and 'serverPort'. If 'oldState' is provided, this request will do long-polling, blocking for a few seconds before get response if there is no new state updated.
func (*ApiClient) DialState ¶
Get the dial state which can be used to simulate network latency or failure before actually dial the server.
func (*ApiClient) ServerStarted ¶
Register the server port on API server. Should be called after open a listener.
func (*ApiClient) ServerStopped ¶
Unregister the server port on API server. Should be called after closed a listener.
func (*ApiClient) StartProxy ¶
func (client *ApiClient) StartProxy(clientName, proxyName, proxyPort, originAddr string) (err error)
Start a proxy server in API server process. The 'clientName' going to be used to register a client port at API server when the proxy server accepts a new connection, For example, if you pass 'matter.metal.gold' as clientName, every client connected to the proxy server will be considered located at 'matter.metal.gold'. This can be updated after the proxy is open, but only one 'clientName' can be used by a proxy server at a time.
func (*ApiClient) UpdateConfig ¶
Update the API server config, the topology on API server will be rebuild. You can use the 'DefaultConfig' as a base config, then do some modification to meet your requirement.
func (*ApiClient) UpdateNodeState ¶
Set the node's state, the name can be dc, rack or host depends on the number of dot in the name. If latency of the nodeState is zero, the target node's latency will stay unchanged.
func (*ApiClient) UpdateProxy ¶
Update the 'clientName' for a proxy server, so future connection will be registered with the new name. This will not affect connections that have been registered already.
type ApiServer ¶
type ApiServer struct {
// contains filtered or unexported fields
}
The API server holds the state of topology and proxy servers, serve requests from API client.
func NewApiServer ¶
func NewApiServer() (ms *ApiServer)
type Config ¶
type Config struct { DcDefault *NodeState RackDefault *NodeState HostDefault *NodeState DataCenters []*DataCenter }