Example #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))
}
Example #2
0
func newDiscovery(ctx *context.T, connectionUrl string) (discovery.T, error) {
	u, err := url.ParseRequestURI(connectionUrl)
	if err != nil {
		return nil, err
	}

	q := u.Query()
	if _, ok := q[QueryGlobal]; ok {
		mountTTL, err := parseDuration(q.Get(QueryMountTTL))
		if err != nil {
			return nil, err
		}
		scanInterval, err := parseDuration(q.Get(QueryScanInterval))
		if err != nil {
			return nil, err
		}
		return global.NewWithTTL(ctx, q.Get(QueryGlobal), mountTTL, scanInterval)
	}
	return v23.NewDiscovery(ctx)
}