func StartBBPD(requestedPorts []int) error {
	// try to get a port to listen to
	for _, p := range requestedPorts {
		e := fmt.Sprintf("trying to bind to port:%d", p)
		log.Printf(e)
		if canAssignPort(p) {
			port = &p
			break
		} else {
			e := fmt.Sprintf("port %d already in use", p)
			log.Printf(e)
		}
	}
	if port == nil {
		// if all ports are in use, we may assume that other bbpd invocations are
		// running correctly. in which case, return nil here and the caller will
		// exit with code 0, which is important to prevent rc managers etc from
		// automatically respawning the program
		log.Printf("bbpd_route.StartBBPD:no listen port")
		return nil
	}
	e := fmt.Sprintf("init routing on port %d", *port)
	log.Printf(e)
	http.HandleFunc(STATUSPATH, statusHandler)
	http.HandleFunc(DESCRIBETABLEPATH, describe_table_route.RawPostHandler)
	http.HandleFunc(DESCRIBETABLEGETPATH, describe_table_route.DescribeTableHandler)
	http.HandleFunc(LISTTABLESPATH, list_tables_route.ListTablesHandler)
	http.HandleFunc(CREATETABLEPATH, create_table_route.RawPostHandler)
	http.HandleFunc(UPDATETABLEPATH, update_table_route.RawPostHandler)
	http.HandleFunc(STATUSTABLEPATH, describe_table_route.StatusTableHandler)
	http.HandleFunc(PUTITEMPATH, put_item_route.RawPostHandler)
	http.HandleFunc(PUTITEMJSONPATH, put_item_route.PutItemJSONHandler)
	http.HandleFunc(GETITEMPATH, get_item_route.RawPostHandler)
	http.HandleFunc(GETITEMJSONPATH, get_item_route.GetItemJSONHandler)
	http.HandleFunc(BATCHGETITEMPATH, batch_get_item_route.BatchGetItemHandler)
	http.HandleFunc(BATCHGETITEMJSONPATH, batch_get_item_route.BatchGetItemJSONHandler)
	http.HandleFunc(BATCHWRITEITEMPATH, batch_write_item_route.BatchWriteItemHandler)
	http.HandleFunc(BATCHWRITEITEMJSONPATH, batch_write_item_route.BatchWriteItemJSONHandler)
	http.HandleFunc(DELETEITEMPATH, delete_item_route.RawPostHandler)
	http.HandleFunc(UPDATEITEMPATH, update_item_route.RawPostHandler)
	http.HandleFunc(QUERYPATH, query_route.RawPostHandler)
	http.HandleFunc(SCANPATH, scan_route.RawPostHandler)
	http.HandleFunc(RAWPOSTPATH, raw_post_route.RawPostHandler)
	http.HandleFunc(COMPATPATH, CompatHandler)

	// undelete these to enable table deletions, a little dangerous!
	// http.HandleFunc(DELETETABLEPATH,     delete_table_route.RawPostHandler)
	// http.HandleFunc(DELETETABLEGETPATH,  delete_table_route.DeleteTableHandler)

	const SERV_TIMEOUT = 20
	srv = &http.Server{
		Addr: ":" + strconv.Itoa(*port),
		// The timeouts seems too-long, but they accomodates the exponential decay retry loop.
		// Programs using this can either change these directly or use goroutine timeouts
		// to impose a local minimum.
		ReadTimeout:  SERV_TIMEOUT * time.Second,
		WriteTimeout: SERV_TIMEOUT * time.Second,
		ConnState: func(conn net.Conn, new_state http.ConnState) {
			bbpd_runinfo.RecordConnState(new_state)
			return
		},
	}
	bbpd_runinfo.SetBBPDAccept()
	return srv.ListenAndServe()
}
// StartBBPD is where the proxy http server is started.
// The requestedPort is a *int so it can be nil'able. passing 0 as an implied
// null value could result in a dial that takes any available port, as is
// implied by the go docs.
StartBBPD is where the proxy http server is started.
The requestedPort is a *int so it can be nil'able. passing 0 as an implied
null value could result in a dial that takes any available port, as is
implied by the go docs.
// StartBBPD is where the proxy http server is started . // The requestedPort is a * int so it can be nil ' able . passing 0 as an implied // null value could result in a dial that takes any available port as is // implied by the go docs .
func StartBBPD(requestedPorts []int) error {
	for _, p := range requestedPorts {
		e := fmt.Sprintf("trying to bind to port:%d", p)
		log.Printf(e)
		if canAssignPort(p) {
			port = &p
			break
		} else {
			e := fmt.Sprintf("port %d already in use", p)
			log.Printf(e)
		}
	}
	if port == nil {
		log.Printf("bbpd_route.StartBBPD:no listen port")
		return nil
	}
	e := fmt.Sprintf("init routing on port %d", *port)
	log.Printf(e)
	http.HandleFunc(STATUSPATH, statusHandler)
	http.HandleFunc(DESCRIBETABLEPATH, describe_table_route.RawPostHandler)
	http.HandleFunc(DESCRIBETABLEGETPATH, describe_table_route.DescribeTableHandler)
	http.HandleFunc(LISTTABLESPATH, list_tables_route.ListTablesHandler)
	http.HandleFunc(CREATETABLEPATH, create_table_route.RawPostHandler)
	http.HandleFunc(UPDATETABLEPATH, update_table_route.RawPostHandler)
	http.HandleFunc(STATUSTABLEPATH, describe_table_route.StatusTableHandler)
	http.HandleFunc(PUTITEMPATH, put_item_route.RawPostHandler)
	http.HandleFunc(PUTITEMJSONPATH, put_item_route.PutItemJSONHandler)
	http.HandleFunc(GETITEMPATH, get_item_route.RawPostHandler)
	http.HandleFunc(GETITEMJSONPATH, get_item_route.GetItemJSONHandler)
	http.HandleFunc(BATCHGETITEMPATH, batch_get_item_route.BatchGetItemHandler)
	http.HandleFunc(BATCHGETITEMJSONPATH, batch_get_item_route.BatchGetItemJSONHandler)
	http.HandleFunc(BATCHWRITEITEMPATH, batch_write_item_route.BatchWriteItemHandler)
	http.HandleFunc(BATCHWRITEITEMJSONPATH, batch_write_item_route.BatchWriteItemJSONHandler)
	http.HandleFunc(DELETEITEMPATH, delete_item_route.RawPostHandler)
	http.HandleFunc(UPDATEITEMPATH, update_item_route.RawPostHandler)
	http.HandleFunc(QUERYPATH, query_route.RawPostHandler)
	http.HandleFunc(SCANPATH, scan_route.RawPostHandler)
	http.HandleFunc(RAWPOSTPATH, raw_post_route.RawPostHandler)
	http.HandleFunc(COMPATPATH, CompatHandler)
	const SERV_TIMEOUT = 20
	srv = &http.Server{
		Addr: ":" + strconv.Itoa(*port),
		ReadTimeout:  SERV_TIMEOUT * time.Second,
		WriteTimeout: SERV_TIMEOUT * time.Second,
		ConnState: func(conn net.Conn, new_state http.ConnState) {
			bbpd_runinfo.RecordConnState(new_state)
			return
		},
	}
	bbpd_runinfo.SetBBPDAccept()
	return srv.ListenAndServe()
}
func StartBBPD ( requestedPorts [ ] int ) error { for _ , p := range requestedPorts { e := fmt . Sprintf ( " " , p ) log . Printf ( e ) if canAssignPort ( p ) { port = & p break } else { e := fmt . Sprintf ( " " , p ) log . Printf ( e ) } } if port == nil { log . Printf ( " " ) return nil } e := fmt . Sprintf ( " " , * port ) log . Printf ( e ) http . HandleFunc ( STATUSPATH , statusHandler ) http . HandleFunc ( DESCRIBETABLEPATH , describe_table_route . RawPostHandler ) http . HandleFunc ( DESCRIBETABLEGETPATH , describe_table_route . DescribeTableHandler ) http . HandleFunc ( LISTTABLESPATH , list_tables_route . ListTablesHandler ) http . HandleFunc ( CREATETABLEPATH , create_table_route . RawPostHandler ) http . HandleFunc ( UPDATETABLEPATH , update_table_route . RawPostHandler ) http . HandleFunc ( STATUSTABLEPATH , describe_table_route . StatusTableHandler ) http . HandleFunc ( PUTITEMPATH , put_item_route . RawPostHandler ) http . HandleFunc ( PUTITEMJSONPATH , put_item_route . PutItemJSONHandler ) http . HandleFunc ( GETITEMPATH , get_item_route . RawPostHandler ) http . HandleFunc ( GETITEMJSONPATH , get_item_route . GetItemJSONHandler ) http . HandleFunc ( BATCHGETITEMPATH , batch_get_item_route . BatchGetItemHandler ) http . HandleFunc ( BATCHGETITEMJSONPATH , batch_get_item_route . BatchGetItemJSONHandler ) http . HandleFunc ( BATCHWRITEITEMPATH , batch_write_item_route . BatchWriteItemHandler ) http . HandleFunc ( BATCHWRITEITEMJSONPATH , batch_write_item_route . BatchWriteItemJSONHandler ) http . HandleFunc ( DELETEITEMPATH , delete_item_route . RawPostHandler ) http . HandleFunc ( UPDATEITEMPATH , update_item_route . RawPostHandler ) http . HandleFunc ( QUERYPATH , query_route . RawPostHandler ) http . HandleFunc ( SCANPATH , scan_route . RawPostHandler ) http . HandleFunc ( RAWPOSTPATH , raw_post_route . RawPostHandler ) http . HandleFunc ( COMPATPATH , CompatHandler ) const SERV_TIMEOUT = 20 srv = & http . Server { Addr : " " + strconv . Itoa ( * port ) , ReadTimeout : SERV_TIMEOUT * time . Second , WriteTimeout : SERV_TIMEOUT * time . Second , ConnState : func ( conn net . Conn , new_state http . ConnState ) { bbpd_runinfo . RecordConnState ( new_state ) return } , } bbpd_runinfo . SetBBPDAccept ( ) return srv . ListenAndServe ( ) }
StartBBPD is where the proxy http server is started.
StartBBPD is where the proxy http server is started .
// try to get a port to listen to // if all ports are in use, we may assume that other bbpd invocations are // running correctly. in which case, return nil here and the caller will // exit with code 0, which is important to prevent rc managers etc from // automatically respawning the program // undelete these to enable table deletions, a little dangerous! // http.HandleFunc(DELETETABLEPATH,     delete_table_route.RawPostHandler) // http.HandleFunc(DELETETABLEGETPATH,  delete_table_route.DeleteTableHandler) // The timeouts seems too-long, but they accomodates the exponential decay retry loop. // Programs using this can either change these directly or use goroutine timeouts // to impose a local minimum.