use of org.nustaq.kontraktor.Promise in project kontraktor by RuedigerMoeller.
the class HttpConnectable method connect.
@Override
public <T extends Actor> IPromise<T> connect(Callback<ActorClientConnector> disconnectCallback, Consumer<Actor> actorDisconnecCB) {
HttpClientConnector con = new HttpClientConnector(this);
con.disconnectCallback = disconnectCallback;
ActorClient actorClient = new ActorClient(con, actorClz, coding);
Promise p = new Promise();
con.getRefPollActor().execute(() -> {
Thread.currentThread().setName("Http Ref Polling");
actorClient.connect(inboundQueueSize, null).then(p);
});
return p;
}
use of org.nustaq.kontraktor.Promise in project kontraktor by RuedigerMoeller.
the class HttpPublisher method publish.
@Override
public IPromise<ActorServer> publish(Consumer<Actor> disconnectCallback) {
ActorServer actorServer;
try {
Pair<PathHandler, Undertow> serverPair = Http4K.get().getServer(port, hostName);
UndertowHttpServerConnector con = new UndertowHttpServerConnector(facade);
con.setConnectionVerifier(connectionVerifier);
con.setSessionTimeout(sessionTimeout);
actorServer = new ActorServer(con, facade, coding == null ? new Coding(SerializerType.FSTSer) : coding);
con.setActorServer(actorServer);
actorServer.start(disconnectCallback);
serverPair.getFirst().addPrefixPath(urlPath, con);
} catch (Exception e) {
Log.Warn(null, e);
return new Promise<>(null, e);
}
return new Promise<>(actorServer);
}
use of org.nustaq.kontraktor.Promise in project kontraktor by RuedigerMoeller.
the class JNPM method getVersions.
protected IPromise<List<String>> getVersions(String module) {
Promise res = new Promise();
http.getContent(config.getRepo() + "/" + module).then((cont, err) -> {
if (cont != null) {
JsonObject parse = Json.parse(cont).asObject().get("versions").asObject();
List<String> versions = new ArrayList<>();
parse.forEach(mem -> versions.add(mem.getName()));
res.resolve(versions);
} else {
res.reject(err);
}
});
return res;
}
use of org.nustaq.kontraktor.Promise in project kontraktor by RuedigerMoeller.
the class JNPM method downLoadAndInstall.
private IPromise downLoadAndInstall(String tarUrl, String moduleName, String resolvedVersion, File targetDir) {
Promise p = new Promise();
String moduleKey = createModuleKey(moduleName, targetDir);
List<Promise> promlist = packagesUnderway.get(moduleKey);
if (promlist != null) {
if (promlist.size() == 0) {
// timing: has already arrived and proms resolved
p.resolve(true);
} else {
packagesUnderway.get(moduleKey).add(p);
}
return p;
}
Log.Info(this, String.format("installing '%s' in %s.", moduleName + "@" + resolvedVersion, targetDir.getAbsolutePath()));
ArrayList list = new ArrayList();
packagesUnderway.put(moduleKey, list);
list.add(p);
checkThread();
http.getContentBytes(tarUrl).then((resp, err) -> {
execInThreadPool(() -> {
// multithread unpacking (java io blocks, so lets mass multithread)
byte[] b = resp;
try {
b = AsyncHttpActor.unGZip(b, b.length * 10);
File outputDir = new File(targetDir, moduleName);
unTar(new ByteArrayInputStream(b), outputDir);
} catch (IOException e) {
e.printStackTrace();
return false;
} catch (ArchiveException e) {
e.printStackTrace();
return false;
}
return true;
}).then(() -> {
checkThread();
// Log.Info(this,String.format("installed '%s' in %s.", moduleName+"@"+ resolvedVersion, nodeModulesDir.getAbsolutePath()));
packagesUnderway.get(moduleKey).forEach(prom -> prom.resolve(true));
packagesUnderway.get(moduleKey).clear();
});
});
return p;
}
use of org.nustaq.kontraktor.Promise in project kontraktor by RuedigerMoeller.
the class JNPM method getDistributions.
// map of tag => version
protected IPromise<JsonObject> getDistributions(String module) {
Promise res = new Promise();
// http://registry.npmjs.org/-/package/react/dist-tags
http.getContent(config.getRepo() + "/-/package/" + module + "/dist-tags").then((cont, err) -> {
if (cont != null) {
JsonObject parse = Json.parse(cont).asObject();
res.resolve(parse);
} else {
res.reject(err);
}
});
return res;
}
Aggregations