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 4813afa commit 8b09f4f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
17 changes: 16 additions & 1 deletion jpos/src/main/java/org/jpos/log/evt/Deploy.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.jpos.log.evt;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import org.jpos.log.AuditLogEvent;

Expand All @@ -28,6 +29,20 @@
*
* @param path the path where the deployment is located
* @param enabled a boolean flag indicating whether the deployment is enabled
* @param eager a boolean flag indicating whether the QBean requires eager-start
*/

public record Deploy(String path, @JacksonXmlProperty(isAttribute = true) boolean enabled) implements AuditLogEvent { }
public record Deploy(
String path,
@JacksonXmlProperty(isAttribute = true) boolean enabled,
@JacksonXmlProperty(isAttribute = true) @JsonInclude(JsonInclude.Include.NON_DEFAULT) boolean eager
) implements AuditLogEvent {
@Override
public String toString() {
return "Deploy{" +
"path='" + path + '\'' +
", enabled=" + enabled +
(eager ? ", eager=" + eager : "")+
'}';
}
}
20 changes: 17 additions & 3 deletions jpos/src/main/java/org/jpos/q2/Q2.java
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,12 @@ private void deploy () {
long deployed = qentry.getDeployed ();
if (deployed == 0) {
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 @@ -587,8 +591,9 @@ private boolean deploy (File f) {
}
}
enabled = QFactory.isEnabled(rootElement);
qentry.setEagerStart(QFactory.isEagerStart(rootElement));
if (evt != null)
evt.addMessage(new Deploy(f.getCanonicalPath(), enabled));
evt.addMessage(new Deploy(f.getCanonicalPath(), enabled, qentry.isEagerStart()));
if (enabled) {
Object obj = factory.instantiate (this, factory.expandEnvProperties(rootElement));
qentry.setObject (obj);
Expand Down Expand Up @@ -1043,6 +1048,7 @@ public static class QEntry {
long deployed;
ObjectInstance instance;
Object obj;
boolean eagerStart;
public QEntry () {
super();
}
Expand Down Expand Up @@ -1078,6 +1084,14 @@ public boolean isQBean () {
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
24 changes: 17 additions & 7 deletions jpos/src/main/java/org/jpos/q2/QFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -432,16 +432,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 8b09f4f

Please sign in to comment.