コード例 #1
0
ファイル: server.go プロジェクト: jmptrader/splitter
func StartReadListening(readPort int, writePort int, defaultWriters []string, mapOperation SplitterMap) {
	// Create buffer to hold data
	queue := lane.NewQueue()
	MonitorServer(queue)
	// Start listening for writer destinations
	go StartWriteListening(queue, defaultWriters, writePort)

	socket, err := net.Listen("tcp", ":"+strconv.Itoa(readPort))
	if err != nil {
		logrus.Error(err)
	}
	// This will block the main thread
	for {
		// Begin trying to accept connections
		logrus.Debug("Awaiting Connection...")
		//Block and wait for listeners
		conn, err := socket.Accept()
		if err != nil {
			logrus.Error(err)
		} else {
			logrus.Debug("Accepted Connection...")
			go HandleReadConnection(conn, queue, writePort, mapOperation)
		}
	}
}
コード例 #2
0
ファイル: gowork.go プロジェクト: ryanskidmore/GoWork
func NewServerInit(Transformer encrypt.Transformer) *WorkServer {
	Queue := lane.NewQueue()
	WorkerMembers := make(map[int]*Worker)
	Workers := &WorkersStruct{WorkerMembers, Transformer, 0}
	HandlerFuncs := make(map[string]func(*Event, map[string]interface{}))
	HandlerParams := make(map[string]interface{})
	WorkServerInst := &WorkServer{Queue, HandlerFuncs, HandlerParams, Workers}
	return WorkServerInst
}
コード例 #3
0
ファイル: idpool.go プロジェクト: sech90/go-message-hub
//Reusable pool constructor.
func NewReusableIdPool() *ReusableIdPool {

	pool := &ReusableIdPool{
		lastId:  0,
		freeIds: lane.NewQueue(),
	}

	return pool
}
コード例 #4
0
ファイル: client_conn.go プロジェクト: zzragida/goquic
func (c *Conn) CreateStream() *SpdyClientStream {
	quicClientStream := c.quicClient.CreateReliableQuicStream()
	stream := &SpdyClientStream{
		conn:             c,
		quicClientStream: quicClientStream,
		pendingReads:     lane.NewQueue(),
	}
	quicClientStream.userStream = stream
	return stream
}
コード例 #5
0
func BroadcastWithdraw(watchmetadata *Watchmedata, destinations []utilities.OPData) *lane.Queue {
	var wg sync.WaitGroup
	wg.Add(len(destinations))
	var queue *lane.Queue = lane.NewQueue()
	for i := 0; i < len(destinations); i++ {
		go callPeer(watchmetadata, &destinations[i], queue, "withdraw", &wg)
	}
	wg.Wait()
	return queue
}
コード例 #6
0
ファイル: gowork.go プロジェクト: rmulley/GoWork
func MustNewServer(Secret string) *WorkServer {
	if len(Secret) != 32 {
		panic("Secret must be 32 characters")
	}
	Queue := lane.NewQueue()
	WorkerMembers := make(map[int]*Worker)
	Workers := &WorkersStruct{WorkerMembers, Secret, 0}
	HandlerFuncs := make(map[string]func(*Event, map[string]interface{}))
	HandlerParams := make(map[string]interface{})
	WorkServerInst := &WorkServer{Queue, HandlerFuncs, HandlerParams, Workers}
	return WorkServerInst
}
コード例 #7
0
ファイル: handler_test.go プロジェクト: stratospark/torro
/*
Dial returns a new MockConnection and adds it to the set of Conns.
*/
func (t *MockConnectionFetcher) Dial(addr string) (*BTConn, error) {
	conn := &MockConnection{
		ReadQueue:         lane.NewQueue(),
		SendMessageChan:   make(chan structure.Message, 1),
		RestOfMessageChan: make(chan bool, 1),
		ReceiveBytesChan:  make(chan []byte, 1),
	}
	btc := NewBTConn(conn, addr)
	t.Conns[addr] = btc

	return btc, nil
}
コード例 #8
0
ファイル: irrational.go プロジェクト: Efruit/marqit
func (i *Irrational) Init(license xchg.LicenseID) {
	i.log.Info("Licensed", "license", license)
	i.log = log15.New("license", license)
	i.id = license
	//i.tc = make(chan Tick)
	i.cl = make(chan bool)
	i.tq = lane.NewQueue()
	i.lp = make(map[xchg.Symbol]float32)
	i.ls = make(map[xchg.Symbol]uint64)
	i.tra = make(map[xchg.AuctionID]xchg.TradeStatus)
	i.trb = make(map[xchg.BidID]xchg.TradeStatus)
	i.act = i.mkt.Bank().Open()
	i.log.Info("Bank account opened", "token", i.act)
	go i.Loop()
}
コード例 #9
0
ファイル: impl.go プロジェクト: terminiter/earthquake
func NewBasicTBQueue() TimeBoundedQueue {
	q := &BasicTBQueue{
		dequeueChan:        make(chan TimeBoundedQueueItem),
		fixedDurationQueue: lane.NewQueue(),
	}

	// TODO: gracefully shutdown this routine
	go func() {
		for {
			x := q.fixedDurationQueue.Dequeue()
			item, ok := x.(TimeBoundedQueueItem)
			if ok {
				if item.MinDuration() != item.MaxDuration() {
					panic(fmt.Errorf("minDuration != maxDuration: %#v", item))
				}
				<-time.After(item.MaxDuration())
				q.dequeueChan <- item.(TimeBoundedQueueItem)
			}
		}
	}()

	return q
}
コード例 #10
0
ファイル: job_queue.go プロジェクト: bddppq/eblance
func NewJobQueue(name string) *JobQueue {
	return &JobQueue{
		lane.NewQueue(),
	}
}
コード例 #11
0
ファイル: main.go プロジェクト: vjeko/godrone
func main() {
	f, err := os.OpenFile("/var/log/firmware", os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0666)
	if err != nil {
		panic(err)
	}
	defer f.Close()
	log.SetOutput(f)

	cutoutReason := "not calibrated"
	flag.Parse()

	log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds)
	log.Printf("Godrone started")

	var firmware *godrone.Firmware
	if *dummy {
		firmware, _ = godrone.NewCustomFirmware(&mockNavboard{}, &mockMotorboard{})
	} else {
		var err error
		firmware, err = godrone.NewFirmware()
		if err != nil {
			log.Fatalf("%s", err)
		}
		defer firmware.Close()
	}

	// This is the channel to send requests to the main control loop.
	// It is the only way to send and receive info the the
	// godrone.Firmware object (which is non-concurrent).
	//reqCh := make(chan Request)
	motorCh := make(chan *godrone.MotorPWM)

	// Autonomy/guard goroutines.
	//go monitorAngles(reqCh)
	//go lander(reqCh)

	// The websocket input goroutine.
	//go serveHttp(reqCh)

	calibrate := func() {
		for {
			// @TODO The LEDs don't seem to turn off when this is called again after
			// a calibration errors, instead they just blink. Not sure why.
			firmware.Motorboard.WriteLeds(godrone.Leds(godrone.LedOff))
			log.Printf("Calibrating sensors")
			err := firmware.Calibrate()
			if err != nil {
				firmware.Motorboard.WriteLeds(godrone.Leds(godrone.LedRed))
				time.Sleep(time.Second)
			} else {
				log.Printf("Finished calibration")
				firmware.Motorboard.WriteLeds(godrone.Leds(godrone.LedGreen))
				cutoutReason = ""
				break
			}
		}
	}
	calibrate()
	println("Success.")
	log.Print("Up, up and away!")

	var q *lane.Queue = lane.NewQueue()
	q.Enqueue([4]float64{0.0, 0.0, 0.0, 0.0})

	go handleExternal(motorCh, firmware)

	for {
		select {
		case packet := <-motorCh:

			if packet.Speed < godrone.MAX_MOTOR {
				q.Enqueue([4]float64{
					packet.Speed, packet.Speed, packet.Speed, packet.Speed})
				q.Dequeue()
				//log.Println(q.Head())
			}
		default:
		}

		time.Sleep(time.Millisecond * 10)
		v := q.Head()
		switch v := v.(type) {
		case [4]float64:
			if err := firmware.Motorboard.WriteSpeeds(v); err != nil {
				log.Printf("Failed to write speeds: %s", err)
			}
		default:
			log.Println("ERROR")
		}
	}

	//go rotate(queue, motorCh)

	// This is the main control loop.
	/*
		flying := false
		for {
			select {
			case req := <-reqCh:
				var res Response
				res.Cutout = cutoutReason
				res.Actual = firmware.Actual
				res.Desired = firmware.Desired
				res.Time = time.Now()

				if req.SetDesired != nil {
					// Log changes to desired
					if Verbose() && firmware.Desired != *req.SetDesired {
						log.Print("New desired attitude:", firmware.Desired)
					}
					firmware.Desired = *req.SetDesired
				}
				if req.Cutout != "" {
					cutoutReason = req.Cutout
					log.Print("Cutout: ", cutoutReason)
					firmware.Desired.Altitude = 0
				}
				if req.Calibrate {
					calibrate()
				}
				req.response <- res
				if reallyVerbose() {
					log.Print("Request: ", req, "Response: ", res)
				}
			default:
			}

			var err error
			if firmware.Desired.Altitude > 0 {
				err = firmware.Control()
				flying = true
			} else {
				// Something subtle to note here: When the motors are running,
				// but then desired altitude goes to zero (for instance due to
				// the emergency command in the UI) we end up here.
				//
				// We never actually send a motors=0 command. Instead we count on
				// the failsafe behavior of the motorboard, which puts the motors to
				// zero if it does not receive a new motor command soon enough.
				err = firmware.Observe()
				if flying {
					log.Print("Motor cutoff.")
					flying = false
				}
			}
			if err != nil {
				log.Printf("%s", err)
			}
		}
	*/
}
コード例 #12
0
ファイル: Controller.go プロジェクト: Melinysh/Project-Clay
	"github.com/oleiade/lane"
)

type Controller struct {
	a Analyzer
	c Collector
}

var myAnalyzer = newAnalyzer()

var usersInPrimaryQueue = &map[int64]bool{}
var usersInSecondaryQueue = &map[int64]bool{}
var usersInTertiaryQueue = &map[int64]bool{}
var usersInRelationsQueue = &map[int64]bool{}

var globalPrimaryUserFetchQueue = lane.NewQueue()
var globalSecondaryUserFetchQueue = lane.NewQueue()
var globalTertiaryUserFetchQueue = lane.NewQueue()

var globalAppFavouritesFetchQueue = lane.NewQueue()
var globalAppTweetFetchQueue = lane.NewQueue()

var globalUserTweetFetchQueue = lane.NewQueue()
var globalUserFavouritesFetchQueue = lane.NewQueue()

var globalRelationsFetchQueue = lane.NewQueue()

func main() {
	fmt.Println("\n\tWelcome.")
	fmt.Println("-=-=-=- CLAY v1.2.1 =-=-=-=")
	fmt.Println("Let's begin.")