Search in sources :

Example 1 with TCPConnectable

use of org.nustaq.kontraktor.remoting.tcp.TCPConnectable in project kontraktor by RuedigerMoeller.

the class ProcessStarter method init.

public void init(ProcessStarterArgs options) {
    this.options = options;
    siblings = new HashMap<>();
    nextSiblings = new HashMap<>();
    id = UUID.randomUUID().toString();
    if (options.getName() == null) {
        try {
            this.name = InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException e) {
            Log.Error(this, e);
            this.name = "unknown";
        }
    } else {
        name = options.getName();
    }
    if (options.getHost() == null) {
        try {
            options.host = InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException e) {
            Log.Error(this, e);
            options.host = "unknown";
        }
    } else {
        name = options.getName();
    }
    final String siblingHost = options.getSiblingHost();
    if (siblingHost != null) {
        final int siblingPort = options.getSiblingPort();
        primarySibling = new TCPConnectable(ProcessStarter.class, siblingHost, siblingPort);
        cycle();
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) TCPConnectable(org.nustaq.kontraktor.remoting.tcp.TCPConnectable)

Example 2 with TCPConnectable

use of org.nustaq.kontraktor.remoting.tcp.TCPConnectable in project kontraktor by RuedigerMoeller.

the class ProcessStarter method main.

public static void main(String[] args) throws InterruptedException, IOException {
    BackOffStrategy.SLEEP_NANOS = 10 * 1000 * 1000;
    final ProcessStarterArgs options = new ProcessStarterArgs();
    final JCommander jCommander = new JCommander(options);
    jCommander.parse(args);
    if (options.isHelp()) {
        jCommander.usage();
        System.exit(0);
    }
    options.underride(locateProps(0, new File("./"), "troll.properties"));
    ProcessStarter ps = Actors.AsActor(ProcessStarter.class);
    ps.init(options);
    new TCPNIOPublisher().port(options.getPort()).facade(ps).publish(act -> {
        System.out.println("Discon " + act);
    }).then((r, e) -> {
        if (e == null) {
            System.out.println("started demon on all nics port " + options.getPort() + " sibling expected on " + options.getSiblingHost() + ":" + options.getSiblingPort());
        } else {
            System.out.println("error connecting " + e);
        }
    });
// testing
// ProcessStarter remote = (ProcessStarter) new TCPConnectable(ProcessStarter.class,options.getHost(),options.getPort()).connect( (x,y) -> System.out.println("client disc "+x)).await();
// ProcessInfo bash = remote.startProcess("/tmp", Collections.emptyMap(), "bash", "-c", "xclock -digital").await();
// 
// List<ProcessInfo> procs = remote.getProcesses().await();
// procs.forEach( proc -> System.out.println(proc));
// 
// Thread.sleep(3000);
// 
// 
// Object await = remote.terminateProcess(bash.getId(), true, 15).await();
// System.out.println("term result "+await);
// http://stackoverflow.com/questions/5740390/printing-my-macs-serial-number-in-java-using-unix-commands/5740673#5740673
// http://stackoverflow.com/questions/1980671/executing-untokenized-command-line-from-java/1980921#1980921
}
Also used : TCPConnectable(org.nustaq.kontraktor.remoting.tcp.TCPConnectable) java.util(java.util) BackOffStrategy(org.nustaq.kontraktor.impl.BackOffStrategy) JCommander(com.beust.jcommander.JCommander) Promise(org.nustaq.kontraktor.Promise) Field(java.lang.reflect.Field) UnknownHostException(java.net.UnknownHostException) Collectors(java.util.stream.Collectors) InetAddress(java.net.InetAddress) TimeUnit(java.util.concurrent.TimeUnit) IPromise(org.nustaq.kontraktor.IPromise) java.io(java.io) ConnectableActor(org.nustaq.kontraktor.remoting.base.ConnectableActor) Actor(org.nustaq.kontraktor.Actor) Log(org.nustaq.kontraktor.util.Log) Actors(org.nustaq.kontraktor.Actors) TCPNIOPublisher(org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher) JCommander(com.beust.jcommander.JCommander) TCPNIOPublisher(org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher)

Example 3 with TCPConnectable

use of org.nustaq.kontraktor.remoting.tcp.TCPConnectable in project kontraktor by RuedigerMoeller.

the class ProcessStarter method initPrimary.

void initPrimary() {
    try {
        ProcessStarter sibling = (ProcessStarter) primarySibling.connect((x, y) -> System.out.println("client disc " + x), act -> {
            System.out.println("act " + act);
            // siblings.clear();
            primaryDesc = null;
        }).await();
        primaryDesc = sibling.getInstanceDesc().await();
        siblings.put(primaryDesc.getId(), primaryDesc);
        System.out.println("primary sibling connected " + primaryDesc);
        distribute(SOFT_SYNC, null, null);
    } catch (Throwable e) {
        System.out.println("failed to connect primary " + primarySibling);
        // try another
        if (siblings.size() > 0) {
            Map.Entry<String, StarterDesc> next = siblings.entrySet().iterator().next();
            primarySibling = new TCPConnectable().actorClass(ProcessStarter.class).host(next.getValue().getHost()).port(next.getValue().getPort());
        // siblings.remove(next.getKey());
        }
    }
}
Also used : TCPConnectable(org.nustaq.kontraktor.remoting.tcp.TCPConnectable)

Example 4 with TCPConnectable

use of org.nustaq.kontraktor.remoting.tcp.TCPConnectable in project kontraktor by RuedigerMoeller.

the class HelloClient method main.

public static void main(String[] args) {
    org.nustaq.kontraktor.remoting.base.ConnectableActor[] connectables = { new WebSocketConnectable(HelloActor.class, "http://localhost:8080/hello").serType(SerializerType.FSTSer), new HttpConnectable(HelloActor.class, "http://localhost:8080/hellohttp").serType(SerializerType.JsonNoRefPretty), new TCPConnectable(HelloActor.class, "localhost", 6789) };
    stream(connectables).forEach(connectable -> {
        HelloActor remote = (HelloActor) connectable.connect((res, err) -> System.out.println(connectable + " disconnected !")).await();
        remote.getMyName().then(name -> {
            System.out.println(connectable.getClass().getSimpleName() + " " + name);
        });
    });
}
Also used : HttpConnectable(org.nustaq.kontraktor.remoting.http.HttpConnectable) TCPConnectable(org.nustaq.kontraktor.remoting.tcp.TCPConnectable) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)

