Exemplo n.º 1
0
// New creates a new Service, using the given Router and WebServer.
// If the router has already a configured Cluster, it is registered as a service module.
// The Router and Webserver are then registered as modules.
func New(router router.Router, webserver *webserver.WebServer) *Service {
	s := &Service{
		webserver:       webserver,
		router:          router,
		healthFrequency: defaultHealthFrequency,
		healthThreshold: defaultHealthThreshold,
	}
	cluster := router.Cluster()
	if cluster != nil {
		s.RegisterModules(1, 5, cluster)
		router.Cluster().Router = router
	}
	s.RegisterModules(2, 2, s.router)
	s.RegisterModules(3, 4, s.webserver)
	return s
}
Exemplo n.º 2
0
// NewWSHandler returns a new WSHandler.
func NewWSHandler(router router.Router, prefix string) (*WSHandler, error) {
	accessManager, err := router.AccessManager()
	if err != nil {
		return nil, err
	}
	return &WSHandler{
		router:        router,
		prefix:        prefix,
		accessManager: accessManager,
	}, nil
}
Exemplo n.º 3
0
// NewReceiverFromCmd parses the info in the command
func NewReceiverFromCmd(
	applicationID string,
	cmd *protocol.Cmd,
	sendChannel chan []byte,
	router router.Router,
	userID string) (rec *Receiver, err error) {

	messageStore, err := router.MessageStore()
	if err != nil {
		return nil, err
	}

	rec = &Receiver{
		applicationID:       applicationID,
		sendC:               sendChannel,
		router:              router,
		messageStore:        messageStore,
		cancelC:             make(chan bool, 1),
		enableNotifications: true,
		userID:              userID,
	}
	if len(cmd.Arg) == 0 || cmd.Arg[0] != '/' {
		return nil, fmt.Errorf("command requires at least a path argument, but non given")
	}

	args := strings.SplitN(cmd.Arg, " ", 3)
	rec.path = protocol.Path(args[0])

	if len(args) > 1 {
		rec.doFetch = true
		rec.startID, err = strconv.ParseInt(args[1], 10, 64)
		if err != nil {
			return nil, fmt.Errorf("startid has to be empty or int, but was %q: %v", args[1], err)
		}
	}

	rec.doSubscription = true
	if len(args) > 2 {
		rec.doSubscription = false
		rec.maxCount, err = strconv.Atoi(args[2])
		if err != nil {
			return nil, fmt.Errorf("maxCount has to be empty or int, but was %q: %v", args[1], err)
		}
	}

	return rec, nil
}
Exemplo n.º 4
0
func NewConnector(router router.Router, sender Sender, config Config) (Connector, error) {
	kvs, err := router.KVStore()
	if err != nil {
		return nil, err
	}

	if config.Workers <= 0 {
		config.Workers = DefaultWorkers
	}

	c := &connector{
		config:  config,
		sender:  sender,
		manager: NewManager(config.Schema, kvs),
		queue:   NewQueue(sender, config.Workers),
		router:  router,
		kvstore: kvs,
		logger:  logger.WithField("name", config.Name),
	}
	c.initMuxRouter()
	return c, nil
}