How to use Alive method of refactor Package

Best Gauge code snippet using refactor.Alive

group__.go

Source:group__.go Github

copy

Full Screen

...113 defer group.mutex.Unlock()114 group.tickPullModule()115 group.startPushIfNeeded()116 // 定时关闭没有数据的session117 if tickCount%checkSessionAliveIntervalSec == 0 {118 group.disposeInactiveSessions()119 }120 // 定时计算session bitrate121 if tickCount%calcSessionStatIntervalSec == 0 {122 group.updateAllSessionStat()123 }124}125// Dispose ...126func (group *Group) Dispose() {127 Log.Infof("[%s] lifecycle dispose group.", group.UniqueKey)128 group.exitChan <- struct{}{}129 group.mutex.Lock()130 defer group.mutex.Unlock()131 if group.rtmpPubSession != nil {132 group.rtmpPubSession.Dispose()133 }134 if group.rtspPubSession != nil {135 group.rtspPubSession.Dispose()136 }137 for session := range group.rtmpSubSessionSet {138 session.Dispose()139 }140 group.rtmpSubSessionSet = nil141 for session := range group.rtspSubSessionSet {142 session.Dispose()143 }144 group.rtspSubSessionSet = nil145 for session := range group.httpflvSubSessionSet {146 session.Dispose()147 }148 group.httpflvSubSessionSet = nil149 for session := range group.httptsSubSessionSet {150 session.Dispose()151 }152 group.httptsSubSessionSet = nil153 group.delIn()154}155// ---------------------------------------------------------------------------------------------------------------------156func (group *Group) StringifyDebugStats(maxsub int) string {157 b, _ := json.Marshal(group.GetStat(maxsub))158 return string(b)159}160func (group *Group) GetStat(maxsub int) base.StatGroup {161 // TODO(chef): [refactor] param maxsub162 group.mutex.Lock()163 defer group.mutex.Unlock()164 if group.rtmpPubSession != nil {165 group.stat.StatPub = base.Session2StatPub(group.rtmpPubSession)166 } else if group.rtspPubSession != nil {167 group.stat.StatPub = base.Session2StatPub(group.rtspPubSession)168 } else {169 group.stat.StatPub = base.StatPub{}170 }171 group.stat.StatPull = group.getStatPull()172 group.stat.StatSubs = nil173 var statSubCount int174 for s := range group.rtmpSubSessionSet {175 statSubCount++176 if statSubCount > maxsub {177 break178 }179 group.stat.StatSubs = append(group.stat.StatSubs, base.Session2StatSub(s))180 }181 for s := range group.httpflvSubSessionSet {182 statSubCount++183 if statSubCount > maxsub {184 break185 }186 group.stat.StatSubs = append(group.stat.StatSubs, base.Session2StatSub(s))187 }188 for s := range group.httptsSubSessionSet {189 statSubCount++190 if statSubCount > maxsub {191 break192 }193 group.stat.StatSubs = append(group.stat.StatSubs, base.Session2StatSub(s))194 }195 for s := range group.rtspSubSessionSet {196 statSubCount++197 if statSubCount > maxsub {198 break199 }200 group.stat.StatSubs = append(group.stat.StatSubs, base.Session2StatSub(s))201 }202 return group.stat203}204func (group *Group) KickSession(sessionId string) bool {205 group.mutex.Lock()206 defer group.mutex.Unlock()207 Log.Infof("[%s] kick out session. session id=%s", group.UniqueKey, sessionId)208 if strings.HasPrefix(sessionId, base.UkPreRtmpServerSession) {209 if group.rtmpPubSession != nil && group.rtmpPubSession.UniqueKey() == sessionId {210 group.rtmpPubSession.Dispose()211 return true212 }213 for s := range group.rtmpSubSessionSet {214 if s.UniqueKey() == sessionId {215 s.Dispose()216 return true217 }218 }219 } else if strings.HasPrefix(sessionId, base.UkPreRtmpPullSession) || strings.HasPrefix(sessionId, base.UkPreRtspPullSession) {220 return group.kickPull(sessionId)221 } else if strings.HasPrefix(sessionId, base.UkPreRtspPubSession) {222 if group.rtspPubSession != nil && group.rtspPubSession.UniqueKey() == sessionId {223 group.rtspPubSession.Dispose()224 return true225 }226 } else if strings.HasPrefix(sessionId, base.UkPreFlvSubSession) {227 // TODO chef: 考虑数据结构改成sessionIdzuokey的map228 for s := range group.httpflvSubSessionSet {229 if s.UniqueKey() == sessionId {230 s.Dispose()231 return true232 }233 }234 } else if strings.HasPrefix(sessionId, base.UkPreTsSubSession) {235 for s := range group.httptsSubSessionSet {236 if s.UniqueKey() == sessionId {237 s.Dispose()238 return true239 }240 }241 } else if strings.HasPrefix(sessionId, base.UkPreRtspSubSession) {242 for s := range group.rtspSubSessionSet {243 if s.UniqueKey() == sessionId {244 s.Dispose()245 return true246 }247 }248 } else {249 Log.Errorf("[%s] kick session while session id format invalid. %s", group.UniqueKey, sessionId)250 }251 return false252}253func (group *Group) IsInactive() bool {254 group.mutex.Lock()255 defer group.mutex.Unlock()256 return group.isTotalEmpty() && !group.isPullModuleAlive()257}258func (group *Group) HasInSession() bool {259 group.mutex.Lock()260 defer group.mutex.Unlock()261 return group.hasInSession()262}263func (group *Group) HasOutSession() bool {264 group.mutex.Lock()265 defer group.mutex.Unlock()266 return group.hasOutSession()267}268func (group *Group) OutSessionNum() int {269 // TODO(chef): 没有包含hls的播放者270 group.mutex.Lock()271 defer group.mutex.Unlock()272 pushNum := 0273 for _, item := range group.url2PushProxy {274 // TODO(chef): [refactor] 考虑只判断session是否为nil 202205275 if item.isPushing && item.pushSession != nil {276 pushNum++277 }278 }279 return len(group.rtmpSubSessionSet) + len(group.rtspSubSessionSet) + len(group.httpflvSubSessionSet) + len(group.httptsSubSessionSet) + pushNum280}281// ---------------------------------------------------------------------------------------------------------------------282// disposeInactiveSessions 关闭不活跃的session283//284// TODO chef: [refactor] 梳理和naza.Connection超时重复部分285//286func (group *Group) disposeInactiveSessions() {287 if group.rtmpPubSession != nil {288 if readAlive, _ := group.rtmpPubSession.IsAlive(); !readAlive {289 Log.Warnf("[%s] session timeout. session=%s", group.UniqueKey, group.rtmpPubSession.UniqueKey())290 group.rtmpPubSession.Dispose()291 }292 }293 if group.rtspPubSession != nil {294 if readAlive, _ := group.rtspPubSession.IsAlive(); !readAlive {295 Log.Warnf("[%s] session timeout. session=%s", group.UniqueKey, group.rtspPubSession.UniqueKey())296 group.rtspPubSession.Dispose()297 }298 }299 group.disposeInactivePullSession()300 for session := range group.rtmpSubSessionSet {301 if _, writeAlive := session.IsAlive(); !writeAlive {302 Log.Warnf("[%s] session timeout. session=%s", group.UniqueKey, session.UniqueKey())303 session.Dispose()304 }305 }306 for session := range group.rtspSubSessionSet {307 if _, writeAlive := session.IsAlive(); !writeAlive {308 Log.Warnf("[%s] session timeout. session=%s", group.UniqueKey, session.UniqueKey())309 session.Dispose()310 }311 }312 for session := range group.httpflvSubSessionSet {313 if _, writeAlive := session.IsAlive(); !writeAlive {314 Log.Warnf("[%s] session timeout. session=%s", group.UniqueKey, session.UniqueKey())315 session.Dispose()316 }317 }318 for session := range group.httptsSubSessionSet {319 if _, writeAlive := session.IsAlive(); !writeAlive {320 Log.Warnf("[%s] session timeout. session=%s", group.UniqueKey, session.UniqueKey())321 session.Dispose()322 }323 }324 for _, item := range group.url2PushProxy {325 session := item.pushSession326 if item.isPushing && session != nil {327 if _, writeAlive := session.IsAlive(); !writeAlive {328 Log.Warnf("[%s] session timeout. session=%s", group.UniqueKey, session.UniqueKey())329 session.Dispose()330 }331 }332 }333}334// updateAllSessionStat 更新所有session的状态335//336func (group *Group) updateAllSessionStat() {337 if group.rtmpPubSession != nil {338 group.rtmpPubSession.UpdateStat(calcSessionStatIntervalSec)339 }340 if group.rtspPubSession != nil {341 group.rtspPubSession.UpdateStat(calcSessionStatIntervalSec)...

