Search in sources :

Example 51 with Promise

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

the class DeadLocks method main.

public static void main(String[] arg) {
    SelfDeadLocker dl = Actors.AsActor(SelfDeadLocker.class, 1000);
    Promise end = new Promise();
    dl.deadLock(end, true);
    end.then((r, e) -> {
        System.out.println("control finished: " + dl.getActor().msgcount);
        dl.stop();
    });
    SelfDeadLocker dl1 = Actors.AsActor(SelfDeadLocker.class, 1000);
    Promise end1 = new Promise();
    dl1.deadLock(end1, false);
    end1.then((r, e) -> {
        System.out.println("nocontrol finished: " + dl1.getActor().msgcount);
        dl1.stop();
    });
}
Also used : IPromise(org.nustaq.kontraktor.IPromise) Promise(org.nustaq.kontraktor.Promise)

Example 52 with Promise

use of org.nustaq.kontraktor.Promise 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 53 with Promise

use of org.nustaq.kontraktor.Promise 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 54 with Promise

use of org.nustaq.kontraktor.Promise 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)

Example 55 with Promise

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

the class RemoteRefPolling method scheduleSendLoop.

/**
 * return a future which is completed upon connection close
 *
 * @param reg
 *
 * @return future completed upon termination of scheduling (disconnect)
 */
public IPromise scheduleSendLoop(ConnectionRegistry reg) {
    Promise promise = new Promise();
    sendJobs.add(new ScheduleEntry(reg, promise));
    synchronized (this) {
        if (!loopStarted) {
            loopStarted = true;
            Actor.current().execute(this);
        }
    }
    return promise;
}
Also used : IPromise(org.nustaq.kontraktor.IPromise) Promise(org.nustaq.kontraktor.Promise)

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