Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 47 additions & 25 deletions jpos/src/main/java/org/jpos/q2/QFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public QFactory (ObjectName loaderName, Q2 q2) {
}

@SuppressWarnings("PMD.EmptyCatchBlock")
public Object instantiate (Q2 server, Element e)
public Object instantiate (Q2 server, Element e)
throws ReflectionException,
MBeanException,
InstanceNotFoundException
Expand All @@ -82,7 +82,7 @@ public Object instantiate (Q2 server, Element e)
return mserver.instantiate (clazz, loaderName);
}

public ObjectInstance createQBean (Q2 server, Element e, Object obj)
public ObjectInstance createQBean (Q2 server, Element e, Object obj)
throws MalformedObjectNameException,
InstanceAlreadyExistsException,
InstanceNotFoundException,
Expand All @@ -102,7 +102,7 @@ public ObjectInstance createQBean (Q2 server, Element e, Object obj)
throw new InstanceAlreadyExistsException (name+" has already been deployed in another file.");
}
ObjectInstance instance = mserver.registerMBean (
obj, objectName
obj, objectName
);
try {
setAttribute (mserver, objectName, "Name", name);
Expand All @@ -115,7 +115,7 @@ public ObjectInstance createQBean (Q2 server, Element e, Object obj)
setAttribute (mserver, objectName, "Server", server);
setAttribute (mserver, objectName, "Persist", e);
configureQBean(mserver,objectName,e);
setConfiguration (obj, e); // handle legacy (QSP v1) Configurables
setConfiguration (obj, e); // handle legacy (QSP v1) Configurables

if (obj instanceof QBean)
mserver.invoke (objectName, "init", null, null);
Expand All @@ -140,8 +140,7 @@ private void getExtraPath (QClassLoader loader, Element e) {
} catch (Throwable t) {
getQ2().getLog().error(t);
}
for (Object o : classpathElement.getChildren("url")) {
Element u = (Element) o;
for (Element u : classpathElement.getChildren("url")) {
try {
loader.addURL(u.getTextTrim());
} catch (MalformedURLException ex) {
Expand All @@ -152,8 +151,8 @@ private void getExtraPath (QClassLoader loader, Element e) {
}

@SuppressWarnings("PMD.EmptyCatchBlock")
public void setAttribute
(MBeanServer server, ObjectName objectName,
public void setAttribute
(MBeanServer server, ObjectName objectName,
String attribute, Object value)
throws InstanceNotFoundException,
MBeanException,
Expand All @@ -170,7 +169,7 @@ objectName, new Attribute (attribute, value)
// okay to fail (produced by some application servers instead of AttributeNotFoundException)
}
}

public void startQBean (Q2 server, ObjectName objectName)
throws InstanceNotFoundException,
MBeanException,
Expand Down Expand Up @@ -231,7 +230,7 @@ public AttributeList getAttributeList(Element e)
* @throws ConfigurationException If an exception is found trying to create the object.
*/
@SuppressWarnings("unchecked")
protected Object getObject(Element childElement)
protected Object getObject(Element childElement)
throws ConfigurationException
{
String type = childElement.getAttributeValue("type","java.lang.String");
Expand All @@ -245,7 +244,7 @@ else if ("boolean".equals (type))
String value = childElement.getText();
value = Environment.getEnvironment().getProperty(value, value);
try {
Class attributeType = Class.forName(type);
Class<?> attributeType = Class.forName(type);
if(Collection.class.isAssignableFrom(attributeType))
return getCollection(attributeType, childElement);
else{
Expand All @@ -256,10 +255,10 @@ else if ("boolean".equals (type))
} catch (Exception e1) {
throw new ConfigurationException(e1);
}

}


/** Creats a collection from a definition element with the format.
* <PRE>
* <{attr|item} type="...">
Expand All @@ -278,8 +277,8 @@ protected Collection getCollection(Class type, Element e)
{
try{
Collection<Object> col = (Collection<Object>) type.newInstance();
for (Object o : e.getChildren("item")) {
col.add(getObject((Element) o));
for (Element o : e.getChildren("item")) {
col.add(getObject(o));
}
return col;
}catch(Exception e1){
Expand Down Expand Up @@ -318,6 +317,29 @@ public <T> T newInstance (Class<T> clazz)
return newInstance(clazz.getName());
}

/**
* Creates a new instance from the values in {@code Element e}.<br/>
* <p>
* The method honors the {@code enabled} attribute in the given {@code Element e},
* returning null immediately if {@code enabled} is computed to a true-equivalent.</p>
* <p>
* It also calls {@link #setLogger} to set logger and realm, and {@link #setConfiguration(Object, Element)}
* to trigger the standard [auto]configuration sequence from properties and XML.</p>
*
* @param e The XML config
* @return the new instance, or null if not enabled
* @throws ConfigurationException if the instance can't be created (e.g. class not found)
* or the configuration process itself threw the exception.
*/
public <T> T newInstance(Element e) throws ConfigurationException {
if (!QFactory.isEnabled(e))
return null;
T obj = newInstance(QFactory.getAttributeValue (e, "class"));
setLogger (obj, e);
setConfiguration(obj, e);
return obj;
}

public Configuration getConfiguration (Element e)
throws ConfigurationException
{
Expand Down Expand Up @@ -372,7 +394,7 @@ public static String getAttributeValue (Element e, String name) {
return Environment.getEnvironment().getProperty(s, s);
}
public void setConfiguration (Object obj, Element e)
throws ConfigurationException
throws ConfigurationException
{
try {
Configuration cfg = getConfiguration (e);
Expand All @@ -394,8 +416,8 @@ public void setConfiguration (Object obj, Element e)
* @param p parameter
* @throws ConfigurationException if method happens to throw an exception
*/
public static void invoke (Object obj, String m, Object p)
throws ConfigurationException
public static void invoke (Object obj, String m, Object p)
throws ConfigurationException
{
invoke (obj, m, p, p != null ? p.getClass() : null);
}
Expand All @@ -410,8 +432,8 @@ public static void invoke (Object obj, String m, Object p)
* @throws ConfigurationException if method happens to throw an exception
*/
@SuppressWarnings("PMD.EmptyCatchBlock")
public static void invoke (Object obj, String m, Object p, Class pc)
throws ConfigurationException
public static void invoke (Object obj, String m, Object p, Class pc)
throws ConfigurationException
{
try {
if (p!=null) {
Expand Down Expand Up @@ -479,7 +501,7 @@ else if (c.isAssignableFrom(double.class) || c.isAssignableFrom(Double.class))
field.set(obj, cfg.getDouble(config.value()));
else if (c.isAssignableFrom(boolean.class) || c.isAssignableFrom(Boolean.class))
field.set(obj, cfg.getBoolean(config.value()));
else if (c.isEnum())
else if (c.isEnum())
field.set(obj, Enum.valueOf((Class<Enum>) c, v));
else if (c.isArray()) {
Class<?> ct = c.getComponentType();
Expand All @@ -490,8 +512,8 @@ else if (ct.isAssignableFrom(int.class) || ct.isAssignableFrom(Integer.class))
else if (ct.isAssignableFrom(long.class) || ct.isAssignableFrom(Long.class))
field.set(obj, cfg.getLongs(config.value()));
else if (ct.isAssignableFrom(double.class) || ct.isAssignableFrom(Double.class))
field.set(obj, cfg.getDoubles(config.value()));
}
field.set(obj, cfg.getDoubles(config.value()));
}
}
}
}
Expand Down Expand Up @@ -539,5 +561,5 @@ private static void expandEnvProperties(Element e, Environment env) {
}
}
}

}
29 changes: 12 additions & 17 deletions jpos/src/main/java/org/jpos/q2/iso/ChannelAdaptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public class ChannelAdaptor
boolean ignoreISOExceptions = false;
boolean writeOnly = false;
int rx, tx, connects;
long lastTxn = 0l;
long timeout = 0l;
long lastTxn = 0L;
long timeout = 0L;
boolean waitForWorkersOnStop;
private Thread receiver;
private Thread sender;
Expand Down Expand Up @@ -202,16 +202,15 @@ public String getOutQueue () {
return out;
}

public ISOChannel newChannel (Element e, QFactory f)
public ISOChannel newChannel (Element e, QFactory f)
throws ConfigurationException
{
String channelName = QFactory.getAttributeValue (e, "class");
String packagerName = QFactory.getAttributeValue (e, "packager");

ISOChannel channel = (ISOChannel) f.newInstance (channelName);
ISOPackager packager;
ISOChannel channel = f.newInstance(channelName);
if (packagerName != null) {
packager = (ISOPackager) f.newInstance (packagerName);
ISOPackager packager = f.newInstance(packagerName);
channel.setPackager (packager);
f.setConfiguration (packager, e);
}
Expand All @@ -235,13 +234,9 @@ public ISOChannel newChannel (Element e, QFactory f)
protected void addFilters (FilteredChannel channel, Element e, QFactory fact)
throws ConfigurationException
{
for (Object o : e.getChildren("filter")) {
Element f = (Element) o;
if (!QFactory.isEnabled(f)) continue;
String clazz = QFactory.getAttributeValue(f, "class");
ISOFilter filter = (ISOFilter) fact.newInstance(clazz);
fact.setLogger(filter, f);
fact.setConfiguration(filter, f);
for (Element f : e.getChildren("filter")) {
ISOFilter filter = fact.newInstance(f);
if (filter == null) continue;
String direction = QFactory.getAttributeValue(f, "direction");
if (direction == null)
channel.addFilter(filter);
Expand All @@ -267,8 +262,8 @@ protected ISOChannel initChannel () throws ConfigurationException {
ISOChannel c = newChannel (e, getFactory());
String socketFactoryString = getSocketFactory();
if (socketFactoryString != null && c instanceof FactoryChannel) {
ISOClientSocketFactory sFac = (ISOClientSocketFactory) getFactory().newInstance(socketFactoryString);
if (sFac != null && sFac instanceof LogSource) {
ISOClientSocketFactory sFac = getFactory().newInstance(socketFactoryString);
if (sFac instanceof LogSource) {
((LogSource) sFac).setLogger(log.getLogger(),getName() + ".socket-factory");
}
getFactory().setConfiguration (sFac, e);
Expand All @@ -290,7 +285,7 @@ protected void initSpaceAndQueues () throws ConfigurationException {
keepAlive = "yes".equalsIgnoreCase (Environment.get(persist.getChildTextTrim ("keep-alive")));
ignoreISOExceptions = "yes".equalsIgnoreCase (Environment.get(persist.getChildTextTrim ("ignore-iso-exceptions")));
String t = Environment.get(persist.getChildTextTrim("timeout"));
timeout = t != null && t.length() > 0 ? Long.parseLong(t) : 0l;
timeout = t != null && t.length() > 0 ? Long.parseLong(t) : 0L;
ready = getName() + ".ready";
reconnect = getName() + ".reconnect";
waitForWorkersOnStop = "yes".equalsIgnoreCase(Environment.get(persist.getChildTextTrim ("wait-for-workers-on-stop")));
Expand Down Expand Up @@ -484,7 +479,7 @@ public synchronized void setSocketFactory (String sFac) {

public void resetCounters () {
rx = tx = connects = 0;
lastTxn = 0l;
lastTxn = 0L;
}
public String getCountersAsString () {
StringBuilder sb = new StringBuilder();
Expand Down
6 changes: 1 addition & 5 deletions jpos/src/main/java/org/jpos/q2/iso/MUXPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,7 @@ public void stopService () {
protected void initHandler(Element e) throws ConfigurationException {
if (e == null)
return;

QFactory factory = getFactory();
strategyHandler = factory.newInstance(QFactory.getAttributeValue (e, "class"));
factory.setLogger(strategyHandler, e);
factory.setConfiguration(strategyHandler, e);
strategyHandler = getFactory().newInstance(e);
}

public ISOMsg request (ISOMsg m, long timeout) throws ISOException {
Expand Down
9 changes: 4 additions & 5 deletions jpos/src/main/java/org/jpos/q2/iso/OneShotChannelAdaptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ public void initChannel () throws ConfigurationException {

String socketFactoryString = getSocketFactory();
if (socketFactoryString != null && channel instanceof FactoryChannel) {
ISOClientSocketFactory sFac = (ISOClientSocketFactory) getFactory().newInstance(socketFactoryString);
if (sFac != null && sFac instanceof LogSource) {
ISOClientSocketFactory sFac = getFactory().newInstance(socketFactoryString);
if (sFac instanceof LogSource) {
((LogSource) sFac).setLogger(log.getLogger(),getName() + ".socket-factory");
}
getFactory().setConfiguration (sFac, e);
Expand All @@ -214,10 +214,9 @@ private ISOChannel newChannel (Element e, QFactory f)

String packagerName = QFactory.getAttributeValue (e, "packager");

ISOChannel channel = (ISOChannel) f.newInstance (channelName);
ISOPackager packager;
ISOChannel channel = f.newInstance (channelName);
if (packagerName != null) {
packager = (ISOPackager) f.newInstance (packagerName);
ISOPackager packager = f.newInstance (packagerName);
channel.setPackager (packager);
f.setConfiguration (packager, e);
}
Expand Down
28 changes: 11 additions & 17 deletions jpos/src/main/java/org/jpos/q2/iso/QMUX.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class QMUX
private Counter rxCounter;
private Counter rxMatchCounter;
private Counter rxUnhandledCounter;

public QMUX () {
super ();
listeners = new ArrayList<>();
Expand Down Expand Up @@ -104,7 +104,7 @@ public void initService () throws ConfigurationException {
}
ready = toStringArray(Environment.get(e.getChildTextTrim ("ready")));
mtiMapping = toStringArray(Environment.get(e.getChildTextTrim ("mtimapping")));
if (mtiMapping == null || mtiMapping.length != 3)
if (mtiMapping == null || mtiMapping.length != 3)
mtiMapping = new String[] { nomap, nomap, "0022446689" };
addListeners ();
unhandled = Environment.get(e.getChildTextTrim ("unhandled"));
Expand Down Expand Up @@ -138,7 +138,7 @@ public void destroyService () {
* @see NameRegistrar
*/
public static MUX getMUX (String name)
throws NameRegistrar.NotFoundException
throws NameRegistrar.NotFoundException
{
return (MUX) NameRegistrar.get ("mux."+name);
}
Expand Down Expand Up @@ -349,7 +349,7 @@ public String getInQueue () {
return in;
}
public synchronized void setOutQueue (String out) {
this.out = out;
this.out = out;
getPersist().getChild("out").setText (out);
setModified (true);
}
Expand All @@ -373,17 +373,11 @@ public String[] getReadyIndicatorNames() {
}

private void addListeners() throws ConfigurationException {
List<Element> rlisten = getPersist().getChildren("request-listener");
if (rlisten.isEmpty())
return;

QFactory factory = getFactory ();
for (Element l : rlisten) {
ISORequestListener listener = (ISORequestListener)
factory.newInstance (QFactory.getAttributeValue (l, "class"));
factory.setLogger (listener, l);
factory.setConfiguration (listener, l);
addISORequestListener (listener);
for (Element l : getPersist().getChildren("request-listener")) {
ISORequestListener listener = factory.newInstance(l);
if (listener != null)
addISORequestListener (listener);
}
}
public void addISORequestListener(ISORequestListener l) {
Expand Down Expand Up @@ -417,7 +411,7 @@ public String getCountersAsString () {
}
return sb.toString();
}

public int getTXCounter() {
return tx;
}
Expand Down Expand Up @@ -477,7 +471,7 @@ protected void processUnhandled (ISOMsg m) {
sp.out (unhandled, m, 120000);
}
}
private LocalSpace grabSpace (Element e)
private LocalSpace grabSpace (Element e)
throws ConfigurationException
{
String uri = e != null ? e.getText() : "";
Expand Down Expand Up @@ -544,7 +538,7 @@ private String[] toStringArray(String s) {
return toStringArray(s, null,null);
}
private boolean shouldIgnore (ISOMsg m) {
if (m != null && ignorerc != null
if (m != null && ignorerc != null
&& ignorerc.length() > 0 && m.hasField(39))
{
return ignorerc.contains(m.getString(39));
Expand Down
Loading
Loading