Esempio n. 1
0
//export Java_io_v_impl_google_lib_discovery_UpdateImpl_nativeAttachment
func Java_io_v_impl_google_lib_discovery_UpdateImpl_nativeAttachment(jenv *C.JNIEnv, _ C.jobject, goRef C.jlong, jCtx C.jobject, jName C.jstring, jCbObj C.jobject) {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	ctx, _, err := jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jCtx))))
	if err != nil {
		jutil.JThrowV(env, err)
		return
	}

	update := *(*discovery.Update)(jutil.GoRefValue(jutil.Ref(goRef)))
	name := jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jName))))

	jCb := jutil.Object(uintptr(unsafe.Pointer(jCbObj)))
	jutil.DoAsyncCall(env, jCb, func() (jutil.Object, error) {
		dataOrErr := <-update.Attachment(ctx, name)
		if dataOrErr.Error != nil {
			return jutil.NullObject, err
		}

		env, freeFunc := jutil.GetEnv()
		defer freeFunc()

		jData, err := jutil.JByteArray(env, dataOrErr.Data)
		if err != nil {
			return jutil.NullObject, err
		}
		// Must grab a global reference as we free up the env and all local references that come
		// along with it.
		return jutil.NewGlobalRef(env, jData), nil // Un-refed in DoAsyncCall
	})
}
Esempio n. 2
0
//export Java_io_v_v23_security_PublicKeyThirdPartyCaveatValidator_nativeValidate
func Java_io_v_v23_security_PublicKeyThirdPartyCaveatValidator_nativeValidate(jenv *C.JNIEnv, jThirdPartyValidatorClass C.jclass, jContext C.jobject, jCall C.jobject, jCaveatParam C.jobject) {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	param, err := jutil.GoVomCopyValue(env, jutil.Object(uintptr(unsafe.Pointer(jCaveatParam))))
	if err != nil {
		jutil.JThrowV(env, err)
		return
	}
	ctx, _, err := jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jContext))))
	if err != nil {
		jutil.JThrowV(env, err)
		return
	}
	call, err := GoCall(env, jutil.Object(uintptr(unsafe.Pointer(jCall))))
	if err != nil {
		jutil.JThrowV(env, err)
		return
	}
	caveat, err := security.NewCaveat(security.PublicKeyThirdPartyCaveat, param)
	if err != nil {
		jutil.JThrowV(env, err)
		return
	}
	if err := caveat.Validate(ctx, call); err != nil {
		jutil.JThrowV(env, err)
		return
	}
}
Esempio n. 3
0
//export Java_io_v_v23_security_VSecurity_nativeGetSigningBlessingNames
func Java_io_v_v23_security_VSecurity_nativeGetSigningBlessingNames(jenv *C.JNIEnv, jVSecurityClass C.jclass, jCtx C.jobject, jPrincipal C.jobject, jBlessings C.jobject) C.jobjectArray {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	ctx, _, err := jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jCtx))))
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	principal, err := GoPrincipal(env, jutil.Object(uintptr(unsafe.Pointer(jPrincipal))))
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	blessings, err := GoBlessings(env, jutil.Object(uintptr(unsafe.Pointer(jBlessings))))
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	blessingStrs, _ := security.SigningBlessingNames(ctx, principal, blessings)
	jArr, err := jutil.JStringArray(env, blessingStrs)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	return C.jobjectArray(unsafe.Pointer(jArr))
}
Esempio n. 4
0
//export Java_io_v_impl_google_lib_discovery_GlobalDiscovery_nativeNewDiscovery
func Java_io_v_impl_google_lib_discovery_GlobalDiscovery_nativeNewDiscovery(jenv *C.JNIEnv, jRuntime C.jclass, jContext C.jobject, jPath C.jstring, jMountTTL, jScanInterval C.jobject) C.jobject {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	ctx, _, err := jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jContext))))
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	path := jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jPath))))
	mountTTL, err := jutil.GoDuration(env, jutil.Object(uintptr(unsafe.Pointer(jMountTTL))))
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	scanInterval, err := jutil.GoDuration(env, jutil.Object(uintptr(unsafe.Pointer(jScanInterval))))
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}

	discovery, err := gdiscovery.NewWithTTL(ctx, path, mountTTL, scanInterval)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	jDiscovery, err := JavaDiscovery(env, discovery)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	return C.jobject(unsafe.Pointer(jDiscovery))
}
Esempio n. 5
0
//export Java_io_v_impl_google_lib_discovery_FactoryUtil_injectMockPlugin
func Java_io_v_impl_google_lib_discovery_FactoryUtil_injectMockPlugin(jenv *C.JNIEnv, _ C.jclass, jCtx C.jobject) {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	ctx, _, err := jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jCtx))))
	if err != nil {
		jutil.JThrowV(env, err)
		return
	}
	injectMockPlugin(ctx)
}
Esempio n. 6
0
func unmountArgs(env jutil.Env, jName, jServer C.jstring, jContext, jOptions C.jobject) (name, server string, context *context.T, options []naming.NamespaceOpt, err error) {
	name = jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jName))))
	server = jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jServer))))
	context, _, err = jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jContext))))
	if err != nil {
		return
	}
	options, err = goNamespaceOptions(env, jutil.Object(uintptr(unsafe.Pointer(jOptions))))
	return
}
Esempio n. 7
0
//export Java_io_v_impl_google_lib_discovery_DiscoveryImpl_nativeAdvertise
func Java_io_v_impl_google_lib_discovery_DiscoveryImpl_nativeAdvertise(jenv *C.JNIEnv, _ C.jobject, goRef C.jlong, jCtx C.jobject, jAdObj C.jobject, jVisibilityObj C.jobject, jCbObj C.jobject) {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	ctx, _, err := jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jCtx))))
	if err != nil {
		jutil.JThrowV(env, err)
		return
	}

	d := *(*discovery.T)(jutil.GoRefValue(jutil.Ref(goRef)))
	jAd := jutil.Object(uintptr(unsafe.Pointer(jAdObj)))
	jVisibility := jutil.Object(uintptr(unsafe.Pointer(jVisibilityObj)))

	var ad discovery.Advertisement
	if err := jutil.GoVomCopy(env, jAd, jAdvertisementClass, &ad); err != nil {
		jutil.JThrowV(env, err)
		return
	}

	jVisibilityList, err := jutil.GoObjectList(env, jVisibility)
	if err != nil {
		jutil.JThrowV(env, err)
		return
	}
	visibility := make([]security.BlessingPattern, len(jVisibilityList))
	for i, jPattern := range jVisibilityList {
		if err := jutil.GoVomCopy(env, jPattern, jBlessingPatternClass, &visibility[i]); err != nil {
			jutil.JThrowV(env, err)
			return
		}
	}

	done, err := d.Advertise(ctx, &ad, visibility)
	if err != nil {
		jutil.JThrowV(env, err)
		return
	}

	// Copy back the advertisement id.
	jId, err := jutil.JVomCopy(env, &ad.Id, jAdIdClass)
	if err != nil {
		jutil.JThrowV(env, err)
		return
	}
	if err = jutil.CallVoidMethod(env, jAd, "setId", []jutil.Sign{adIdSign}, jId); err != nil {
		jutil.JThrowV(env, err)
		return
	}

	jCb := jutil.Object(uintptr(unsafe.Pointer(jCbObj)))
	jutil.DoAsyncCall(env, jCb, func() (jutil.Object, error) {
		<-done
		return jutil.NullObject, nil
	})
}
Esempio n. 8
0
func globArgs(env jutil.Env, jContext C.jobject, jPattern C.jstring, jOptions C.jobject) (context *context.T, cancel func(), pattern string, opts []naming.NamespaceOpt, err error) {
	context, cancel, err = jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jContext))))
	if err != nil {
		return
	}
	opts, err = goNamespaceOptions(env, jutil.Object(uintptr(unsafe.Pointer(jOptions))))
	if err != nil {
		return
	}
	pattern = jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jPattern))))
	return
}
Esempio n. 9
0
func getPermissionsArgs(env jutil.Env, jContext C.jobject, jName C.jstring, jOptions C.jobject) (context *context.T, name string, options []naming.NamespaceOpt, err error) {
	context, _, err = jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jContext))))
	if err != nil {
		return
	}
	options, err = goNamespaceOptions(env, jutil.Object(uintptr(unsafe.Pointer(jOptions))))
	if err != nil {
		return
	}
	name = jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jName))))
	return
}
Esempio n. 10
0
func resolveToMountTableArgs(env jutil.Env, jContext, jOptions C.jobject, jName C.jstring) (context *context.T, options []naming.NamespaceOpt, name string, err error) {
	context, _, err = jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jContext))))
	if err != nil {
		return
	}
	options, err = goNamespaceOptions(env, jutil.Object(uintptr(unsafe.Pointer(jOptions))))
	if err != nil {
		return
	}
	name = jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jName))))
	return
}
Esempio n. 11
0
func deleteArgs(env jutil.Env, jContext, jOptions C.jobject, jName C.jstring, jDeleteSubtree C.jboolean) (context *context.T, options []naming.NamespaceOpt, name string, deleteSubtree bool, err error) {
	context, _, err = jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jContext))))
	if err != nil {
		return
	}
	options, err = goNamespaceOptions(env, jutil.Object(uintptr(unsafe.Pointer(jOptions))))
	if err != nil {
		return
	}
	name = jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jName))))
	deleteSubtree = jDeleteSubtree == C.JNI_TRUE
	return
}
Esempio n. 12
0
//export Java_io_v_v23_syncbase_DatabaseImpl_nativeListenForInvites
func Java_io_v_v23_syncbase_DatabaseImpl_nativeListenForInvites(jenv *C.JNIEnv, jDatabase C.jobject, jContext C.jobject, jInviteHandler C.jobject) {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	database := jutil.Object(uintptr(unsafe.Pointer(jDatabase)))
	handler := jutil.Object(uintptr(unsafe.Pointer(jInviteHandler)))

	ctx, _, err := jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jContext))))
	if err != nil {
		jutil.JThrowV(env, err)
		return
	}

	jDbId, err := jutil.CallObjectMethod(env, database, "id", nil, idSign)
	if err != nil {
		jutil.JThrowV(env, err)
		return
	}
	dbName, err := jutil.CallStringMethod(env, jDbId, "getName", nil)
	if err != nil {
		jutil.JThrowV(env, err)
		return
	}
	dbBlessing, err := jutil.CallStringMethod(env, jDbId, "getBlessing", nil)
	if err != nil {
		jutil.JThrowV(env, err)
		return
	}

	dbId := wire.Id{Name: dbName, Blessing: dbBlessing}
	// Note: There is no need to use a buffered channel here.  ListenForInvites
	// spawns a goroutine for this listener that acts as an infinite buffer so we can
	// process invites at our own pace.
	ch := make(chan discovery.Invite)
	if err := discovery.ListenForInvites(ctx, dbId, ch); err != nil {
		jutil.JThrowV(env, err)
		return
	}

	handler = jutil.NewGlobalRef(env, handler)
	go func() {
		for invite := range ch {
			if err := handleInvite(invite, handler); err != nil {
				// TODO(mattr): We should cancel the stream and return an error to
				// the user here.
				ctx.Errorf("couldn't call invite handler: %v", err)
			}
		}
		env, free := jutil.GetEnv()
		jutil.DeleteGlobalRef(env, handler)
		free()
	}()
}
Esempio n. 13
0
func setPermissionsArgs(env jutil.Env, jContext, jPermissions C.jobject, jName, jVersion C.jstring, jOptions C.jobject) (context *context.T, permissions access.Permissions, name, version string, options []naming.NamespaceOpt, err error) {
	context, _, err = jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jContext))))
	if err != nil {
		return
	}
	err = jutil.GoVomCopy(env, jutil.Object(uintptr(unsafe.Pointer(jPermissions))), jPermissionsClass, &permissions)
	if err != nil {
		return
	}
	options, err = goNamespaceOptions(env, jutil.Object(uintptr(unsafe.Pointer(jOptions))))
	name = jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jName))))
	version = jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jVersion))))
	return
}
Esempio n. 14
0
func mountArgs(env jutil.Env, jContext C.jobject, jName, jServer C.jstring, jDuration, jOptions C.jobject) (context *context.T, name, server string, duration time.Duration, options []naming.NamespaceOpt, err error) {
	context, _, err = jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jContext))))
	if err != nil {
		return
	}
	name = jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jName))))
	server = jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jServer))))
	duration, err = jutil.GoDuration(env, jutil.Object(uintptr(unsafe.Pointer(jDuration))))
	if err != nil {
		return
	}
	options, err = goNamespaceOptions(env, jutil.Object(uintptr(unsafe.Pointer(jOptions))))
	return
}
Esempio n. 15
0
func (c *callImpl) Context() *context.T {
	env, freeFunc := jutil.GetEnv()
	defer freeFunc()
	contextSign := jutil.ClassSign("io.v.v23.context.VContext")
	jCtx, err := jutil.CallObjectMethod(env, c.jCall, "context", nil, contextSign)
	if err != nil {
		log.Printf("Couldn't get Java Vanadium context: %v", err)
	}
	ctx, _, err := jcontext.GoContext(env, jCtx)
	if err != nil {
		log.Printf("Couldn't convert Java Vanadium context to Go: %v", err)
	}
	return ctx
}
Esempio n. 16
0
//export Java_io_v_impl_google_namespace_NamespaceImpl_nativeFlushCacheEntry
func Java_io_v_impl_google_namespace_NamespaceImpl_nativeFlushCacheEntry(jenv *C.JNIEnv, jNamespaceClass C.jclass, goRef C.jlong, jContext C.jobject, jName C.jstring) C.jboolean {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	n := *(*namespace.T)(jutil.GoRefValue(jutil.Ref(goRef)))
	context, _, err := jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jContext))))
	if err != nil {
		jutil.JThrowV(env, err)
		return C.JNI_FALSE
	}
	result := n.FlushCacheEntry(context, jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jName)))))
	if result {
		return C.JNI_TRUE
	} else {
		return C.JNI_FALSE
	}
}
Esempio n. 17
0
//export Java_io_v_v23_security_access_AccessList_nativeAuthorize
func Java_io_v_v23_security_access_AccessList_nativeAuthorize(jenv *C.JNIEnv, jAccessList C.jobject, goRef C.jlong, jCtx C.jobject, jCall C.jobject) {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	ctx, _, err := jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jCtx))))
	if err != nil {
		jutil.JThrowV(env, err)
		return
	}
	call, err := jsecurity.GoCall(env, jutil.Object(uintptr(unsafe.Pointer(jCall))))
	if err != nil {
		jutil.JThrowV(env, err)
	}
	if err := (*(*access.AccessList)(jutil.GoRefValue(jutil.Ref(goRef)))).Authorize(ctx, call); err != nil {
		jutil.JThrowV(env, err)
		return
	}
}
Esempio n. 18
0
//export Java_io_v_v23_services_groups_PermissionsAuthorizer_nativeAuthorize
func Java_io_v_v23_services_groups_PermissionsAuthorizer_nativeAuthorize(jenv *C.JNIEnv, jPermissionsAuthorizer C.jobject, goRef C.jlong, jContext C.jobject, jCall C.jobject) {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	ctx, _, err := jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jContext))))
	if err != nil {
		jutil.JThrowV(env, err)
		return
	}
	call, err := jsecurity.GoCall(env, jutil.Object(uintptr(unsafe.Pointer(jCall))))
	if err != nil {
		jutil.JThrowV(env, err)
		return
	}
	if err := (*(*security.Authorizer)(jutil.GoRefValue(jutil.Ref(goRef)))).Authorize(ctx, call); err != nil {
		jutil.JThrowV(env, err)
		return
	}
}
Esempio n. 19
0
//export Java_io_v_android_util_Vango_nativeGoContextCall
func Java_io_v_android_util_Vango_nativeGoContextCall(jenv *C.JNIEnv, jVango C.jobject, jContext C.jobject, jKey C.jstring, jOutput C.jobject) {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	key := jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jKey))))
	ctx, _, err := jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jContext))))
	if err != nil {
		jutil.JThrowV(env, err)
		return
	}
	f, ok := vangoFuncs[key]
	if !ok {
		jutil.JThrowV(env, fmt.Errorf("vangoFunc key %q doesn't exist", key))
		return
	}
	if err := f(ctx, newJavaOutputWriter(env, jutil.Object(uintptr(unsafe.Pointer(jOutput))))); err != nil {
		jutil.JThrowV(env, err)
		return
	}

}
Esempio n. 20
0
//export Java_io_v_v23_security_VSecurity_nativeGetLocalBlessingNames
func Java_io_v_v23_security_VSecurity_nativeGetLocalBlessingNames(jenv *C.JNIEnv, jVSecurityClass C.jclass, jCtx C.jobject, jCall C.jobject) C.jobjectArray {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	ctx, _, err := jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jCtx))))
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	call, err := GoCall(env, jutil.Object(uintptr(unsafe.Pointer(jCall))))
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	blessingStrs := security.LocalBlessingNames(ctx, call)
	jArr, err := jutil.JStringArray(env, blessingStrs)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	return C.jobjectArray(unsafe.Pointer(jArr))
}
Esempio n. 21
0
//export Java_io_v_impl_google_lib_discovery_DiscoveryImpl_nativeScan
func Java_io_v_impl_google_lib_discovery_DiscoveryImpl_nativeScan(jenv *C.JNIEnv, _ C.jobject, goRef C.jlong, jCtx C.jobject, jQuery C.jstring) C.jobject {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	ctx, _, err := jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jCtx))))
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}

	d := *(*discovery.T)(jutil.GoRefValue(jutil.Ref(goRef)))
	query := jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jQuery))))

	scanCh, err := d.Scan(ctx, query)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}

	jChannel, err := jchannel.JavaInputChannel(env, ctx, nil, func() (jutil.Object, error) {
		update, ok := <-scanCh
		if !ok {
			return jutil.NullObject, verror.NewErrEndOfFile(ctx)
		}

		env, freeFunc := jutil.GetEnv()
		defer freeFunc()

		jUpdate, err := javaUpdate(env, update)
		if err != nil {
			return jutil.NullObject, err
		}
		// Must grab a global reference as we free up the env and all local references that come
		// along with it.
		return jutil.NewGlobalRef(env, jUpdate), nil // un-refed by InputChannelImpl_nativeRecv
	})
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	return C.jobject(unsafe.Pointer(jChannel))
}
Esempio n. 22
0
//export Java_io_v_impl_google_rpc_ClientImpl_nativeStartCall
func Java_io_v_impl_google_rpc_ClientImpl_nativeStartCall(jenv *C.JNIEnv, jClientObj C.jobject, goRef C.jlong,
	jContext C.jobject, jName C.jstring, jMethod C.jstring, jVomArgs C.jobjectArray, jOptionsObj C.jobject, jCallbackObj C.jobject) {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	name := jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jName))))
	method := jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jMethod))))
	jOptions := jutil.Object(uintptr(unsafe.Pointer(jOptionsObj)))
	jCallback := jutil.Object(uintptr(unsafe.Pointer(jCallbackObj)))
	ctx, cancel, err := jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jContext))))
	if err != nil {
		jutil.CallbackOnFailure(env, jCallback, err)
		return
	}
	args, err := decodeArgs(env, jVomArgs)
	if err != nil {
		jutil.CallbackOnFailure(env, jCallback, err)
		return
	}

	opts, err := jopts.GoRpcOpts(env, jOptions)
	if err != nil {
		jutil.CallbackOnFailure(env, jCallback, err)
		return
	}

	// Create a global reference to the client object for the duration of the call
	// so that the java object doesn't get garbage collected while the async call
	// is happening. This is an issue because if the java object is garbage collected,
	// the go ref will also be collected causing doStartCall to panic.
	jClient := jutil.NewGlobalRef(env, jutil.Object(uintptr(unsafe.Pointer(jClientObj))))
	jutil.DoAsyncCall(env, jCallback, func() (jutil.Object, error) {
		obj, err := doStartCall(ctx, cancel, name, method, opts, goRef, args)
		env, freeFunc := jutil.GetEnv()
		jutil.DeleteGlobalRef(env, jClient)
		freeFunc()
		return obj, err
	})
}
Esempio n. 23
0
//export Java_io_v_impl_google_services_groups_GroupServer_nativeWithNewServer
func Java_io_v_impl_google_services_groups_GroupServer_nativeWithNewServer(jenv *C.JNIEnv, jGroupServerClass C.jclass, jContext C.jobject, jGroupServerParams C.jobject) C.jobject {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	jCtx := jutil.Object(uintptr(unsafe.Pointer(jContext)))
	jParams := jutil.Object(uintptr(unsafe.Pointer(jGroupServerParams)))

	// Read and translate all of the server params.
	name, err := jutil.CallStringMethod(env, jParams, "getName", nil)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	rootDir, err := jutil.CallStringMethod(env, jParams, "getStorageRootDir", nil)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	if rootDir == "" {
		rootDir = filepath.Join(os.TempDir(), "groupserver")
		if err := os.Mkdir(rootDir, 0755); err != nil && !os.IsExist(err) {
			jutil.JThrowV(env, err)
			return nil
		}
	}
	jEngine, err := jutil.CallObjectMethod(env, jParams, "getStorageEngine", nil, storageEngineSign)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	engine, err := GoStorageEngine(env, jEngine)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}

	// Start the server.
	ctx, cancel, err := jcontext.GoContext(env, jCtx)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	dispatcher, err := lib.NewGroupsDispatcher(rootDir, engine)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	newCtx, s, err := v23.WithNewDispatchingServer(ctx, name, dispatcher)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	jNewCtx, err := jcontext.JavaContext(env, newCtx, cancel)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	jServer, err := jrpc.JavaServer(env, s)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	// Attach a server to the new context.
	jServerAttCtx, err := jutil.CallStaticObjectMethod(env, jVRuntimeImplClass, "withServer", []jutil.Sign{contextSign, serverSign}, contextSign, jNewCtx, jServer)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	return C.jobject(unsafe.Pointer(jServerAttCtx))
}
Esempio n. 24
0
//export Java_io_v_impl_google_services_mounttable_MountTableServer_nativeWithNewServer
func Java_io_v_impl_google_services_mounttable_MountTableServer_nativeWithNewServer(jenv *C.JNIEnv, jMountTableServerClass C.jclass, jContext C.jobject, jMountTableServerParams C.jobject) C.jobject {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	jCtx := jutil.Object(uintptr(unsafe.Pointer(jContext)))
	jParams := jutil.Object(uintptr(unsafe.Pointer(jMountTableServerParams)))

	// Read and translate all of the server params.
	mountName, err := jutil.CallStringMethod(env, jParams, "getName", nil)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	rootDir, err := jutil.CallStringMethod(env, jParams, "getStorageRootDir", nil)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	permsJMap, err := jutil.CallMapMethod(env, jParams, "getPermissions", nil)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	permsMap := make(map[string]access.Permissions)
	for jPath, jPerms := range permsJMap {
		path := jutil.GoString(env, jPath)
		perms, err := jaccess.GoPermissions(env, jPerms)
		if err != nil {
			jutil.JThrowV(env, err)
			return nil
		}
		permsMap[path] = perms
	}
	// Write JSON-encoded permissions to a file.
	jsonPerms, err := json.Marshal(permsMap)
	if err != nil {
		jutil.JThrowV(env, fmt.Errorf("Couldn't JSON-encode path-permissions: %v", err))
		return nil

	}
	permsFile, err := ioutil.TempFile(rootDir, "jni_permissions")
	if err != nil {
		jutil.JThrowV(env, fmt.Errorf("Couldn't create permissions file: %v", err))
		return nil
	}
	w := bufio.NewWriter(permsFile)
	if _, err := w.Write(jsonPerms); err != nil {
		jutil.JThrowV(env, fmt.Errorf("Couldn't write to permissions file: %v", err))
		return nil
	}
	if err := w.Flush(); err != nil {
		jutil.JThrowV(env, fmt.Errorf("Couldn't flush to permissions file: %v", err))
	}
	statsPrefix, err := jutil.CallStringMethod(env, jParams, "getStatsPrefix", nil)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}

	// Start the mounttable server.
	ctx, cancel, err := jcontext.GoContext(env, jCtx)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	d, err := mounttablelib.NewMountTableDispatcher(ctx, permsFile.Name(), rootDir, statsPrefix)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	newCtx, s, err := v23.WithNewDispatchingServer(ctx, mountName, d, options.ServesMountTable(true))
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	jNewCtx, err := jcontext.JavaContext(env, newCtx, cancel)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	jServer, err := jrpc.JavaServer(env, s)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	// Attach a server to the new context.
	jServerAttCtx, err := jutil.CallStaticObjectMethod(env, jVRuntimeImplClass, "withServer", []jutil.Sign{contextSign, serverSign}, contextSign, jNewCtx, jServer)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	return C.jobject(unsafe.Pointer(jServerAttCtx))
}
Esempio n. 25
0
//export Java_io_v_impl_google_services_syncbase_SyncbaseServer_nativeWithNewServer
func Java_io_v_impl_google_services_syncbase_SyncbaseServer_nativeWithNewServer(jenv *C.JNIEnv, jSyncbaseServerClass C.jclass, jContext C.jobject, jSyncbaseServerParams C.jobject) C.jobject {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	jCtx := jutil.Object(uintptr(unsafe.Pointer(jContext)))
	jParams := jutil.Object(uintptr(unsafe.Pointer(jSyncbaseServerParams)))

	// Read and translate all of the server params.
	jPerms, err := jutil.CallObjectMethod(env, jParams, "getPermissions", nil, permissionsSign)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	perms, err := jaccess.GoPermissions(env, jPerms)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	name, err := jutil.CallStringMethod(env, jParams, "getName", nil)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	rootDir, err := jutil.CallStringMethod(env, jParams, "getStorageRootDir", nil)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	if rootDir == "" {
		rootDir = filepath.Join(os.TempDir(), "syncbaseserver")
		if err := os.Mkdir(rootDir, 0755); err != nil && !os.IsExist(err) {
			jutil.JThrowV(env, err)
			return nil
		}
	}
	jEngine, err := jutil.CallObjectMethod(env, jParams, "getStorageEngine", nil, storageEngineSign)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	engine, err := GoStorageEngine(env, jEngine)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	ctx, cancel, err := jcontext.GoContext(env, jCtx)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}

	// Create the rpc server before the service so that connections are shared between
	// clients in the service and the rpc server. (i.e. connections are shared if the
	// context returned from WithNewDispatchingServer is used for client calls).
	d := dispatcher.NewDispatcherWrapper()
	ctx, s, err := v23.WithNewDispatchingServer(ctx, name, d, options.ChannelTimeout(vsync.NeighborConnectionTimeout))
	if err != nil {
		cancel()
		jutil.JThrowV(env, err)
		return nil
	}

	service, err := server.NewService(ctx, server.ServiceOptions{
		Perms:   perms,
		RootDir: rootDir,
		Engine:  engine,
	})
	if err != nil {
		cancel()
		jutil.JThrowV(env, err)
		return nil
	}
	// Set the dispatcher in the dispatcher wrapper for the server to start responding
	// to incoming rpcs.
	d.SetDispatcher(server.NewDispatcher(service))

	if err := service.AddNames(ctx, s); err != nil {
		cancel()
		jutil.JThrowV(env, err)
		return nil
	}
	jNewCtx, err := jcontext.JavaContext(env, ctx, cancel)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	jServer, err := jrpc.JavaServer(env, s)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	// Attach a server to the new context.
	jServerAttCtx, err := jutil.CallStaticObjectMethod(env, jVRuntimeImplClass, "withServer", []jutil.Sign{contextSign, serverSign}, contextSign, jNewCtx, jServer)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	return C.jobject(unsafe.Pointer(jServerAttCtx))
}