Search in sources :

Example 61 with Promise

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;
}
Also used : IPromise(org.nustaq.kontraktor.IPromise) Promise(org.nustaq.kontraktor.Promise) ActorClient(org.nustaq.kontraktor.remoting.base.ActorClient)

Example 62 with Promise

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);
}
Also used : Promise(org.nustaq.kontraktor.Promise) IPromise(org.nustaq.kontraktor.IPromise) ActorServer(org.nustaq.kontraktor.remoting.base.ActorServer) Coding(org.nustaq.kontraktor.remoting.encoding.Coding) PathHandler(io.undertow.server.handlers.PathHandler) Undertow(io.undertow.Undertow)

Example 63 with Promise

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;
}
Also used : Promise(org.nustaq.kontraktor.Promise) IPromise(org.nustaq.kontraktor.IPromise) JsonObject(com.eclipsesource.json.JsonObject)

Example 64 with Promise

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;
}
Also used : Promise(org.nustaq.kontraktor.Promise) IPromise(org.nustaq.kontraktor.IPromise) ArchiveException(org.apache.commons.compress.archivers.ArchiveException)

Example 65 with Promise

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;
}
Also used : Promise(org.nustaq.kontraktor.Promise) IPromise(org.nustaq.kontraktor.IPromise) JsonObject(com.eclipsesource.json.JsonObject)

Aggregations

Promise (org.nustaq.kontraktor.Promise)67 IPromise (org.nustaq.kontraktor.IPromise)62 Test (org.junit.Test)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 Actor (org.nustaq.kontraktor.Actor)6 Remoted (org.nustaq.kontraktor.annotations.Remoted)6 IOException (java.io.IOException)4 Actors (org.nustaq.kontraktor.Actors)4 RateMeasure (org.nustaq.kontraktor.util.RateMeasure)4 JsonObject (com.eclipsesource.json.JsonObject)3 ByteBuffer (java.nio.ByteBuffer)3 KeyManagementException (java.security.KeyManagementException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 CertificateException (java.security.cert.CertificateException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Consumer (java.util.function.Consumer)3 ActorServer (org.nustaq.kontraktor.remoting.base.ActorServer)3 TCPConnectable (org.nustaq.kontraktor.remoting.tcp.TCPConnectable)3 TableSpaceActor (org.nustaq.reallive.impl.tablespace.TableSpaceActor)3 EOFException (java.io.EOFException)2