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();
}
}
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
}
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());
}
}
}
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);
});
});
}
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();
}
Aggregations