v.io/x/ref: add namespace factory option to rt.Init()
This option will be used by the android runtime to override
default namespace creation. We need this functionality in order
to implement remote GCM wakeups, which are performed by the
special mounttable we run.
Change-Id: I6b20329a550a07c84c41c2a9412c64f860803473
diff --git a/runtime/factories/android/android.go b/runtime/factories/android/android.go
index 5704786..49c376a 100644
--- a/runtime/factories/android/android.go
+++ b/runtime/factories/android/android.go
@@ -19,6 +19,7 @@
"v.io/v23"
"v.io/v23/context"
"v.io/v23/flow"
+ "v.io/v23/namespace"
"v.io/v23/rpc"
"v.io/x/ref/internal/logger"
@@ -30,6 +31,7 @@
"v.io/x/ref/runtime/internal/lib/appcycle"
"v.io/x/ref/runtime/internal/lib/roaming"
"v.io/x/ref/runtime/internal/lib/xwebsocket"
+ inamespace "v.io/x/ref/runtime/internal/naming/namespace"
"v.io/x/ref/runtime/internal/rt"
_ "v.io/x/ref/runtime/protocols/tcp"
_ "v.io/x/ref/runtime/protocols/ws"
@@ -37,18 +39,29 @@
"v.io/x/ref/services/debug/debuglib"
)
+var (
+ commonFlags *flags.Flags
+ namespaceFactory inamespace.Factory
+)
+
const (
connIdleExpiry = 15 * time.Second
)
-var commonFlags *flags.Flags
-
func init() {
v23.RegisterRuntimeFactory(Init)
flow.RegisterUnknownProtocol("wsh", xwebsocket.WSH{})
commonFlags = flags.CreateAndRegister(flag.CommandLine, flags.Runtime, flags.Listen)
}
+// Sets the namespace factory to be used for creating all namespaces.
+//
+// If never invoked, a default namespace factory will be used. If invoked,
+// must be before Init() function below, i.e., before v23.Init().
+func SetNamespaceFactory(factory func(*context.T, namespace.T, ...string) (namespace.T, error)) {
+ namespaceFactory = inamespace.Factory(factory)
+}
+
func Init(ctx *context.T) (v23.Runtime, *context.T, v23.Shutdown, error) {
if err := internal.ParseFlagsAndConfigureGlobalLogger(commonFlags); err != nil {
return nil, nil, nil, err
@@ -76,7 +89,7 @@
publisher := pubsub.NewPublisher()
- runtime, ctx, shutdown, err := rt.Init(ctx, ac, discoveryFactory, nil, &listenSpec, publisher, commonFlags.RuntimeFlags(), reservedDispatcher, connIdleExpiry)
+ runtime, ctx, shutdown, err := rt.Init(ctx, ac, discoveryFactory, namespaceFactory, nil, &listenSpec, publisher, commonFlags.RuntimeFlags(), reservedDispatcher, connIdleExpiry)
if err != nil {
ishutdown()
return nil, nil, nil, err
diff --git a/runtime/factories/chrome/chrome.go b/runtime/factories/chrome/chrome.go
index 9bde6ab..ed49651 100644
--- a/runtime/factories/chrome/chrome.go
+++ b/runtime/factories/chrome/chrome.go
@@ -37,7 +37,7 @@
protocols := []string{"wsh", "ws"}
listenSpec := rpc.ListenSpec{Addrs: rpc.ListenAddrs{{Protocol: "ws", Address: ""}}}
- runtime, ctx, shutdown, err := grt.Init(ctx, nil, nil, protocols, &listenSpec, nil, commonFlags.RuntimeFlags(), nil, 0)
+ runtime, ctx, shutdown, err := grt.Init(ctx, nil, nil, nil, protocols, &listenSpec, nil, commonFlags.RuntimeFlags(), nil, 0)
if err != nil {
return nil, nil, nil, err
}
diff --git a/runtime/factories/gce/gce.go b/runtime/factories/gce/gce.go
index a28801c..b230fc6 100644
--- a/runtime/factories/gce/gce.go
+++ b/runtime/factories/gce/gce.go
@@ -64,7 +64,7 @@
})
}
- runtime, ctx, shutdown, err := grt.Init(ctx, ac, nil, nil, &listenSpec, nil, commonFlags.RuntimeFlags(), nil, 0)
+ runtime, ctx, shutdown, err := grt.Init(ctx, ac, nil, nil, nil, &listenSpec, nil, commonFlags.RuntimeFlags(), nil, 0)
if err != nil {
ac.Shutdown()
return nil, nil, nil, err
diff --git a/runtime/factories/generic/generic.go b/runtime/factories/generic/generic.go
index de7c2a6..ac3a0d6 100644
--- a/runtime/factories/generic/generic.go
+++ b/runtime/factories/generic/generic.go
@@ -58,7 +58,7 @@
discoveryFactory.Shutdown()
}
- runtime, ctx, shutdown, err := grt.Init(ctx, ac, discoveryFactory, nil, &listenSpec, nil, commonFlags.RuntimeFlags(), nil, 0)
+ runtime, ctx, shutdown, err := grt.Init(ctx, ac, discoveryFactory, nil, nil, &listenSpec, nil, commonFlags.RuntimeFlags(), nil, 0)
if err != nil {
ishutdown()
return nil, nil, nil, err
diff --git a/runtime/factories/roaming/roaming.go b/runtime/factories/roaming/roaming.go
index 926e486..e8e6ea3 100644
--- a/runtime/factories/roaming/roaming.go
+++ b/runtime/factories/roaming/roaming.go
@@ -72,7 +72,7 @@
publisher := pubsub.NewPublisher()
- runtime, ctx, shutdown, err := rt.Init(ctx, ac, discoveryFactory, nil, &listenSpec, publisher, commonFlags.RuntimeFlags(), reservedDispatcher, 0)
+ runtime, ctx, shutdown, err := rt.Init(ctx, ac, discoveryFactory, nil, nil, &listenSpec, publisher, commonFlags.RuntimeFlags(), reservedDispatcher, 0)
if err != nil {
ishutdown()
return nil, nil, nil, err