Skip to content

Commit

Permalink
add eager-start support
Browse files Browse the repository at this point in the history
  • Loading branch information
ar committed Oct 3, 2024
1 parent 5365f22 commit 03b3bc1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
23 changes: 18 additions & 5 deletions jpos/src/main/java/org/jpos/q2/Q2.java
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,12 @@ private void deploy () {
qentry.setDeployed (f.lastModified ());
}
else if (deploy(f)) {
if (qentry.isQBean ())
startList.add (qentry.getInstance());
if (qentry.isQBean ()) {
if (qentry.isEagerStart())
start(qentry.getInstance());
else
startList.add(qentry.getInstance());
}
qentry.setDeployed (f.lastModified ());
} else {
// deploy failed, clean up.
Expand Down Expand Up @@ -580,15 +584,15 @@ private boolean deploy (File f) {
}
}
if (QFactory.isEnabled(rootElement)) {
if (evt != null)
evt.addMessage("deploy: " + f.getCanonicalPath());
Object obj = factory.instantiate (this, rootElement);
qentry.setObject (obj);

qentry.setEagerStart(QFactory.isEagerStart(rootElement));
ObjectInstance instance = factory.createQBean (
this, doc.getRootElement(), obj
);
qentry.setInstance (instance);
if (evt != null)
evt.addMessage("deploy: " + f.getCanonicalPath() + (qentry.isEagerStart() ? " (eager-start)" : ""));
} else if (evt != null) {
evt.addMessage("deploy ignored (enabled='" + QFactory.getEnabledAttribute(rootElement) + "'): " + f.getCanonicalPath());
}
Expand Down Expand Up @@ -1061,6 +1065,7 @@ public static class QEntry {
ObjectInstance instance;
Object obj;
boolean osgiBundle;
boolean eagerStart;
public QEntry (boolean osgiBundle) {
super();
this.osgiBundle = osgiBundle;
Expand Down Expand Up @@ -1100,6 +1105,14 @@ public boolean isOSGIBundle() {
public boolean isQPersist () {
return obj instanceof QPersist;
}

public boolean isEagerStart() {
return eagerStart;
}

public void setEagerStart(boolean eagerStart) {
this.eagerStart = eagerStart;
}
}

private void writePidFile() {
Expand Down
23 changes: 17 additions & 6 deletions jpos/src/main/java/org/jpos/q2/QFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -431,15 +431,26 @@ public static void invoke (Object obj, String m, Object p, Class pc)
}
}

public static boolean isEnabled (Element e) {
String enabledAttribute = getEnabledAttribute(e);
return "true".equalsIgnoreCase(enabledAttribute) ||
"yes".equalsIgnoreCase(enabledAttribute) ||
enabledAttribute.contains(Environment.getEnvironment().getName());
public static boolean isEnabled(Element e) {
return isTrue(getEnabledAttribute(e));
}
public static boolean isEagerStart(Element e) {
return isTrue(getEagerStartAttribute(e));
}
private static boolean isTrue(String attribute) {
return "true".equalsIgnoreCase(attribute) ||
"yes".equalsIgnoreCase(attribute) ||
attribute.contains(Environment.getEnvironment().getName());
}

public static String getEnabledAttribute (Element e) {
return Environment.get(e.getAttributeValue("enabled", "true"));
return getAttribute(e, "enabled", "true");
}
public static String getEagerStartAttribute (Element e) {
return getAttribute(e, "eager-start", "false");
}
private static String getAttribute (Element e, String attr, String def) {
return Environment.get(e.getAttributeValue(attr, def));
}

@SuppressWarnings("rawtypes")
Expand Down

0 comments on commit 03b3bc1

Please sign in to comment.