Full Screen

Full Screen

refactor.go

Source:refactor.go Github

copy

Full Screen

1// Copyright (c) 2020 10X Genomics, Inc. All rights reserved.2// Package refactoring includes methods for modifying martian ASTs.3package refactoring4import (5 "fmt"6 "github.com/martian-lang/martian/martian/syntax"7)8func getCallable(id string, asts []*syntax.Ast) syntax.Callable {9 for _, ast := range asts {10 if ast != nil && ast.Callables != nil {11 if c := ast.Callables.Table[id]; c != nil {12 return c13 }14 }15 }16 return nil17}18type CallableParam struct {19 Callable string20 Param string21}22type Rename struct {23 Callable string24 NewName string25}26type RenameParam struct {27 CallableParam28 NewName string29}30// RefactorConfig contains options to be passed to Refactor.31type RefactorConfig struct {32 // If topCalls is non-empty, the RemoveUnusedOutputs will be applied repeatedly33 // until no further changes are made. If RemoveCalls is also specified, the34 // calls to RemoveAllUnusedCalls and RemoveUnusedOutputs are alternated.35 TopCalls StringSet36 // Remove the given input parameters.37 RemoveInParams []CallableParam38 // Remove the given output parameters.39 RemoveOutParams []CallableParam40 // If removeCalls is true, RemoveAllUnusedCalls is applied repeatedly until41 // no further changes are made.42 RemoveCalls bool43 // Rename the given callable objects.44 Rename []Rename45 // Rename the given input parameters.46 RenameInParam []RenameParam47 // Rename the given output parameters.48 RenameOutParam []RenameParam49}50// Refactor modifies a set of ASTs.51//52// The returned Edit will apply the same changes to another Ast.53func Refactor(asts []*syntax.Ast,54 opt RefactorConfig) (Edit, error) {55 edits := make(editSet, 0, 2+len(opt.TopCalls))56 for _, rename := range opt.Rename {57 callable := getCallable(rename.Callable, asts)58 if callable == nil {59 return edits, fmt.Errorf("callable %s not found", rename.Callable)60 }61 edit := RenameCallable(callable, rename.NewName, asts)62 if edit != nil {63 edits = append(edits, edit)64 for _, ast := range asts {65 // Run this on the compiled ASTs so removeCalls has66 // an up-to-date version of the pipelines.67 if _, err := edit.Apply(ast); err != nil {68 return edits, fmt.Errorf("applying edit: %w", err)69 }70 }71 }72 }73 for _, rename := range opt.RenameInParam {74 callable := getCallable(rename.Callable, asts)75 if callable == nil {76 return edits, fmt.Errorf("callable %s not found", rename.Callable)77 }78 edit := RenameInput(callable, rename.Param, rename.NewName, asts)79 if edit != nil {80 edits = append(edits, edit)81 for _, ast := range asts {82 // Run this on the compiled ASTs so removeCalls has83 // an up-to-date version of the pipelines.84 if _, err := edit.Apply(ast); err != nil {85 return edits, fmt.Errorf("applying edit: %w", err)86 }87 }88 }89 }90 for _, rename := range opt.RenameOutParam {91 callable := getCallable(rename.Callable, asts)92 if callable == nil {93 return edits, fmt.Errorf("callable %s not found", rename.Callable)94 }95 edit := RenameOutput(callable, rename.Param, rename.NewName, asts)96 if edit != nil {97 edits = append(edits, edit)98 for _, ast := range asts {99 // Run this on the compiled ASTs so removeCalls has100 // an up-to-date version of the pipelines.101 if _, err := edit.Apply(ast); err != nil {102 return edits, fmt.Errorf("applying edit: %w", err)103 }104 }105 }106 }107 for _, removeParam := range opt.RemoveInParams {108 cname := removeParam.Callable109 param := removeParam.Param110 callable := getCallable(cname, asts)111 if callable == nil {112 return edits, fmt.Errorf("callable %s not found", cname)113 }114 edit := RemoveInputParam(callable, param, asts)115 if edit != nil {116 edits = append(edits, edit)117 if opt.RemoveCalls || len(opt.TopCalls) > 0 {118 for _, ast := range asts {119 // Run this on the compiled ASTs so removeCalls has120 // an up-to-date version of the pipelines.121 if _, err := edit.Apply(ast); err != nil {122 return edits, fmt.Errorf("applying edit: %w", err)123 }124 }125 }126 }127 }128 for _, removeParam := range opt.RemoveOutParams {129 cname := removeParam.Callable130 param := removeParam.Param131 callable := getCallable(cname, asts)132 if callable == nil {133 return edits, fmt.Errorf("callable %s not found", cname)134 }135 edit, err := RemoveOutputParam(callable, param, asts)136 if err != nil {137 return edits, err138 }139 if edit != nil {140 edits = append(edits, edit)141 if opt.RemoveCalls || len(opt.TopCalls) > 0 {142 for _, ast := range asts {143 // Run this on the compiled ASTs so removeCalls has144 // an up-to-date version of the pipelines.145 if _, err := edit.Apply(ast); err != nil {146 return edits, fmt.Errorf("applying edit: %w", err)147 }148 }149 }150 }151 }152 if opt.RemoveCalls || len(opt.TopCalls) > 0 {153 changes := true154 for changes {155 changes = false156 if opt.RemoveCalls {157 edit := RemoveAllUnusedCalls(asts)158 if edit != nil {159 count := 0160 for _, ast := range asts {161 if c, err := edit.Apply(ast); err != nil {162 return edits, fmt.Errorf("applying edit: %w", err)163 } else {164 count += c165 }166 }167 if count > 0 {168 // Go around for another pass, in case some of the169 // removed calls were the only dependencies keeping170 // another call alive171 changes = true172 edits = append(edits, edit)173 }174 }175 }176 if len(opt.TopCalls) > 0 {177 edit := RemoveUnusedOutputs(opt.TopCalls, asts)178 if edit != nil {179 count := 0180 for _, ast := range asts {181 if c, err := edit.Apply(ast); err != nil {182 return edits, fmt.Errorf("applying edit: %w", err)183 } else {184 count += c185 }186 }187 if count > 0 {188 // Go around for another pass, in case some of the189 // removed outputs were the only dependencies keeping190 // another call alive191 changes = true192 edits = append(edits, edit)193 }194 }195 }196 }197 }198 if len(edits) == 0 {199 return nil, nil200 }201 return edits, nil202}...

