Exemplo n.º 1
0
func connectContext(
	broker *muxBroker,
	ctx *context.Shared, args *ContextSharedArgs) (io.Closer, error) {
	closer := &multiCloser{}

	// Setup Directory
	conn, err := broker.Dial(args.DirectoryId)
	if err != nil {
		return closer, err
	}
	client := rpc.NewClient(conn)
	closer.Closers = append(closer.Closers, client)
	ctx.Directory = &Directory{
		Broker: broker,
		Client: client,
		Name:   "Directory",
	}

	// Setup Ui
	conn, err = broker.Dial(args.UiId)
	if err != nil {
		return closer, err
	}
	client = rpc.NewClient(conn)
	closer.Closers = append(closer.Closers, client)
	ctx.Ui = &Ui{
		Client: client,
		Name:   "Ui",
	}

	return closer, nil
}
Exemplo n.º 2
0
func serveContext(broker *muxBroker, ctx *context.Shared, args *ContextSharedArgs) {
	// Serve the directory
	id := broker.NextId()
	go acceptAndServe(broker, id, "Directory", &DirectoryServer{
		Broker:    broker,
		Directory: ctx.Directory,
	})
	args.DirectoryId = id

	// Server the Ui
	id = broker.NextId()
	go acceptAndServe(broker, id, "Ui", &UiServer{
		Ui: ctx.Ui,
	})
	args.UiId = id

	// Set the context fields to nil so that they aren't sent over the
	// network (Go will just panic if we didn't do this).
	ctx.Directory = nil
	ctx.Ui = nil
}