From 03b3bc157260091f082a85ed33125a2807b3ee36 Mon Sep 17 00:00:00 2001 From: Alejandro Revilla Date: Thu, 3 Oct 2024 16:04:13 -0300 Subject: [PATCH] add eager-start support --- jpos/src/main/java/org/jpos/q2/Q2.java | 23 +++++++++++++++----- jpos/src/main/java/org/jpos/q2/QFactory.java | 23 +++++++++++++++----- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/jpos/src/main/java/org/jpos/q2/Q2.java b/jpos/src/main/java/org/jpos/q2/Q2.java index c8248545e3..35e7f5a52c 100644 --- a/jpos/src/main/java/org/jpos/q2/Q2.java +++ b/jpos/src/main/java/org/jpos/q2/Q2.java @@ -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. @@ -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()); } @@ -1061,6 +1065,7 @@ public static class QEntry { ObjectInstance instance; Object obj; boolean osgiBundle; + boolean eagerStart; public QEntry (boolean osgiBundle) { super(); this.osgiBundle = osgiBundle; @@ -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() { diff --git a/jpos/src/main/java/org/jpos/q2/QFactory.java b/jpos/src/main/java/org/jpos/q2/QFactory.java index 328f332b07..497ef8c40e 100644 --- a/jpos/src/main/java/org/jpos/q2/QFactory.java +++ b/jpos/src/main/java/org/jpos/q2/QFactory.java @@ -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")