Search in sources :

Example 1 with FeatureProvider

use of org.apache.bookkeeper.feature.FeatureProvider in project distributedlog by twitter.

the class DistributedLogNamespaceBuilder method build.

/**
     * Build the namespace.
     *
     * @return the namespace instance.
     * @throws IllegalArgumentException when there is illegal argument provided in the builder
     * @throws NullPointerException when there is null argument provided in the builder
     * @throws IOException when fail to build the backend
     */
public DistributedLogNamespace build() throws IllegalArgumentException, NullPointerException, IOException {
    // Check arguments
    Preconditions.checkNotNull(_conf, "No DistributedLog Configuration.");
    Preconditions.checkNotNull(_uri, "No DistributedLog URI");
    // Validate the uri and load the backend according to scheme
    String scheme = _uri.getScheme();
    Preconditions.checkNotNull(scheme, "Invalid DistributedLog URI : " + _uri);
    String[] schemeParts = StringUtils.split(scheme, '-');
    Preconditions.checkArgument(schemeParts.length > 0, "Invalid distributedlog scheme found : " + _uri);
    Preconditions.checkArgument(Objects.equal(DistributedLogConstants.SCHEME_PREFIX, schemeParts[0].toLowerCase()), "Unknown distributedlog scheme found : " + _uri);
    //       if we are going to support other backends : e.g. 'distributedlog-mem:'.
    if (schemeParts.length > 1) {
        String backendProvider = schemeParts[1];
        Preconditions.checkArgument(Objects.equal(DistributedLogConstants.BACKEND_BK, backendProvider.toLowerCase()), "Backend '" + backendProvider + "' is not supported yet.");
    }
    // Built the feature provider
    FeatureProvider featureProvider;
    if (null == _featureProvider) {
        featureProvider = new SettableFeatureProvider("", 0);
        logger.info("No feature provider is set. All features are disabled now.");
    } else {
        featureProvider = _featureProvider;
    }
    URI bkUri;
    try {
        bkUri = new URI(// remove backend info from bookkeeper backend
        schemeParts[0], _uri.getAuthority(), _uri.getPath(), _uri.getQuery(), _uri.getFragment());
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("Invalid distributedlog uri found : " + _uri, e);
    }
    return BKDistributedLogNamespace.newBuilder().conf(_conf).uri(bkUri).statsLogger(_statsLogger).featureProvider(featureProvider).clientId(_clientId).regionId(_regionId).build();
}
Also used : FeatureProvider(org.apache.bookkeeper.feature.FeatureProvider) SettableFeatureProvider(org.apache.bookkeeper.feature.SettableFeatureProvider) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) SettableFeatureProvider(org.apache.bookkeeper.feature.SettableFeatureProvider)

Aggregations

URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 FeatureProvider (org.apache.bookkeeper.feature.FeatureProvider)1 SettableFeatureProvider (org.apache.bookkeeper.feature.SettableFeatureProvider)1