Skip to content

Commit

Permalink
Q2 registers itself with the NameRegistrar
Browse files Browse the repository at this point in the history
Q2 now registers itself with the NameRegistrar using the default name 'Q2'.

An optional `--name` argument is honoured if present.
  • Loading branch information
ar committed Mar 7, 2016
1 parent 3338f38 commit bc7be43
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions jpos/src/main/java/org/jpos/q2/Q2.java
Expand Up @@ -97,6 +97,7 @@ public class Q2 implements FileFilter, Runnable {
private boolean startOSGI = false;
private BundleContext bundleContext;
private String pidFile;
private String name = JMX_NAME;
private long lastVersionLog;
private String watchServiceClassname;

Expand All @@ -111,6 +112,7 @@ public Q2 (String[] args, BundleContext bundleContext) {
deployDir.mkdirs ();
mainClassLoader = getClass().getClassLoader();
this.bundleContext = bundleContext;
registerQ2();
}
public Q2 () {
this (new String[] {}, null );
Expand Down Expand Up @@ -652,6 +654,7 @@ private void parseCmdLine (String[] args) {
options.addOption ("c","command", true, "Command to execute");
options.addOption ("O", "osgi", false, "Start experimental OSGi framework server");
options.addOption ("p", "pid-file", true, "Store project's pid");
options.addOption ("n", "name", true, "Optional name (default to 'Q2')");

try {
CommandLine line = parser.parse (options, args);
Expand Down Expand Up @@ -683,6 +686,8 @@ private void parseCmdLine (String[] args) {
startOSGI = true;
if (line.hasOption("p"))
pidFile = line.getOptionValue("p");
if (line.hasOption("n"))
name = line.getOptionValue("n");
} catch (MissingArgumentException e) {
System.out.println("ERROR: " + e.getMessage());
System.exit(1);
Expand Down Expand Up @@ -1029,4 +1034,16 @@ private boolean waitForChanges (WatchService service) throws InterruptedExceptio
}
return true;
}

private void registerQ2() {
synchronized (Q2.class) {
for (int i=0; ; i++) {
String key = name + (i > 0 ? "-" + i : "");
if (NameRegistrar.getIfExists(key) == null) {
NameRegistrar.register(key, this);
break;
}
}
}
}
}

0 comments on commit bc7be43

Please sign in to comment.