Documentation
¶
Index ¶
- Constants
- Variables
- type Attributes
- type BroadcastPacket
- type Element
- func (element *Element) Add(content ...interface{}) *Element
- func (element *Element) GetAttribute(name string, defaultValue string) string
- func (element *Element) GetBoolAttribute(name string, defaultValue bool) bool
- func (element *Element) GetChild(name string) *Element
- func (element *Element) GetChildren(name string) []*Element
- func (element *Element) GetIntAttribute(name string, defaultValue int) int
- func (element *Element) GetValue() string
- func (element *Element) RemoveAttribute(name string)
- func (element *Element) SetAttribute(name string, value interface{})
- func (element *Element) SetAttributes(setMap map[string]interface{})
- func (element Element) String() string
- type EndPoint
- func (endPoint *EndPoint) AddLoggingHandler(defaultLoggers []string) *EndPoint
- func (endPoint *EndPoint) Close() error
- func (endPoint *EndPoint) DisableLogging(names string)
- func (endPoint *EndPoint) EnableLogging(names string) *EndPoint
- func (endPoint *EndPoint) GetActiveLoggerNames() []string
- func (endPoint *EndPoint) GetLoggerNames() []string
- func (endPoint *EndPoint) IsConnected() error
- func (endPoint *EndPoint) IsStarted() bool
- func (endPoint *EndPoint) Log(name string) OptionalLogger
- func (endPoint *EndPoint) Message(content ...interface{}) *Packet
- func (endPoint *EndPoint) Name() string
- func (endPoint *EndPoint) OnClose(f func(endPoint *EndPoint)) *EndPoint
- func (endPoint *EndPoint) OnPacketReceived(f func(packet *Packet) bool) *EndPoint
- func (endPoint *EndPoint) Request(content ...interface{}) *Packet
- func (endPoint *EndPoint) SetName(name string) *EndPoint
- func (endPoint *EndPoint) Start() *EndPoint
- func (endPoint *EndPoint) String() string
- type NullLogger
- func (l NullLogger) Fatal(v ...interface{})
- func (l NullLogger) Fatalf(f string, v ...interface{})
- func (l NullLogger) Fatalln(v ...interface{})
- func (l NullLogger) Flags() int
- func (l NullLogger) Output(depth int, s string) error
- func (l NullLogger) Panic(v ...interface{})
- func (l NullLogger) Panicf(f string, v ...interface{})
- func (l NullLogger) Panicln(v ...interface{})
- func (l NullLogger) Prefix() string
- func (l NullLogger) Print(v ...interface{})
- func (l NullLogger) Printf(f string, v ...interface{})
- func (l NullLogger) Println(v ...interface{})
- func (l NullLogger) SetFlags(flag int)
- func (l NullLogger) SetOutput(w io.Writer)
- func (l NullLogger) SetPrefix(prefix string)
- func (l NullLogger) Writer() io.Writer
- type OptionalLogger
- type Packet
- func (requestPacket *Packet) Exception(exception error, content ...interface{}) *Packet
- func (requestPacket *Packet) GetRequestId() (int, error)
- func (packet *Packet) GetType() string
- func (packet *Packet) IsRequest() bool
- func (maybeRequestPacket *Packet) OptionalReply(content ...interface{}) *Packet
- func (requestPacket *Packet) Reply(content ...interface{}) *Packet
- func (packet *Packet) Send() error
- func (pakcet Packet) String() string
- func (packet *Packet) Submit(ctx ctx.Context) chan SubmitResult
- type Service
- func (service *Service) Broadcast(packet *BroadcastPacket, ...) error
- func (service *Service) DisableLogging(names string)
- func (service *Service) EnableLogging(names string) *Service
- func (service *Service) GetLoggerNames() []string
- func (service *Service) Log(name string) OptionalLogger
- func (service *Service) Message(content ...interface{}) *BroadcastPacket
- func (service *Service) Terminate()
- type SubmitResult
Constants ¶
const CausalityAttributeName = "Causality"
const LogEndPoint = "EndPoint"
const LogMessages = "Messages"
const LogService = "Service"
const RequestIdAttributeName = "_RequestId"
Variables ¶
var ErrEndPointDisconnected = fmt.Errorf("EndPoint disconnnected")
Functions ¶
This section is empty.
Types ¶
type Attributes ¶
type Attributes map[string]interface{}
type BroadcastPacket ¶
func (*BroadcastPacket) Broadcast ¶
func (broadcastPacket *BroadcastPacket) Broadcast(sendPredicate func(endPoint *EndPoint, packet *BroadcastPacket) bool) error
func (BroadcastPacket) String ¶
func (packet BroadcastPacket) String() string
type Element ¶
type Element struct {
Name string
Attributes Attributes
Children []interface{}
}
func NewElement ¶
Create new element with a given name You can add any number of attributes or child elements
For example:
element := ms.NewElement("Message", &Attributes{"Type" : "Warning", "Context" : "Unknwon", "Id": 1}, NewElement("Child"))
func (*Element) GetAttribute ¶
func (*Element) GetBoolAttribute ¶
func (*Element) GetChildren ¶
func (*Element) GetIntAttribute ¶
func (*Element) RemoveAttribute ¶
func (*Element) SetAttribute ¶
func (*Element) SetAttributes ¶
type EndPoint ¶
type EndPoint struct {
Connection net.Conn
Service *Service
Id int
Info interface{}
UseCausality bool // Use Causality attribute in addition to _RequestID for backward compatability
// contains filtered or unexported fields
}
EndPoint - a message stream end point is used to send/receive messages to another end point
func NewEndPoint ¶
Create a new end point and associate it with a connection
name - the end point's name. When calling NewEndPoint from a service createEndPoint call back,
you can use an empty string to assign default name (serivce name with end point id suffix)
Usually you will assign packet recieved callback also do not forget to start the end point if not created in the context of a service createEndPoint callback
Example:
conn, err := net.Dial("tcp", "someserver.com")
endPoint := ms.NewEndPoint("MyConnection", conn).OnPacketReceived(func (packet *msPacket) {
fmt.Println("Received:", packet)
}).Start()
func (*EndPoint) AddLoggingHandler ¶
Add an handler for _Log messages
The message has the following format ¶
_Log [Name={list of to log}] [Scope="EndPoint"|"Service"] [Disable=True|False]
Default scope is Service (logging of this type will be applied to all EndPoint created by this service) If no specific logger Names are given, MessageStream related logs along with a supplied list of logger names will be enabled (or disabled)
func (*EndPoint) DisableLogging ¶
Disable a logger with a given name. If logger is disable then things of this type will not be logged
For example:
endPoint.DisableLogger("Messages") will stop logging of all messages received/sent by the end point
func (*EndPoint) EnableLogging ¶
Enable a logger with a given name. If logger is enabled then things of this type will be logged
For example:
endPoint.EnableLogger("Messages") will cause all messages received/sent by the end point to be logged
func (*EndPoint) GetActiveLoggerNames ¶
Get a list of all the logger which are enabled, both loggers which are enabled just for this end point and those enabled for the service
func (*EndPoint) GetLoggerNames ¶
Get a list of all the loggers which are enabled for this end point (this does not include loggers which are enabled for the service)
func (*EndPoint) Log ¶
func (endPoint *EndPoint) Log(name string) OptionalLogger
Get a logger with a specific name.
If the logger is enabled, a logger that does something is returned If the logger is not enabled, a logger which does nothing is returned
A typical usage:
endPoint.Log("LogTemperatures").Println("It is hot today")
A logger can be enabled either in end point scope (only for this specific endpoint) or in a service scope (for all endpoint created by the service)
func (*EndPoint) Message ¶
Create a message that can be sent
endPoint.Message(Attributes{"Type" : "SundayArrived"}).Send()
func (*EndPoint) OnClose ¶
Add end point close handler (function called when end point is closed)
end point is either explicitly closed by calling endPoint.Close() or when the connection is terminated
func (*EndPoint) OnPacketReceived ¶
Add packet receive handler (function called when a new packet is received)
func (*EndPoint) Request ¶
Create a request packet that can submitted
reply := <- endPoint.Request(Attributes{"Type" : "FindMyWife"}).Submit()
func (*EndPoint) Start ¶
Start (activate the end point)
The following code is typical for creating a client side end point
conn, err := net.Dial("tcp", "someserver.com")
endPoint := ms.NewEndPoint("MyConnection", conn).OnPacketReceived(func (packet *msPacket) {
fmt.Println("Received:", packet)
}).Start()
type NullLogger ¶
type NullLogger struct{}
func (NullLogger) Fatal ¶
func (l NullLogger) Fatal(v ...interface{})
func (NullLogger) Fatalf ¶
func (l NullLogger) Fatalf(f string, v ...interface{})
func (NullLogger) Fatalln ¶
func (l NullLogger) Fatalln(v ...interface{})
func (NullLogger) Flags ¶
func (l NullLogger) Flags() int
func (NullLogger) Panic ¶
func (l NullLogger) Panic(v ...interface{})
func (NullLogger) Panicf ¶
func (l NullLogger) Panicf(f string, v ...interface{})
func (NullLogger) Panicln ¶
func (l NullLogger) Panicln(v ...interface{})
func (NullLogger) Prefix ¶
func (l NullLogger) Prefix() string
func (NullLogger) Print ¶
func (l NullLogger) Print(v ...interface{})
func (NullLogger) Printf ¶
func (l NullLogger) Printf(f string, v ...interface{})
func (NullLogger) Println ¶
func (l NullLogger) Println(v ...interface{})
func (NullLogger) SetFlags ¶
func (l NullLogger) SetFlags(flag int)
func (NullLogger) SetOutput ¶
func (l NullLogger) SetOutput(w io.Writer)
func (NullLogger) SetPrefix ¶
func (l NullLogger) SetPrefix(prefix string)
func (NullLogger) Writer ¶
func (l NullLogger) Writer() io.Writer
type OptionalLogger ¶
type OptionalLogger interface {
Fatal(v ...interface{})
Fatalf(f string, v ...interface{})
Fatalln(v ...interface{})
Flags() int
Output(depth int, s string) error
Panic(v ...interface{})
Panicf(f string, v ...interface{})
Panicln(v ...interface{})
Prefix() string
Print(v ...interface{})
Printf(f string, v ...interface{})
Println(v ...interface{})
SetFlags(flag int)
SetOutput(w io.Writer)
SetPrefix(prefix string)
Writer() io.Writer
}
Interface for something that act as a logger, this can be either the logger returned by log.NewLogger or null logger which log nothing
type Packet ¶
func (*Packet) GetRequestId ¶
Return requestID (if one exists)
func (*Packet) OptionalReply ¶
OptionalReply - create reply packet if the sending packet is request. Otherwise, return null
func (*Packet) Reply ¶
Create a reply to a request
didSundayArrivedRequest.Reply(Attributes{"Answer" : true}).Send()
type Service ¶
type Service struct {
Name string
Info interface{}
// contains filtered or unexported fields
}
Service - wait for connection request, associate each incoming connection request with an end point which then processes received messages
func NewService ¶
func NewService(name string, network string, address string, info interface{}, createEndPoint func(service *Service, conn net.Conn) *EndPoint) *Service
Create a new service (server side):
name - service name
metwork, address - where sevice will listen
createEndPoint - function that associats end point with accepted connection
Example:
myService := ms.NewService("My service", "tcp", ":1000", func (service *ms.Service, conn ney.Conn) *ms.EndPoint) {
return ms.NewEndPoint("", conn).OnPacketReceived(func (packet *ms.Packet) {
// Do something with the packet...
})
})
func (*Service) Broadcast ¶
func (service *Service) Broadcast(packet *BroadcastPacket, sendPredicate func(endPoint *EndPoint, packet *BroadcastPacket) bool) error
Broadcast a packet to all streams connected to a service
func (*Service) DisableLogging ¶
Disable a logger with a given name. If logger is disable then things of this type will not be logged
For example:
servicet.DisableLogger("Service") will stop logging of service state related messages
func (*Service) EnableLogging ¶
Enable a logger with a given name. If logger is enabled then things of this type will be logged
For example:
service.EnableLogger("Service") will cause all messages assocaited with service state to be logged
func (*Service) GetLoggerNames ¶
Get a list of all the loggers which are enabled for this service
func (*Service) Log ¶
func (service *Service) Log(name string) OptionalLogger
Get a logger with a specific name.
If the logger is enabled, a logger that does something is returned If the logger is not enabled, a logger which does nothing is returned
A typical usage:
service.Log("LogTemperatures").Println("It is hot today")
func (*Service) Message ¶
func (service *Service) Message(content ...interface{}) *BroadcastPacket
Create message that is suitable for broadcasting
service.Bradcast(Message(Attributes{"Type": "SundayArrived"}))