Full Screen

Full Screen

life.go

Source:life.go Github

copy

Full Screen

1package main2import (3 "fmt"4 "math/rand"5 "time"6)7// cell struct with location and state (dead or alive)8type Cell struct {9 x int10 y int11 state int12}13// TODO: Refactor this out to match Go paradigms? 14// grid size and number of generations to simulate15const GRID_X, GRID_Y int = 10, 1016const GEN int = 1017// generate starting grid (using random seed)18func populateSeed() (grid [GRID_X][GRID_Y]int, err error) {19 // generate random seed20 rand.Seed(time.Now().UTC().UnixNano())21 // check grid size is valid22 if GRID_X < 0 {23 return grid, fmt.Errorf("grid dimensions must be a positive number")24 }25 // populate grid with random states26 for i := 0; i < GRID_X; i++ {27 for j := 0; j < GRID_Y; j++ {28 grid[i][j] = rand.Intn(2)29 }30 }31 return grid, err32}33// evaluate if a specified cell lives or dies34func lifeEvaluation(grid [GRID_X][GRID_Y]int, cell Cell) Cell {35 var alive int36 37 // count living neighbours38 for i := -1; i < 2; i++ {39 for j := -1; j < 2; j++ {40 if grid[cell.x-i][cell.y-j] == 1 {41 alive++42 }43 }44 }45 // any live cell with two or three live neighbours survives.46 if cell.state == 1 && (alive-cell.state == 2 || alive-cell.state == 3) {47 cell.state = 148 // any dead cell with three live neighbours becomes a live cell.49 } else if cell.state == 0 && alive-cell.state == 3 {50 cell.state = 151 // all other live cells die in the next generation. Similarly, all other dead cells stay dead.52 } else if cell.state == 1 {53 cell.state = 054 }55 return cell56}57// populates a new grid with next generation states (ignores edges)58func nextGeneration(current_grid [GRID_X][GRID_Y]int) [GRID_X][GRID_Y]int {59 // new grid declared with each call (inefficient)60 var next_grid [GRID_X][GRID_Y]int61 var current Cell62 // populate new grid63 for i := 1; i < GRID_X-1; i++ {64 for j := 1; j < GRID_Y-1; j++ {65 current.state = current_grid[i][j]66 current.x = i67 current.y = j68 next_grid[i][j] = lifeEvaluation(current_grid, current).state69 }70 }71 return next_grid72 // TODO: declare two grids and swap between them for memory efficinecy73 // TODO: better method for dealing with grid edges74}75// prints grid along with generation count, x == alive, - == dead76func printGrid(grid [GRID_X][GRID_Y]int, gen int) {77 // print generation78 fmt.Println("generation", gen)79 80 // print grid81 for i := 0; i < GRID_X; i++ {82 for j := 0; j < GRID_Y; j++ {83 if grid[i][j] == 1 {84 // alive85 fmt.Print(" x ")86 } else {87 // dead88 fmt.Print(" - ")89 }90 }91 fmt.Println("")92 }93}94// run the simulation and print the results for specified gen count95func simulate(grid [GRID_X][GRID_Y]int, cell Cell) {96 var err error97 // generate random array98 grid, err = populateSeed()99 if err != nil {100 fmt.Println(err)101 return 102 }103 // print generation 0 grid104 printGrid(grid, 0)105 // simulate for gen generations106 for i := 1; i <= GEN; i++ {107 grid = nextGeneration(grid)108 printGrid(grid, i)109 }110}111func main() {112 // declare grid and cell113 var grid [GRID_X][GRID_Y]int114 var cell Cell115 // simulate game of life116 simulate(grid, cell)117}...