Example 5 with TCPConnectable

use of org.nustaq.kontraktor.remoting.tcp.TCPConnectable in project kontraktor by RuedigerMoeller.

the class RemotingPlayground method main.

public static void main(String[] args) {
    AServ server = Actors.AsActor(AServ.class);
    TCPNIOPublisher publisher = new TCPNIOPublisher(server, 5678);
    publisher.publish(actor -> System.out.println("actor " + actor + " disconnected")).await();
    AServ client = (AServ) new TCPConnectable(AServ.class, "localhost", 5678).connect().await();
    client.pingme();
}
Also used : TCPConnectable(org.nustaq.kontraktor.remoting.tcp.TCPConnectable) Actor(org.nustaq.kontraktor.Actor) Actors(org.nustaq.kontraktor.Actors) TCPClientConnector(org.nustaq.kontraktor.remoting.tcp.TCPClientConnector) TCPNIOPublisher(org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher) TCPConnectable(org.nustaq.kontraktor.remoting.tcp.TCPConnectable) TCPNIOPublisher(org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher)

Aggregations

TCPConnectable (org.nustaq.kontraktor.remoting.tcp.TCPConnectable)25 Test (org.junit.Test)9 TCPNIOPublisher (org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 Actors (org.nustaq.kontraktor.Actors)5 Promise (org.nustaq.kontraktor.Promise)4 TCPPublisher (org.nustaq.kontraktor.remoting.tcp.TCPPublisher)4 RateMeasure (org.nustaq.kontraktor.util.RateMeasure)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 WebSocketConnectable (org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)3 JCommander (com.beust.jcommander.JCommander)2 UnknownHostException (java.net.UnknownHostException)2 Date (java.util.Date)2 TimeUnit (java.util.concurrent.TimeUnit)2 Actor (org.nustaq.kontraktor.Actor)2 IPromise (org.nustaq.kontraktor.IPromise)2 KxPublisher (org.nustaq.kontraktor.reactivestreams.KxPublisher)2 KxReactiveStreams (org.nustaq.kontraktor.reactivestreams.KxReactiveStreams)2 HttpConnectable (org.nustaq.kontraktor.remoting.http.HttpConnectable)2 WebSocketPublisher (org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher)2