Beispiel #1
0
func RegisterServerHandler(server *protocols.Server, handler HeartbeatServerHandler) error {
	if err := server.Protocol().CheckIncludesFragment(Protocol.Name()); err != nil {
		return err
	}
	return server.RegisterHandlers(protocols.ServerHandlerMap{
		codeHeartbeat: func(packet *protocols.Packet) *protocols.Packet {
			val := packet.Val
			if beat, ok := val.(*HeartbeatPacket); ok {
				handler.HeartbeatReceived(beat)
			} else {
				server.LogError(fmt.Errorf("Heartbeat received with wrong payload: (%T) %v", val, val))
			}
			return nil
		},
	})
}
Beispiel #2
0
func RegisterServer(server *protocols.Server) (*LoadStats, error) {
	if err := server.Protocol().CheckIncludesFragment(Protocol.Name()); err != nil {
		return nil, err
	}
	stats := &LoadStats{
		server:   server,
		Received: stats.NewStats("Received"),
		Missed:   stats.NewStats("Missed"),
	}
	err := server.RegisterHandlers(protocols.ServerHandlerMap{
		codeLoad: stats.handleLoad,
	})
	if err != nil {
		return nil, err
	}
	return stats, nil
}
Beispiel #3
0
func RegisterServer(server *protocols.Server, handler Handler) error {
	if err := server.Protocol().CheckIncludesFragment(Protocol.Name()); err != nil {
		return err
	}
	state := &serverState{
		Server:  server,
		handler: handler,
	}
	if err := server.RegisterHandlers(protocols.ServerHandlerMap{
		CodeRedirectStream: state.handleRedirectStream,
		CodePauseStream:    state.handlePauseStream,
		CodeResumeStream:   state.handleResumeStream,
	}); err != nil {
		return err
	}
	server.RegisterStopHandler(state.stopServer)
	return nil
}
Beispiel #4
0
func RegisterServer(server *protocols.Server, handler Handler) error {
	if err := server.Protocol().CheckIncludesFragment(Protocol.Name()); err != nil {
		return err
	}
	state := &serverState{
		Server:  server,
		handler: handler,
	}
	if err := server.RegisterHandlers(protocols.ServerHandlerMap{
		codeStartProxy:     state.handleStartProxy,
		codeStopProxy:      state.handleStopProxy,
		codeStartProxyPair: state.handleStartProxyPair,
		codeStopProxyPair:  state.handleStopProxyPair,
	}); err != nil {
		return err
	}
	server.RegisterStopHandler(state.stopServer)
	return nil
}