Full Screen

Full Screen

Alive

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println(refactor.Alive())4}5import "fmt"6func main() {7 fmt.Println(refactor.Alive())8}9import "fmt"10func main() {11 fmt.Println(refactor.Alive())12}13import "fmt"14func main() {15 fmt.Println(refactor.Alive())16}17import "fmt"18func main() {19 fmt.Println(refactor.Alive())20}21import "fmt"22func main() {23 fmt.Println(refactor.Alive())24}25import "fmt"26func main() {27 fmt.Println(refactor.Alive())28}29import "fmt"30func main() {31 fmt.Println(refactor.Alive())32}33import "fmt"34func main() {35 fmt.Println(refactor.Alive())36}37import "fmt"38func main() {39 fmt.Println(refactor.Alive())40}41import "fmt"42func main() {43 fmt.Println(refactor.Alive())44}45import "fmt"46func main() {47 fmt.Println(refactor.Alive())48}49import "fmt"50func main() {51 fmt.Println(refactor.Alive())52}53import "fmt"54func main() {55 fmt.Println(refactor.Al

Full Screen

Full Screen

Alive

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello, world.")4}5import (6func main() {7 fmt.Println("Hello, world.")8}9import (10func main() {11 fmt.Println("Hello, world.")12}13import (14func main() {15 fmt.Println("Hello, world.")16}17import (18func main() {19 fmt.Println("Hello, world.")20}21import (22func main() {23 fmt.Println("Hello, world.")24}25import (26func main() {27 fmt.Println("Hello, world.")28}29import (30func main() {31 fmt.Println("Hello, world.")32}33import (34func main() {35 fmt.Println("Hello, world.")36}37import (38func main() {39 fmt.Println("Hello, world.")40}41import (

Full Screen

Full Screen

Alive

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 a.Alive()4}5import (6func main() {7 a.Alive()8}9import (10func main() {11 a.Alive()12}13import (14func main() {15 a.Alive()16}17import (18func main() {19 a.Alive()20}21import (22func main() {23 a.Alive()24}25import (26func main() {27 a.Alive()28}29import (30func main() {31 a.Alive()32}33import (34func main() {35 a.Alive()36}37import (38func main() {39 a.Alive()40}41import (42func main() {43 a.Alive()44}45import (46func main() {

Full Screen

Full Screen

Alive

Using AI Code Generation

copy

Full Screen

1func main() {2 var p = refactor.Person{3 }4 fmt.Println(p.Alive())5}6func main() {7 var p = refactor.Person{8 }9 fmt.Println(p.Alive())10}11func main() {12 var p = refactor.Person{13 }14 fmt.Println(p.Alive())15}16func main() {17 var p = refactor.Person{18 }19 fmt.Println(p.Alive())20}21func main() {22 var p = refactor.Person{23 }24 fmt.Println(p.Alive())25}26func main() {27 var p = refactor.Person{28 }29 fmt.Println(p.Alive())30}31func main() {32 var p = refactor.Person{33 }34 fmt.Println(p.Alive())35}36func main() {37 var p = refactor.Person{38 }39 fmt.Println(p.Alive())40}41func main() {42 var p = refactor.Person{43 }44 fmt.Println(p.Alive())45}46func main() {47 var p = refactor.Person{48 }

Full Screen

Full Screen

Alive

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Alive:", refactor.Alive)4}5import (6func main() {7 fmt.Println("Alive:", refactor.Alive)8 fmt.Println("Alive:", refactor.IsAlive())9}10import (11func main() {12 fmt.Println("Alive:", refactor.Person.Alive)13 fmt.Println("Alive:", refactor.Person.IsAlive())14}

Full Screen

Full Screen

Alive

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World")4 var r = refactor.NewRefactor()5 fmt.Println(r.Alive())6}7import (8func main() {9 fmt.Println("Hello World")10 var r = refactor.NewRefactor()11 fmt.Println(r.Alive())12}13import (14func main() {15 fmt.Println("Hello World")16 var r = refactor.NewRefactor()17 fmt.Println(r.Alive())18}19import (20func main() {21 fmt.Println("Hello World")22 var r = refactor.NewRefactor()23 fmt.Println(r.Alive())24}25import (26func main() {27 fmt.Println("Hello World")28 var r = refactor.NewRefactor()29 fmt.Println(r.Alive())30}31import (32func main() {33 fmt.Println("Hello World")34 var r = refactor.NewRefactor()35 fmt.Println(r.Alive())36}37import (

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Gauge automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful