Search in sources :

Example 1 with FeatureNotFoundException

use of com.bluenimble.platform.server.FeatureNotFoundException in project serverless by bluenimble.

the class AbstractApiServer method getFeature.

@Override
public Object getFeature(ApiSpace space, Class<?> type, String name) {
    Feature aFeature = type.getAnnotation(Feature.class);
    JsonObject oFeature = Json.getObject(space.getFeatures(), aFeature.name());
    if (oFeature == null || oFeature.isEmpty()) {
        throw new FeatureNotFoundException("feature " + aFeature.name() + " not available in space " + space.getNamespace());
    }
    JsonObject oProvider = Json.getObject(oFeature, name);
    if (oProvider == null || oProvider.isEmpty()) {
        throw new FeatureNotFoundException("feature provider " + name + " not available in space " + space.getNamespace());
    }
    String provider = Json.getString(oProvider, ApiSpace.Features.Provider);
    if (Lang.isNullOrEmpty(provider)) {
        throw new FeatureNotFoundException("provider for feature " + aFeature.name() + Lang.SLASH + name + " is missing");
    }
    ServerFeature feature = features.get(aFeature.name() + FeatureProtocol + provider);
    if (feature == null) {
        throw new FeatureNotFoundException("feature " + name + Lang.COLON + aFeature.name() + FeatureProtocol + provider + " not found");
    }
    return feature.get(space, name);
}
Also used : ServerFeature(com.bluenimble.platform.server.ServerFeature) JsonObject(com.bluenimble.platform.json.JsonObject) ServerFeature(com.bluenimble.platform.server.ServerFeature) Feature(com.bluenimble.platform.Feature) FeatureNotFoundException(com.bluenimble.platform.server.FeatureNotFoundException)

Example 2 with FeatureNotFoundException

use of com.bluenimble.platform.server.FeatureNotFoundException in project serverless by bluenimble.

the class ApiSpaceImpl method feature.

@SuppressWarnings("unchecked")
@Override
public <T> T feature(Class<T> t, String name, ApiContext context) {
    if (context == null) {
        throw new FeatureNotFoundException("context not available");
    }
    if (Lang.isNullOrEmpty(name)) {
        throw new FeatureNotFoundException("provider can't be null or empty");
    }
    Feature aFeature = t.getAnnotation(Feature.class);
    if (aFeature == null || Lang.isNullOrEmpty(aFeature.name())) {
        throw new FeatureNotFoundException("feature " + t.getSimpleName() + " not registered in this instance");
    }
    String recyclableKey = contextRecyclableKey(aFeature.name(), name);
    Recyclable feature = context.getRecyclable(recyclableKey);
    if (feature != null) {
        return (T) feature;
    }
    T f = (T) server.getFeature(this, t, name);
    if (f == null) {
        throw new FeatureNotFoundException("feature " + name + " not found");
    }
    if (Recyclable.class.isAssignableFrom(f.getClass())) {
        context.addRecyclable(recyclableKey, (Recyclable) f);
    }
    return f;
}
Also used : Recyclable(com.bluenimble.platform.Recyclable) FeatureNotFoundException(com.bluenimble.platform.server.FeatureNotFoundException) Feature(com.bluenimble.platform.Feature)

Example 3 with FeatureNotFoundException

use of com.bluenimble.platform.server.FeatureNotFoundException in project serverless by bluenimble.

the class AbstractApiServer method addFeature.

@Override
public void addFeature(ServerFeature feature) {
    Feature aFeature = feature.type().getAnnotation(Feature.class);
    if (aFeature == null || Lang.isNullOrEmpty(aFeature.name())) {
        throw new FeatureNotFoundException("feature " + feature.type().getSimpleName() + " not registered in this instance");
    }
    features.put(aFeature.name() + FeatureProtocol + feature.provider(), feature);
}
Also used : ServerFeature(com.bluenimble.platform.server.ServerFeature) Feature(com.bluenimble.platform.Feature) FeatureNotFoundException(com.bluenimble.platform.server.FeatureNotFoundException)

Aggregations

Feature (com.bluenimble.platform.Feature)3 FeatureNotFoundException (com.bluenimble.platform.server.FeatureNotFoundException)3 ServerFeature (com.bluenimble.platform.server.ServerFeature)2 Recyclable (com.bluenimble.platform.Recyclable)1 JsonObject (com.bluenimble.platform.json.JsonObject)1