Exemplo n.º 1
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))
}
Exemplo n.º 2
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
}
Exemplo n.º 3
0
func getDuration(env jutil.Env, obj jutil.Object, field string) (*time.Duration, error) {
	jDuration, err := jutil.JObjectField(env, obj, field, jutil.DurationSign)
	if err != nil {
		return nil, err
	}

	if !jDuration.IsNull() {
		duration, err := jutil.GoDuration(env, jDuration)
		if err != nil {
			return nil, err
		}
		return &duration, nil
	}
	return nil, nil
}
Exemplo n.º 4
0
//export Java_io_v_v23_context_VContext_nativeWithTimeout
func Java_io_v_v23_context_VContext_nativeWithTimeout(jenv *C.JNIEnv, jVContext C.jobject, goRef C.jlong, jTimeout C.jobject) C.jobject {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	timeout, err := jutil.GoDuration(env, jutil.Object(uintptr(unsafe.Pointer(jTimeout))))
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	ctx, cancelFunc := context.WithTimeout((*context.T)(jutil.GoRefValue(jutil.Ref(goRef))), timeout)
	jCtx, err := JavaContext(env, ctx, cancelFunc)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	return C.jobject(unsafe.Pointer(jCtx))
}