Created
January 29, 2021 17:05
-
-
Save otrack/077394001cc74e32410b3bf75e9479e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.crucial.dso; | |
import picocli.CommandLine.Command; | |
import picocli.CommandLine.Option; | |
@Command(name = "pipe") | |
public class Pipe { | |
@Option(names = "-n" ) | |
public String name = "pipe"; | |
private AtomicCounter counter; | |
private AtomicReference<String> ipport; | |
private static final int BARRIER = 2; | |
public Pipe() {} | |
public Pipe(String name) { | |
this.name = name; | |
this.counter = new AtomicCounter("counter-"+name); | |
this.ipport = new AtomicReference("ref-"+name); | |
} | |
public int wait() | |
{ | |
int ret = counter.increment(); | |
while(ret < BARRIER) { | |
try { | |
Thread.currentThread().sleep(500); | |
} catch (InterruptedException e) { | |
// ignore | |
} | |
} | |
return 0; | |
} | |
@Override | |
@Command(name = "begin") | |
public String begin() { | |
String ret = this.ipport.get(); | |
this.wait(); | |
} | |
@Override | |
@Command(name = "end") | |
public void end(@Option(names = "-1") String ipport) { | |
this.ipport.set(ipport); | |
this.wait(); | |
} | |
@Override | |
@Command(name = "getName") | |
public String getName() { | |
return this.name; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment