本文整理匯總了Golang中github.com/msackman/chancell.ChanCellHead類的典型用法代碼示例。如果您正苦於以下問題:Golang ChanCellHead類的具體用法?Golang ChanCellHead怎麽用?Golang ChanCellHead使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ChanCellHead類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: actorLoop
func (conn *Connection) actorLoop(head *cc.ChanCellHead) {
var (
err error
stateChanged bool
oldState connectionStateMachineComponent
queryChan <-chan connectionMsg
queryCell *cc.ChanCell
)
chanFun := func(cell *cc.ChanCell) { queryChan, queryCell = conn.queryChan, cell }
head.WithCell(chanFun)
terminate := false
for !terminate {
stateChanged = oldState != conn.currentState
if stateChanged {
oldState = conn.currentState
terminate, err = conn.currentState.start()
} else {
if msg, ok := <-queryChan; ok {
terminate, err = conn.handleMsg(msg)
} else {
head.Next(queryCell, chanFun)
}
}
terminate = terminate || err != nil
}
conn.cellTail.Terminate()
conn.handleShutdown(err)
log.Println("Connection terminated")
}
示例2: actorLoop
func (l *Listener) actorLoop(head *cc.ChanCellHead) {
connectionCount := uint32(0)
var (
err error
queryChan <-chan listenerMsg
queryCell *cc.ChanCell
)
chanFun := func(cell *cc.ChanCell) { queryChan, queryCell = l.queryChan, cell }
head.WithCell(chanFun)
terminate := false
for !terminate {
if msg, ok := <-queryChan; ok {
switch msgT := msg.(type) {
case *listenerMsgShutdown:
terminate = true
case listenerAcceptError:
err = msgT
case *listenerConnMsg:
connectionCount++
NewConnectionFromTCPConn((*net.TCPConn)(msgT), l.connectionManager, connectionCount)
}
terminate = terminate || err != nil
} else {
head.Next(queryCell, chanFun)
}
}
if err != nil {
log.Println("Listen error:", err)
}
l.cellTail.Terminate()
l.listener.Close()
}
示例3: actorLoop
func (reader *mdbReader) actorLoop(readerHead *cc.ChanCellHead) {
runtime.LockOSThread()
var (
err error
readerChan <-chan mdbQuery
readerCell *cc.ChanCell
)
chanFun := func(cell *cc.ChanCell) { readerChan, readerCell = reader.server.readerChan, cell }
readerHead.WithCell(chanFun)
terminate := false
for !terminate {
if query, ok := <-readerChan; ok {
switch msg := query.(type) {
case *readonlyTransactionFuture:
err = reader.handleRunTxn(msg)
case *queryInternalShutdown:
((*sync.WaitGroup)(msg)).Done()
terminate = true
default:
err = UnexpectedMessage
}
} else {
readerHead.Next(readerCell, chanFun)
}
terminate = terminate || err != nil
}
if err != nil {
log.Println(err)
}
}
示例4: actorLoop
func (cm *ConnectionManager) actorLoop(head *cc.ChanCellHead) {
var (
err error
queryChan <-chan connectionManagerMsg
queryCell *cc.ChanCell
)
chanFun := func(cell *cc.ChanCell) { queryChan, queryCell = cm.queryChan, cell }
head.WithCell(chanFun)
terminate := false
var shutdownChan chan struct{}
for !terminate {
if msg, ok := <-queryChan; ok {
switch msgT := msg.(type) {
case connectionManagerMsgShutdown:
shutdownChan = msgT
terminate = true
case *connectionManagerMsgSetDesired:
cm.setDesiredServers(msgT)
case *connectionManagerMsgServerEstablished:
cm.serverEstablished((*Connection)(msgT))
case *connectionManagerMsgServerLost:
cm.serverLost((*Connection)(msgT))
case connectionManagerMsgSenderStart:
cm.startSender(msgT.Sender)
case connectionManagerMsgSenderFinished:
cm.removeSender(msgT.Sender, msgT.resultChan)
case *connectionManagerMsgSetTopology:
cm.updateTopology((*server.Topology)(msgT))
case *connectionManagerMsgGetTopology:
cm.getTopology(msgT)
case *connectionManagerMsgClientEstablished:
cm.clientEstablished(msgT)
case *connectionManagerMsgStatus:
cm.status((*server.StatusConsumer)(msgT))
}
terminate = terminate || err != nil
} else {
head.Next(queryCell, chanFun)
}
}
if err != nil {
log.Println("ConnectionManager error:", err)
}
cm.cellTail.Terminate()
for _, conn := range cm.servers {
conn.Shutdown(true)
}
if shutdownChan != nil {
close(shutdownChan)
}
}
示例5: actorLoop
func (lc *LocalConnection) actorLoop(head *cc.ChanCellHead) {
lc.connectionManager.AddSender(lc)
var (
err error
queryChan <-chan localConnectionMsg
queryCell *cc.ChanCell
)
chanFun := func(cell *cc.ChanCell) { queryChan, queryCell = lc.queryChan, cell }
head.WithCell(chanFun)
terminate := false
for !terminate {
if msg, ok := <-queryChan; ok {
switch msgT := msg.(type) {
case *localConnectionMsgShutdown:
terminate = true
case *localConnectionMsgTopologyChange:
lc.submitter.TopologyChange(msgT.topology, msgT.servers)
case *localConnectionMsgRunTxn:
lc.runTransaction(msgT)
case *localConnectionMsgRunClientTxn:
lc.runClientTransaction(msgT)
case localConnectionMsgOutcomeReceived:
msgT(lc)
case localConnectionMsgDisableHashCodes:
lc.submitter.TopologyChange(nil, msgT)
case *localConnectionMsgStatus:
lc.status((*server.StatusConsumer)(msgT))
}
terminate = terminate || err != nil
} else {
head.Next(queryCell, chanFun)
}
}
if err != nil {
log.Println("LocalConnection error:", err)
}
lc.connectionManager.RemoveSenderAsync(lc)
lc.submitter.Shutdown()
lc.cellTail.Terminate()
}
示例6: loop
func (exe *Executor) loop(head *cc.ChanCellHead) {
terminate := false
var (
queryChan <-chan executorQuery
queryCell *cc.ChanCell
)
chanFun := func(cell *cc.ChanCell) { queryChan, queryCell = exe.queryChan, cell }
head.WithCell(chanFun)
for !terminate {
if msg, ok := <-queryChan; ok {
switch query := msg.(type) {
case *shutdownQuery:
terminate = true
case applyQuery:
query()
}
} else {
head.Next(queryCell, chanFun)
}
}
exe.cellTail.Terminate()
}