Esempio n. 1
0
func (r *Runtime) Listen(service string, receiver interface{}) {
	if IsX(receiver) {
		panic("listen service receiver cannot be a cross-interface")
	}
	types.RegisterValue(receiver)
	r.srv.Add(service, receiver)
}
Esempio n. 2
0
func (r *Runtime) SetBoot(v interface{}) {
	r.blk.Lock()
	defer r.blk.Unlock()
	if v != nil {
		types.RegisterValue(v)
	}
	r.boot = v
}
Esempio n. 3
0
func TestRe(t *testing.T) {
	r := make([]*Runtime, 3)
	l := make([]n.Transport, len(r))
	for i := 0; i < len(r); i++ {
		l[i] = NewSandbox()
		r[i] = New(l[i])
		r[i].Listen("test", &testBoot{fmt.Sprintf("π%d", i)})
	}
	types.RegisterValue(&testGreeter{})

	// R1 gets boot value of R0
	r1b0, err := r[1].TryDial(l[0].Addr(), "test")
	if err != nil {
		t.Fatalf("dial r1b0 (%s)", err)
	}

	// R1 gets an ptr to a new greeter residing on R0
	g0 := r1b0.Call("NewGreeter")[0].(circuit.X)

	// R1 gets boot value of R2
	r1b2, err := r[1].TryDial(l[2].Addr(), "test")
	if err != nil {
		t.Fatalf("dial r1b2 (%s)", err)
	}

	// R1 passes the greeter g0 to R2; R2 will invoke a method in g0
	g := r1b2.Call("UseGreeter", g0)[0].(string)
	if g != testGreeting {
		t.Errorf("exp %s, got %s", testGreeting, g)
	}

	// Kick GC to initiate relinquishPtr from R2 to R1
	runtime.GC()
	runtime.Gosched()
	time.Sleep(time.Second)
}
Esempio n. 4
0
// RegisterValue registers the type of v with the circuit runtime type system.
// As a result this program becomes able to send and receive cross-interfaces pointing to objects of this type.
// By convention, RegisterValue should be invoked from a dedicated init
// function within of the package that defines the type of v.
func RegisterValue(v interface{}) {
	types.RegisterValue(v)
}
Esempio n. 5
0
func (r *Runtime) RegisterValue(v interface{}) {
	types.RegisterValue(v)
}