use of com.bluenimble.platform.api.ApiSpace in project serverless by bluenimble.
the class SmtpMessengerPlugin method init.
@Override
public void init(final ApiServer server) throws Exception {
Feature aFeature = Messenger.class.getAnnotation(Feature.class);
if (aFeature == null || Lang.isNullOrEmpty(aFeature.name())) {
return;
}
feature = aFeature.name();
server.addFeature(new ServerFeature() {
private static final long serialVersionUID = 3585173809402444745L;
@Override
public Class<?> type() {
return Messenger.class;
}
@Override
public Object get(ApiSpace space, String name) {
return ((RecyclableMessenger) (space.getRecyclable(createKey(name)))).messenger();
}
@Override
public String provider() {
return SmtpMessengerPlugin.this.getName();
}
@Override
public Plugin implementor() {
return SmtpMessengerPlugin.this;
}
});
}
use of com.bluenimble.platform.api.ApiSpace in project serverless by bluenimble.
the class FileSystemStoragePlugin method init.
@Override
public void init(final ApiServer server) throws Exception {
Feature aFeature = Storage.class.getAnnotation(Feature.class);
if (aFeature == null || Lang.isNullOrEmpty(aFeature.name())) {
return;
}
feature = aFeature.name();
if (!Lang.isNullOrEmpty(root)) {
fRoot = new File(root);
}
if (!fRoot.exists()) {
fRoot.mkdirs();
}
server.addFeature(new ServerFeature() {
private static final long serialVersionUID = -9012279234275100528L;
@Override
public Class<?> type() {
return Storage.class;
}
@Override
public Object get(ApiSpace space, String name) {
String mount = mounts.get(createStorageKey(name, space));
if (mount == null) {
return null;
}
return new FileSystemStorage(mount, new File(fRoot, mount));
}
@Override
public String provider() {
return FileSystemStoragePlugin.this.getName();
}
@Override
public Plugin implementor() {
return FileSystemStoragePlugin.this;
}
});
}
use of com.bluenimble.platform.api.ApiSpace in project serverless by bluenimble.
the class MemCachedPlugin method init.
@Override
public void init(final ApiServer server) throws Exception {
Feature aFeature = Cache.class.getAnnotation(Feature.class);
if (aFeature == null || Lang.isNullOrEmpty(aFeature.name())) {
return;
}
feature = aFeature.name();
server.addFeature(new ServerFeature() {
private static final long serialVersionUID = 3585173809402444745L;
@Override
public Class<?> type() {
return Cache.class;
}
@Override
public Object get(ApiSpace space, String name) {
return new MemCachedCache(((RecyclableCacheClient) (space.getRecyclable(createKey(name)))).client());
}
@Override
public String provider() {
return MemCachedPlugin.this.getName();
}
@Override
public Plugin implementor() {
return MemCachedPlugin.this;
}
});
}
use of com.bluenimble.platform.api.ApiSpace in project serverless by bluenimble.
the class MongoDatabasePlugin method init.
// private int weight;
@Override
public void init(final ApiServer server) throws Exception {
// weight = server.weight ();
Feature aFeature = Database.class.getAnnotation(Feature.class);
if (aFeature == null || Lang.isNullOrEmpty(aFeature.name())) {
return;
}
feature = aFeature.name();
// add features
server.addFeature(new ServerFeature() {
private static final long serialVersionUID = 2626039344401539390L;
@Override
public Class<?> type() {
return Database.class;
}
@Override
public Object get(ApiSpace space, String name) {
return new MongoDatabaseImpl(MongoDatabasePlugin.this.acquire(space, name), tracer());
}
@Override
public Plugin implementor() {
return MongoDatabasePlugin.this;
}
@Override
public String provider() {
return MongoDatabasePlugin.this.getName();
}
});
codecRegistry = CodecRegistries.fromRegistries(MongoClient.getDefaultCodecRegistry(), CodecRegistries.fromProviders(PojoCodecProvider.builder().automatic(true).build()));
}
use of com.bluenimble.platform.api.ApiSpace in project serverless by bluenimble.
the class MongoDatabasePlugin method onEvent.
@Override
public void onEvent(Event event, Object target) throws PluginRegistryException {
if (!ApiSpace.class.isAssignableFrom(target.getClass())) {
return;
}
tracer().log(Tracer.Level.Info, "onEvent {0}, target {1}", event, target.getClass().getSimpleName());
ApiSpace space = (ApiSpace) target;
switch(event) {
case Create:
createClients(space);
break;
case AddFeature:
// if it's database and provider is 'mongodb' create clients
createClients(space);
break;
case DeleteFeature:
// if it's database and provider is 'mongodb' stop factory
dropClients(space);
break;
default:
break;
}
}
Aggregations