Exemplo n.º 1
0
func StartBrokerServer(brokerPort int, orch Orchestrator, provider IoProvider) {
	log := logging.Log("BrokerServer")
	controllerProvider := newControllerProvider(provider, orch)
	broker := NewBroker(controllerProvider)

	log.Info("Starting broker on port %d", brokerPort)
	http.ListenAndServe(fmt.Sprintf(":%d", brokerPort), broker)
}
Exemplo n.º 2
0
func NewSegmentedFileReader(dir string, pollTime time.Duration) *SegmentedFileReader {
	return &SegmentedFileReader{
		dir:         dir,
		currentFile: -1,
		pollTime:    pollTime,
		log:         logging.Log("SegmentedFileReader"),
	}
}
Exemplo n.º 3
0
func NewReplicatedFileLeader(writer io.Writer, httpStarter HttpStarter) *ReplicatedFileLeader {
	r := &ReplicatedFileLeader{
		log:         logging.Log("ReplicatedFileLeader"),
		writer:      writer,
		httpStarter: httpStarter,
		lenBuffer:   make([]byte, 4),
	}
	httpStarter.Start(http.HandlerFunc(r.handleClient))

	return r
}
Exemplo n.º 4
0
func New(clientAddr string, numberOfReplicas uint, partManager PartitionManager, kvStore KvStore) *Orchestrator {
	orch := &Orchestrator{
		log:              logging.Log("Orchestrator"),
		partManager:      partManager,
		kvStore:          kvStore,
		clientAddr:       clientAddr,
		numberOfReplicas: numberOfReplicas,
	}

	kvStore.ListenForAnnouncements(orch.participateInElection)

	return orch
}
Exemplo n.º 5
0
func NewReplicatedFileClient(url string, writer io.Writer) *ReplicatedFileClient {
	r := &ReplicatedFileClient{
		log:    logging.Log("ReplicatedFileClient"),
		writer: writer,
	}

	conn, _, err := websocket.DefaultDialer.Dial(url, nil)
	if err != nil {
		r.log.Panic("Unable to dial leader", err)
	}

	go r.run(conn)

	return r
}
Exemplo n.º 6
0
func NewSegmentedFileWriter(dir string, desiredLength, maxSegments uint64) *SegmentedFileWriter {
	log := logging.Log("SegmentedFileWriter")
	err := os.MkdirAll(dir, 0777)
	if err != nil {
		log.Panic("Failed to create directory", err)
	}
	log.Debug("Created directory %s", dir)

	return &SegmentedFileWriter{
		dir:           dir,
		desiredLength: desiredLength,
		currentLength: desiredLength + 1,
		maxSegments:   int(maxSegments),
		log:           log,
	}
}
Exemplo n.º 7
0
func New(clientAddr string, healthPort int) *KVStore {
	log := logging.Log("KVStore")
	client, err := api.NewClient(api.DefaultConfig())
	if err != nil {
		log.Panic("Unable to create client", err)
	}

	healthCheckName := fmt.Sprintf("%s-%d", CheckName, rand.Int63())

	return &KVStore{
		log:         log,
		client:      client,
		kv:          client.KV(),
		clientAddr:  clientAddr,
		sessionName: registerSession(healthPort, healthCheckName, client, log),
	}
}
Exemplo n.º 8
0
func NewConnection(URL string) (*Connection, error) {
	log := logging.Log("Connection")
	conn, _, err := websocket.DefaultDialer.Dial(URL, nil)
	if err != nil {
		return nil, err
	}

	c := &Connection{
		log:       log,
		conn:      conn,
		errCh:     make(chan error, 100),
		writeCh:   make(chan clientMsgInfo, 100),
		clientMap: make(map[uint64]chan<- *messages.Server),
	}

	go c.readCore()
	go c.writeCore()

	return c, nil
}
Exemplo n.º 9
0
func NewClient(URLs ...string) (*Client, error) {
	log := logging.Log("Client")
	var conns []*connInfo
	for _, URL := range URLs {
		verifyUrl(URL, log)
		conn, err := NewConnection(URL)
		if err != nil {
			return nil, err
		}
		conns = append(conns, &connInfo{
			URL:  URL,
			conn: conn,
		})
	}

	return &Client{
		log:     log,
		conns:   conns,
		fileIds: make(map[uint64]*connInfo),
	}, nil
}
Exemplo n.º 10
0
func NewBroker(controllerProvider ControllerProvider) *Broker {
	return &Broker{
		log:                logging.Log("Broker"),
		controllerProvider: controllerProvider,
	}
}