use of in.erail.glue.annotation.StartService in project api-framework by vinscom.
the class RateLimiterProcessor method start.
@StartService
public void start() {
for (BridgeEventType type : BridgeEventType.values()) {
Cache<String, Bucket> cache = CacheBuilder.newBuilder().recordStats().expireAfterAccess(getExpireAfterAccess(), TimeUnit.SECONDS).maximumSize(getMaximumSize()).build();
getCache().put(type, cache);
}
}
use of in.erail.glue.annotation.StartService in project api-framework by vinscom.
the class VerticalDeployer method start.
@StartService
public void start() {
// Deploy using name
Arrays.stream(getVerticalNames()).forEach((path) -> {
JsonObject deployMsg = new JsonObject();
deployMsg.put("name", path);
getVertx().getDelegate().deployVerticle(path, getDeploymentOptions(), (result) -> {
if (result.succeeded()) {
String deploymentId = result.result();
deployMsg.put("deploymentId", deploymentId);
deployMsg.put("success", true);
getVertx().eventBus().publish(getDeployStatusTopicName(), deployMsg);
getLog().info(() -> "Deployed:" + path + ":" + deploymentId);
} else {
deployMsg.put("success", false);
getVertx().eventBus().publish(getDeployStatusTopicName(), deployMsg);
getLog().error("Vertical Deployment failed", result.cause());
}
});
});
// Deploy using Java class instance
getVerticalInstances().getServices().stream().forEach((vertical) -> {
JsonObject deployMsg = new JsonObject();
deployMsg.put("name", vertical.getClass().getCanonicalName());
getVertx().getDelegate().deployVerticle((Verticle) vertical, getDeploymentOptions(), (result) -> {
if (result.succeeded()) {
String deploymentId = result.result();
deployMsg.put("deploymentId", deploymentId);
deployMsg.put("success", true);
getVertx().eventBus().publish(getDeployStatusTopicName(), deployMsg);
getLog().info(() -> "Deployed:" + vertical.getClass().getCanonicalName() + ":" + deploymentId);
} else {
deployMsg.put("success", false);
getVertx().eventBus().publish(getDeployStatusTopicName(), deployMsg);
getLog().error("Vertical Deployment failed", result.cause());
}
});
});
}
use of in.erail.glue.annotation.StartService in project api-framework by vinscom.
the class SecurityTools method startup.
@SuppressWarnings("unchecked")
@StartService
public void startup() {
setRandom(new SecureRandom());
if (!getVertx().isClustered()) {
mGlobalUniqueString.complete("A" + mRandom.nextInt());
return;
}
Map<String, Object> cryptCtx = new HashMap<>();
Single<Lock> lock = getVertx().sharedData().rxGetLockWithTimeout("_in.erail.security", 5000);
getVertx().sharedData().<String, byte[]>rxGetClusterWideMap("_in.erail.security").flatMap((m) -> {
cryptCtx.put("map", m);
return m.rxGet("key");
}).map((k) -> {
cryptCtx.put("key", k);
return cryptCtx;
}).flatMap((ctx) -> {
if (ctx.get("key") == null) {
return lock.map((l) -> {
ctx.put("lock", l);
return ctx;
});
}
return Single.just(ctx);
}).flatMap(ctx -> {
if (ctx.get("lock") != null) {
return ((AsyncMap<String, Object>) (ctx.get("map"))).rxGet("key").map((k) -> {
ctx.put("key", k);
return ctx;
});
}
return Single.just(ctx);
}).flatMap((ctx) -> {
if (ctx.get("key") == null) {
KeyGenerator keygen = KeyGenerator.getInstance("AES");
keygen.init(128);
byte[] key = keygen.generateKey().getEncoded();
return ((AsyncMap<String, Object>) (ctx.get("map"))).rxPut("key", key).doOnComplete(() -> ctx.put("key", key)).toSingleDefault(ctx);
}
return Single.just(ctx);
}).map(ctx -> (byte[]) ctx.get("key")).doFinally(() -> {
if (cryptCtx.containsKey("lock")) {
Lock l = (Lock) cryptCtx.get("lock");
l.release();
}
}).subscribe((key) -> {
mKeySpec.complete(new SecretKeySpec(key, "AES"));
String unique = Base64.getEncoder().encodeToString(Arrays.copyOfRange(key, 0, 5));
mGlobalUniqueString.complete(unique.replace("=", ""));
getLog().info(() -> String.format("GlobalUniqueString:[%s]", unique));
});
}
use of in.erail.glue.annotation.StartService in project api-framework by vinscom.
the class Server method start.
@StartService
public void start() {
HttpServer server = getVertx().createHttpServer(new HttpServerOptions().setPort(getPort()).setHost(getHost()));
Router router = Router.router(getVertx());
// Logging
if (getLog().isDebugEnabled()) {
router.route("/*").handler(LoggerHandler.create());
}
if (getSockJSHandler() != null) {
router.route("/eventbus/*").handler(getSockJSHandler());
}
for (int i = 0; i < mMountPath.length; i++) {
router.mountSubRouter(mMountPath[i], mRouter[i]);
}
server.requestHandler(router::accept).rxListen().blockingGet();
getLog().debug(() -> String.format("---------------Server[%s:%s] is ready-----------------", getHost(), getPort()));
}
use of in.erail.glue.annotation.StartService in project api-framework by vinscom.
the class LoadMongoDataService method start.
@StartService
public void start() {
if (!isEnable()) {
return;
}
Set<String> collections = mData.fieldNames();
for (String collection : collections) {
mMongoClient.rxDropCollection(collection).andThen(mMongoClient.rxCreateCollection(collection)).blockingAwait();
JsonArray data = mData.getJsonArray(collection);
Observable.fromIterable(data).map(m -> (JsonObject) m).doOnNext((t) -> {
mMongoClient.rxSave(collection, t).blockingGet();
}).blockingSubscribe();
}
}
Aggregations