Search in sources :

Example 41 with IPromise

use of org.nustaq.kontraktor.IPromise in project kontraktor by RuedigerMoeller.

the class TCPConnectable method connect.

@Override
public <T extends Actor> IPromise<T> connect(Callback<ActorClientConnector> disconnectCallback, Consumer<Actor> actorDisconnecCB) {
    Promise result = new Promise();
    Runnable connect = () -> {
        TCPClientConnector client = new TCPClientConnector(port, host, disconnectCallback);
        ActorClient connector = new ActorClient(client, actorClz, coding);
        connector.connect(inboundQueueSize, actorDisconnecCB).then(result);
    };
    if (!Actor.inside()) {
        TCPClientConnector.get().execute(() -> Thread.currentThread().setName("tcp singleton remote client actor polling"));
        TCPClientConnector.get().execute(connect);
    } else
        connect.run();
    return result;
}
Also used : IPromise(org.nustaq.kontraktor.IPromise) Promise(org.nustaq.kontraktor.Promise) ActorClient(org.nustaq.kontraktor.remoting.base.ActorClient)

Example 42 with IPromise

use of org.nustaq.kontraktor.IPromise in project kontraktor by RuedigerMoeller.

the class HttpMonitor method getMonitorableKeys.

public IPromise<String[]> getMonitorableKeys(String simpleClzName) {
    ArrayList<String> result = new ArrayList();
    monitored.entrySet().forEach((entry) -> {
        Monitorable mon = entry.getValue();
        if (mon instanceof Actor)
            mon = ((Actor) mon).getActor();
        if (entry.getValue() != null && mon.getClass().getSimpleName().equals(simpleClzName)) {
            result.add(entry.getKey());
        }
    });
    String[] res = new String[result.size()];
    result.toArray(res);
    return new Promise(res);
}
Also used : Monitorable(org.nustaq.kontraktor.monitoring.Monitorable) IPromise(org.nustaq.kontraktor.IPromise) Promise(org.nustaq.kontraktor.Promise) Actor(org.nustaq.kontraktor.Actor) ArrayList(java.util.ArrayList)

Example 43 with IPromise

use of org.nustaq.kontraktor.IPromise in project kontraktor by RuedigerMoeller.

the class AsyncSocketConnection method directWrite.

protected IPromise directWrite(ByteBuffer buf) {
    checkThread();
    if (myActor == null)
        myActor = Actor.current();
    if (writePromise != null)
        throw new RuntimeException("concurrent write con:" + chan.isConnected() + " open:" + chan.isOpen());
    writePromise = new Promise();
    writingBuffer = buf;
    Promise res = writePromise;
    try {
        int written = 0;
        written = chan.write(buf);
        if (written < 0) {
            // TODO:closed
            writeFinished(new IOException("connection closed"));
        }
        if (buf.remaining() > 0) {
        // key.interestOps(SelectionKey.OP_WRITE);
        } else {
            writeFinished(null);
        }
    } catch (Exception e) {
        res.reject(e);
        FSTUtil.rethrow(e);
    }
    return res;
}
Also used : IPromise(org.nustaq.kontraktor.IPromise) Promise(org.nustaq.kontraktor.Promise) IOException(java.io.IOException) IOException(java.io.IOException) EOFException(java.io.EOFException)

Example 44 with IPromise

use of org.nustaq.kontraktor.IPromise in project kontraktor by RuedigerMoeller.

the class QueuingAsyncSocketConnection method tryFlush.

public void tryFlush() {
    checkThread();
    if (canWrite()) {
        qWriteTmp.position(0);
        qWriteTmp.limit(qWriteTmp.capacity());
        tmp.setBuffer(qWriteTmp);
        long poll = writeQueue.poll(tmp, 0, tmp.length());
        // System.out.println("try write "+poll+" avail:"+writeQueue.available()+" cap:"+writeQueue.capacity());
        if (poll > 0) {
            qWriteTmp.limit((int) poll);
            IPromise queueDataAvailablePromise = directWrite(qWriteTmp);
            queueDataAvailablePromise.then((res, err) -> {
                if (err != null) {
                    if (err instanceof Throwable) {
                        Log.Lg.error(this, (Throwable) err, "write failure");
                        closed((Throwable) err);
                    } else {
                        Log.Lg.error(this, null, "write failure:" + err);
                        closed(new IOException("" + err));
                    }
                } else {
                    tryFlush();
                }
            });
        }
    }
}
Also used : IPromise(org.nustaq.kontraktor.IPromise) IOException(java.io.IOException)

Example 45 with IPromise

use of org.nustaq.kontraktor.IPromise in project kontraktor by RuedigerMoeller.

the class PlainService method initPlainService.

public IPromise<PlainService> initPlainService(String name, String[] requiredServices, ServiceArgs options) {
    if (requiredServices == null) {
        this.requiredServices = new String[0];
    } else {
        this.requiredServices = requiredServices;
    }
    this.serviceName = name;
    Promise p = new Promise();
    self().init(new TCPConnectable(ServiceRegistry.class, options.getRegistryHost(), options.getRegistryPort()), options, true).then((r, e) -> {
        if (e == null) {
            p.resolve(self());
        } else {
            p.reject(e);
        }
    });
    return p;
}
Also used : IPromise(org.nustaq.kontraktor.IPromise) Promise(org.nustaq.kontraktor.Promise) TCPConnectable(org.nustaq.kontraktor.remoting.tcp.TCPConnectable)

Aggregations

IPromise (org.nustaq.kontraktor.IPromise)58 Promise (org.nustaq.kontraktor.Promise)56 Remoted (org.nustaq.kontraktor.annotations.Remoted)6 Actor (org.nustaq.kontraktor.Actor)5 JsonObject (com.eclipsesource.json.JsonObject)4 IOException (java.io.IOException)4 Test (org.junit.Test)4 ByteBuffer (java.nio.ByteBuffer)3 KeyManagementException (java.security.KeyManagementException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 CertificateException (java.security.cert.CertificateException)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Consumer (java.util.function.Consumer)3 TableSpaceActor (org.nustaq.reallive.impl.tablespace.TableSpaceActor)3 JsonValue (com.eclipsesource.json.JsonValue)2 ArrayList (java.util.ArrayList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ArchiveException (org.apache.commons.compress.archivers.ArchiveException)2 HttpPost (org.apache.http.client.methods.HttpPost)2 StringEntity (org.apache.http.entity.StringEntity)2