public static Optional < CuratorFramework > getCuratorForLocation ( URI location ) { final String defaultConnectionString ; final String namespace ; if ( getLocationType ( location ) != LocationType . EMO_HOST_DISCOVERY ) { // Only host discovery may require ZooKeeper return Optional . absent ( ) ; } if ( getHostOverride ( location ) . isPresent ( ) ) { // Fixed host discovery doesn't require ZooKeeper return Optional . absent ( ) ; } Matcher matcher = getLocatorMatcher ( location ) ; checkArgument ( matcher . matches ( ) , "Invalid location: %s" , location ) ; if ( matcher . group ( "universe" ) != null ) { // Normal host discovery String universe = matcher . group ( "universe" ) ; Region region = getRegion ( Objects . firstNonNull ( matcher . group ( "region" ) , DEFAULT_REGION ) ) ; namespace = format ( "%s/%s" , universe , region ) ; defaultConnectionString = DEFAULT_ZK_CONNECTION_STRING ; } else { // Local host discovery; typically for developer testing namespace = null ; defaultConnectionString = DEFAULT_LOCAL_ZK_CONNECTION_STRING ; } String connectionString = getZkConnectionStringOverride ( location ) . or ( defaultConnectionString ) ; CuratorFramework curator = CuratorFrameworkFactory . builder ( ) . ensembleProvider ( new ResolvingEnsembleProvider ( connectionString ) ) . retryPolicy ( new BoundedExponentialBackoffRetry ( 100 , 1000 , 10 ) ) . threadFactory ( new ThreadFactoryBuilder ( ) . setNameFormat ( "emo-zookeeper-%d" ) . build ( ) ) . namespace ( namespace ) . build ( ) ; curator . start ( ) ; return Optional . of ( curator ) ; }
Returns a configured started Curator for a given location or absent if the location does not use host discovery .