physical-lock: Change many uses of v23.NewServer to use xrpc.New*Server instead.

This is designed to reduce boilerplate and prove out the xrpc interface.
All but about 10 uses were replaced.

Some of the remaining calls are more complicated because the services/dispatchers
currently take the serving address as a construction parameter.

MultiPart: 7/9

Change-Id: I4989bfd7f17caff8c2b43e7a42875b3e21a11e67
diff --git a/go/src/v.io/x/lock/lock/main.go b/go/src/v.io/x/lock/lock/main.go
index 095dca6..4ffe673 100644
--- a/go/src/v.io/x/lock/lock/main.go
+++ b/go/src/v.io/x/lock/lock/main.go
@@ -24,6 +24,7 @@
 	"v.io/x/lock"
 	"v.io/x/lock/locklib"
 	"v.io/x/ref/lib/v23cmd"
+	"v.io/x/ref/lib/xrpc"
 	_ "v.io/x/ref/runtime/factories/static"
 )
 
@@ -353,23 +354,15 @@
 	}
 	defer stop()
 
-	server, err := v23.NewServer(ctx)
-	if err != nil {
-		return fmt.Errorf("failed to create server to receive keys: %v", err)
-	}
-	defer server.Stop()
-	if _, err := server.Listen(v23.GetListenSpec(ctx)); err != nil {
-		return fmt.Errorf("failed to setup listening: %v", err)
-	}
-
 	service := &recvKeyService{
 		env:    env,
 		notify: make(chan error),
 	}
-	if err := server.Serve(recvKeySuffix, service, security.AllowEveryone()); err != nil {
-		return fmt.Errorf("failed to setup service for receiving keys: %v", err)
+	server, err := xrpc.NewServer(ctx, recvKeySuffix, service, security.AllowEveryone())
+	if err != nil {
+		return fmt.Errorf("failed to create server to receive keys: %v", err)
 	}
-
+	defer server.Stop()
 	fmt.Println("Waiting for keys")
 	return <-service.notify
 }
diff --git a/go/src/v.io/x/lock/lockd/starter.go b/go/src/v.io/x/lock/lockd/starter.go
index f40f56e..0be2c4e 100644
--- a/go/src/v.io/x/lock/lockd/starter.go
+++ b/go/src/v.io/x/lock/lockd/starter.go
@@ -15,6 +15,7 @@
 
 	"v.io/x/lib/vlog"
 	"v.io/x/lock/locklib"
+	"v.io/x/ref/lib/xrpc"
 )
 
 var unclaimedLockNhSuffix = "unclaimed-lock-" + fmt.Sprintf("%d", rand.Intn(1000000))
@@ -58,7 +59,8 @@
 		stopMT()
 		return nil, nil, err
 	}
-	server, err := v23.NewServer(ctx)
+	claimed := make(chan struct{})
+	server, err := xrpc.NewServer(ctx, lockObjectName(ctx), newUnclaimedLock(claimed, configDir), security.AllowEveryone())
 	if err != nil {
 		stopMT()
 		return nil, nil, err
@@ -69,20 +71,8 @@
 		vlog.Infof("Stopped unclaimed lock server...")
 		stopMT()
 	}
-	endpoints, err := server.Listen(v23.GetListenSpec(ctx))
-	if err != nil {
-		stopUnclaimedLock()
-		return nil, nil, err
-	}
-
-	claimed := make(chan struct{})
-	if err := server.Serve(lockObjectName(ctx), newUnclaimedLock(claimed, configDir), security.AllowEveryone()); err != nil {
-		stopUnclaimedLock()
-		return nil, nil, err
-	}
-
 	vlog.Infof("Started unclaimed lock server\n")
-	vlog.Infof("ENDPOINT: %v\n", endpoints[0].Name())
+	vlog.Infof("ENDPOINT: %v\n", server.Status().Endpoints[0].Name())
 	return claimed, stopUnclaimedLock, nil
 }
 
@@ -100,7 +90,7 @@
 		stopMT()
 		return nil, err
 	}
-	server, err := v23.NewServer(ctx)
+	server, err := xrpc.NewServer(ctx, lockObjectName(ctx), newLock(), security.DefaultAuthorizer())
 	if err != nil {
 		stopMT()
 		return nil, err
@@ -111,19 +101,8 @@
 		vlog.Infof("Stopped lock server...")
 		stopMT()
 	}
-	endpoints, err := server.Listen(v23.GetListenSpec(ctx))
-	if err != nil {
-		stopLock()
-		return nil, err
-	}
-
-	if err := server.Serve(lockObjectName(ctx), newLock(), security.DefaultAuthorizer()); err != nil {
-		stopLock()
-		return nil, err
-	}
-
 	vlog.Infof("Started lock server\n")
-	vlog.Infof("ENDPOINT: %v\n", endpoints[0].Name())
+	vlog.Infof("ENDPOINT: %v\n", server.Status().Endpoints[0].Name())
 	return stopLock, nil
 }