本文整理汇总了Golang中github.com/cmu440/tribbler/libstore.NewLibstore函数的典型用法代码示例。如果您正苦于以下问题:Golang NewLibstore函数的具体用法?Golang NewLibstore怎么用?Golang NewLibstore使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewLibstore函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: NewTribServer
// NewTribServer creates, starts and returns a new TribServer. masterServerHostPort
// is the master storage server's host:port and port is this port number on which
// the TribServer should listen. A non-nil error should be returned if the TribServer
// could not be started.
//
// For hints on how to properly setup RPC, see the rpc/tribrpc package.
func NewTribServer(masterServerHostPort, myHostPort string) (TribServer, error) {
tribServer := new(tribServer)
// Create the server socket that will listen for incoming RPCs.
listener, err := net.Listen("tcp", myHostPort)
if err != nil {
return nil, err
}
// Wrap the tribServer before registering it for RPC.
err = rpc.RegisterName("TribServer", tribrpc.Wrap(tribServer))
if err != nil {
return nil, err
}
// Setup the HTTP handler that will server incoming RPCs and
// serve requests in a background goroutine.
rpc.HandleHTTP()
go http.Serve(listener, nil)
storage, err := libstore.NewLibstore(masterServerHostPort, myHostPort, libstore.Never)
if err != nil {
return nil, err
}
tribServer.storage = storage
return tribServer, nil
}
开发者ID:jbuckman,项目名称:p2-440,代码行数:35,代码来源:tribserver_impl.go
示例2: NewTribServer
// NewTribServer creates, starts and returns a new TribServer. masterServerHostPort
// is the master storage server's host:port and port is this port number on which
// the TribServer should listen. A non-nil error should be returned if the TribServer
// could not be started.
//
// For hints on how to properly setup RPC, see the rpc/tribrpc package.
func NewTribServer(masterServerHostPort, myHostPort string) (TribServer, error) {
newStore, err := libstore.NewLibstore(masterServerHostPort, myHostPort, libstore.Never)
if err != nil {
return nil, err
}
ts := &tribServer{
myHostPort: myHostPort,
Libstore: newStore,
}
err = rpc.RegisterName("TribServer", tribrpc.Wrap(ts))
if err != nil {
return nil, err
}
rpc.HandleHTTP()
l, err := net.Listen("tcp", myHostPort)
if err != nil {
return nil, err
}
go http.Serve(l, nil)
return ts, nil
}
开发者ID:oldady,项目名称:ds_p2,代码行数:31,代码来源:tribserver_impl.go
示例3: NewTribServer
// NewTribServer creates, starts and returns a new TribServer. masterServerHostPort
// is the master storage server's host:port and port is this port number on which
// the TribServer should listen. A non-nil error should be returned if the TribServer
// could not be started.
//
// For hints on how to properly setup RPC, see the rpc/tribrpc package.
func NewTribServer(masterServerHostPort, myHostPort string) (TribServer, error) {
libStore, err := libstore.NewLibstore(masterServerHostPort, myHostPort, libstore.Never)
//fmt.Println("Creating new tribServer...")
if err != nil {
return nil, err
}
var tribServ tribServer = tribServer{
libStore: libStore,
}
l, err2 := net.Listen("tcp", myHostPort)
if err2 != nil {
fmt.Println(err2)
return nil, err2
}
//go http.Serve(l, nil)
err1 := rpc.RegisterName("TribServer", tribrpc.Wrap(&tribServ))
if err1 != nil {
fmt.Println(err1)
return nil, err1
}
rpc.HandleHTTP()
go http.Serve(l, nil)
return &tribServ, nil
}
开发者ID:aditij1,项目名称:p2aditijakkamat,代码行数:32,代码来源:tribserver_impl.go
示例4: NewTribServer
// NewTribServer creates, starts and returns a new TribServer. masterServerHostPort
// is the master storage server's host:port and port is this port number on which
// the TribServer should listen. A non-nil error should be returned if the TribServer
// could not be started.
//
// For hints on how to properly setup RPC, see the rpc/tribrpc package.
func NewTribServer(masterServerHostPort, myHostPort string) (TribServer, error) {
tribServer := &tribServer{}
var newError error
tribServer.libstore, newError = libstore.NewLibstore(masterServerHostPort, myHostPort, libstore.Normal)
if newError != nil {
fmt.Println(newError)
}
err := rpc.RegisterName("TribServer", tribrpc.Wrap(tribServer))
if err != nil {
return nil, err
}
rpc.HandleHTTP()
listener, err := net.Listen("tcp", ":"+strings.Split(myHostPort, ":")[1])
if err != nil {
return nil, err
}
go http.Serve(listener, nil)
fmt.Println("TribServer Created!", myHostPort)
return tribServer, nil
}
开发者ID:wentianqi7,项目名称:15640-distributed-systems,代码行数:31,代码来源:tribserver_impl.go
示例5: NewTribServer
// NewTribServer creates, starts and returns a new TribServer. masterServerHostPort
// is the master storage server's host:port and port is this port number on which
// the TribServer should listen. A non-nil error should be returned if the TribServer
// could not be started.
//
// For hints on how to properly setup RPC, see the rpc/tribrpc package.
func NewTribServer(masterServerHostPort, myHostPort string) (TribServer, error) {
fmt.Println("tribserver being connection!")
server := new(tribServer)
lib, err := libstore.NewLibstore(masterServerHostPort, myHostPort, libstore.Normal)
if err != nil {
fmt.Println("failed to connect!")
//fmt.Println(err)
return nil, err
}
server.lib = lib
server.id = 0
server.hostport = myHostPort
// listen for incoming RPC
listener, err := net.Listen("tcp", myHostPort)
if err != nil {
fmt.Println("Listen error!")
return nil, err
}
// warp the tribserver
err = rpc.RegisterName("TribServer", tribrpc.Wrap(server))
if err != nil {
fmt.Println("RegisterName error!")
return nil, err
}
rpc.HandleHTTP()
go http.Serve(listener, nil)
fmt.Println("server started!!!!!!!")
return server, nil
}
开发者ID:oldady,项目名称:Tribbler,代码行数:40,代码来源:tribserver_impl.go
示例6: NewTribServer
// NewTribServer creates, starts and returns a new TribServer. masterServerHostPort
// is the master storage server's host:port and port is this port number on which
// the TribServer should listen. A non-nil error should be returned if the TribServer
// could not be started.
//
// For hints on how to properly setup RPC, see the rpc/tribrpc package.
func NewTribServer(masterServerHostPort, myHostPort string) (TribServer, error) {
LOGE.Printf("NewTribServer:: masterServerHostPort=%s myHostPort=%s\n", masterServerHostPort, myHostPort)
server := new(tribServer)
server.hostPort = myHostPort
server.index = 0
lib, err := libstore.NewLibstore(masterServerHostPort, myHostPort, libstore.Normal)
if err != nil {
return nil, err
}
server.lib = lib
listener, err := net.Listen("tcp", myHostPort)
if err != nil {
return nil, err
}
err = rpc.RegisterName("TribServer", tribrpc.Wrap(server))
if err != nil {
fmt.Println("RegisterName error!")
return nil, err
}
rpc.HandleHTTP()
go http.Serve(listener, nil)
return server, nil
}
开发者ID:201101050424,项目名称:Tribbler,代码行数:33,代码来源:tribserver_impl.go
示例7: NewTribServer
// NewTribServer creates, starts and returns a new TribServer. masterServerHostPort
// is the master storage server's host:port and port is this port number on which
// the TribServer should listen. A non-nil error should be returned if the TribServer
// could not be started.
//
// For hints on how to properly setup RPC, see the rpc/tribrpc package.
func NewTribServer(masterServerHostPort, myHostPort string) (TribServer, error) {
ts := new(tribServer)
// Create the libstore for this server
ls, err := libstore.NewLibstore(masterServerHostPort, myHostPort, libstore.Never)
if err != nil {
fmt.Println("Failed to create libstore")
return nil, errors.New("Couldn't start libstore for Tribserver")
}
ts.ls = ls
// Start listening for connections from TribClients
rpc.RegisterName("TribServer", tribrpc.Wrap(ts))
rpc.HandleHTTP()
l, e := net.Listen("tcp", myHostPort)
if e != nil {
fmt.Println("Failed to listen with Tribserver")
return nil, errors.New("Tribserver couldn't start listening")
}
go http.Serve(l, nil)
return ts, nil
// Get rid of this. I didn't want to keep commenting out fmt for testing when I didn't use it
fmt.Println("this is here so I don't throw an error for not using fmt")
return nil, nil
}
开发者ID:pyurky,项目名称:p2,代码行数:33,代码来源:tribserver_impl.go
示例8: NewTribServer
// NewTribServer creates, starts and returns a new TribServer. masterServerHostPort
// is the master storage server's host:port and port is this port number on which
// the TribServer should listen. A non-nil error should be returned if the TribServer
// could not be started.
//
// For hints on how to properly setup RPC, see the rpc/tribrpc package.
func NewTribServer(masterServerHostPort, myHostPort string) (TribServer, error) {
tribServer := new(tribServer)
ls, err := libstore.NewLibstore(masterServerHostPort, myHostPort, libstore.Normal)
if err != nil {
return nil, errors.New("Libstore failed.")
}
tribServer.lib_store = ls
// Create the server socket that will listen for incoming RPCs.
_, port, _ := net.SplitHostPort(myHostPort)
listener, err := net.Listen("tcp", fmt.Sprintf(":%s", port))
if err != nil {
return nil, err
}
// Wrap the tribServer before registering it for RPC.
err = rpc.RegisterName("TribServer", tribrpc.Wrap(tribServer))
if err != nil {
return nil, err
}
// Setup the HTTP handler that will server incoming RPCs and
// serve requests in a background goroutine.
rpc.HandleHTTP()
go http.Serve(listener, nil)
return tribServer, nil
// return nil, errors.New("not implemented")
}
开发者ID:mallocanswer,项目名称:Tribbler,代码行数:36,代码来源:tribserver_impl.go
示例9: testNonexistentServer
// Test libstore returns nil when it cannot connect to the server
func testNonexistentServer() {
if l, err := libstore.NewLibstore(fmt.Sprintf("localhost:%d", *portnum), fmt.Sprintf("localhost:%d", *portnum), libstore.Normal); l == nil || err != nil {
fmt.Println("PASS")
passCount++
} else {
LOGE.Println("FAIL: libstore does not return a non-nil error when it cannot connect to nonexistent storage server")
failCount++
}
cleanupLibstore(nil)
}
开发者ID:codingfrenzy,项目名称:p2,代码行数:11,代码来源:libtest.go
示例10: initLibstore
// Initialize proxy and libstore
func initLibstore(storage, server, myhostport string, alwaysLease bool) (net.Listener, error) {
l, err := net.Listen("tcp", server)
if err != nil {
LOGE.Println("Failed to listen:", err)
return nil, err
}
// The ProxyServer acts like a "StorageServer" in the system, but also has some
// additional functionalities that allow us to enforce the number of RPCs made
// to the storage server, etc.
proxyCounter, err := proxycounter.NewProxyCounter(storage, server)
if err != nil {
LOGE.Println("Failed to setup test:", err)
return nil, err
}
pc = proxyCounter
// Normally the StorageServer would register itself to receive RPCs,
// but we don't call NewStorageServer here, do we need to do it here instead.
rpc.RegisterName("StorageServer", storagerpc.Wrap(pc))
// Normally the TribServer would call the two methods below when it is first
// created, but these tests mock out the TribServer all together, so we do
// it here instead.
rpc.HandleHTTP()
go http.Serve(l, nil)
var leaseMode libstore.LeaseMode
if alwaysLease {
leaseMode = libstore.Always
} else if myhostport == "" {
leaseMode = libstore.Never
} else {
leaseMode = libstore.Normal
}
// Create and start the Libstore.
libstore, err := libstore.NewLibstore(server, myhostport, leaseMode)
if err != nil {
LOGE.Println("Failed to create Libstore:", err)
return nil, err
}
ls = libstore
return l, nil
}
开发者ID:codingfrenzy,项目名称:p2,代码行数:46,代码来源:libtest.go
示例11: NewTribServer
// NewTribServer creates, starts and returns a new TribServer. masterServerHostPort
// is the master storage server's host:port and port is this port number on which
// the TribServer should listen. A non-nil error should be returned if the TribServer
// could not be started.
//
// For hints on how to properly setup RPC, see the rpc/tribrpc package.
func NewTribServer(masterServerHostPort, myHostPort string) (TribServer, error) {
ls, err := libstore.NewLibstore(masterServerHostPort, myHostPort, libstore.Normal)
if err != nil {
return nil, err
}
ts := new(tribServer)
ts.ls = ls
listener, err := net.Listen("tcp", myHostPort)
if err != nil {
return nil, err
}
// Wrap the tribServer before registering it for RPC.
err = rpc.RegisterName("TribServer", tribrpc.Wrap(ts))
if err != nil {
return nil, err
}
// Setup the HTTP handler that will server incoming RPCs and
// serve requests in a background goroutine.
rpc.HandleHTTP()
go http.Serve(listener, nil)
return ts, nil
}
开发者ID:thuhujin,项目名称:Tribbler,代码行数:29,代码来源:tribserver_impl.go
示例12: NewTribServer
// NewTribServer creates, starts and returns a new TribServer. masterServerHostPort
// is the master storage server's host:port and port is this port number on which
// the TribServer should listen. A non-nil error should be returned if the TribServer
// could not be started.
//
// For hints on how to properly setup RPC, see the rpc/tribrpc package.
func NewTribServer(masterServerHostPort, myHostPort string) (TribServer, error) {
libstore, err := libstore.NewLibstore(masterServerHostPort, myHostPort, libstore.Never)
if err != nil {
return nil, errors.New("Creating new libstore failed")
}
newTribServer := &tribServer{
ls: libstore,
}
listener, err := net.Listen("tcp", myHostPort)
if err != nil {
return nil, err
}
err = rpc.RegisterName("TribServer", tribrpc.Wrap(newTribServer))
if err != nil {
return nil, err
}
rpc.HandleHTTP()
go http.Serve(listener, nil)
return newTribServer, nil
}
开发者ID:iedwardwangi,项目名称:Tribbler,代码行数:29,代码来源:tribserver_impl.go
示例13: main
func main() {
flag.Parse()
if flag.NArg() < 2 {
flag.Usage()
os.Exit(1)
}
cmdmap := make(map[string]cmdInfo)
for k, v := range cmdList {
cmdmap[k] = cmdInfo{cmdline: k, nargs: v}
}
cmd := flag.Arg(0)
ci, found := cmdmap[cmd]
if !found {
flag.Usage()
os.Exit(1)
}
if flag.NArg() < (ci.nargs + 1) {
flag.Usage()
os.Exit(1)
}
var leaseCallbackAddr string
if *handleLeases {
// Setup an HTTP handler to receive remote lease revocation requests.
// The student's libstore implementation is resonsible for calling
// rpc.RegisterName("LeaseCallbacks", librpc.Wrap(libstore)) to finish
// the setup.
l, err := net.Listen("tcp", ":0")
if err != nil {
log.Fatalln("Failed to listen:", err)
}
_, listenPort, _ := net.SplitHostPort(l.Addr().String())
leaseCallbackAddr = net.JoinHostPort("localhost", listenPort)
rpc.HandleHTTP()
go http.Serve(l, nil)
}
var leaseMode libstore.LeaseMode
if *handleLeases && *forceLease {
leaseMode = libstore.Always
} else if leaseCallbackAddr == "" {
leaseMode = libstore.Never
} else {
leaseMode = libstore.Normal
}
masterHostPort := net.JoinHostPort(*serverAddress, strconv.Itoa(*port))
ls, err := libstore.NewLibstore(masterHostPort, leaseCallbackAddr, leaseMode)
if err != nil {
log.Fatalln("Failed to create libstore:", err)
}
for i := 0; i < *numTimes; i++ {
switch cmd {
case "g":
val, err := ls.Get(flag.Arg(1))
if err != nil {
fmt.Println("ERROR:", err)
} else {
fmt.Println(val)
}
case "lg":
val, err := ls.GetList(flag.Arg(1))
if err != nil {
fmt.Println("ERROR:", err)
} else {
for _, i := range val {
fmt.Println(i)
}
}
case "p", "la", "lr":
var err error
switch cmd {
case "p":
err = ls.Put(flag.Arg(1), flag.Arg(2))
case "la":
err = ls.AppendToList(flag.Arg(1), flag.Arg(2))
case "lr":
err = ls.RemoveFromList(flag.Arg(1), flag.Arg(2))
}
if err == nil {
fmt.Println("OK")
} else {
fmt.Println("ERROR:", err)
}
}
}
if *handleLeases {
fmt.Println("Waiting 20 seconds for lease callbacks...")
time.Sleep(20 * time.Second)
}
}
开发者ID:codingfrenzy,项目名称:p2,代码行数:95,代码来源:lrunner.go
注:本文中的github.com/cmu440/tribbler/libstore.NewLibstore函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论