Skip to content

Commit

Permalink
Do not create a LogEvent if we don't have a Logger
Browse files Browse the repository at this point in the history
  • Loading branch information
ar committed Oct 1, 2014
1 parent 7c92d0a commit d467755
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions jpos/src/main/java/org/jpos/iso/ISOBasePackager.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,13 @@ public byte[] pack (ISOComponent m) throws ISOException {
* @exception ISOException
*/
public int unpack (ISOComponent m, byte[] b) throws ISOException {
LogEvent evt = new LogEvent (this, "unpack");
LogEvent evt = logger != null ? new LogEvent (this, "unpack") : null;
int consumed = 0;

try {
if (m.getComposite() != m)
throw new ISOException ("Can't call packager on non Composite");
if (logger != null) // save a few CPU cycle if no logger available
if (evt != null) // save a few CPU cycle if no logger available
evt.addMessage (ISOUtil.hexString (b));


Expand All @@ -218,7 +218,7 @@ public int unpack (ISOComponent m, byte[] b) throws ISOException {
ISOBitMap bitmap = new ISOBitMap (-1);
consumed += getBitMapfieldPackager().unpack(bitmap,b,consumed);
bmap = (BitSet) bitmap.getValue();
if (logger != null)
if (evt != null)
evt.addMessage ("<bitmap>"+bmap.toString()+"</bitmap>");
m.set (bitmap);
maxField = Math.min(maxField, bmap.size());
Expand All @@ -236,7 +236,7 @@ public int unpack (ISOComponent m, byte[] b) throws ISOException {

ISOComponent c = fld[i].createComponent(i);
consumed += fld[i].unpack (c, b, consumed);
if (logger != null) {
if (evt != null) {
evt.addMessage ("<unpack fld=\"" + i
+"\" packager=\""
+fld[i].getClass().getName()+ "\">");
Expand All @@ -257,10 +257,12 @@ else if (c.getValue() instanceof byte[]) {
m.set(c);
}
} catch (ISOException e) {
evt.addMessage (
"error unpacking field " + i + " consumed=" + consumed
);
evt.addMessage (e);
if (evt != null) {
evt.addMessage(
"error unpacking field " + i + " consumed=" + consumed
);
evt.addMessage(e);
}
// jPOS-3
e = new ISOException (
String.format ("%s (%s) unpacking field=%d, consumed=%d",
Expand All @@ -269,26 +271,29 @@ else if (c.getValue() instanceof byte[]) {
throw e;
}
}
if (b.length != consumed) {
if (evt != null && b.length != consumed) {
evt.addMessage (
"WARNING: unpack len=" +b.length +" consumed=" +consumed
);
}
return consumed;
} catch (ISOException e) {
evt.addMessage (e);
if (evt != null)
evt.addMessage (e);
throw e;
} catch (Exception e) {
evt.addMessage (e);
if (evt != null)
evt.addMessage (e);
throw new ISOException (e.getMessage() + " consumed=" + consumed);
} finally {
Logger.log (evt);
if (evt != null)
Logger.log (evt);
}
}
public void unpack (ISOComponent m, InputStream in)
throws IOException, ISOException
{
LogEvent evt = new LogEvent (this, "unpack");
LogEvent evt = logger != null ? new LogEvent (this, "unpack") : null;
try {
if (m.getComposite() != m)
throw new ISOException ("Can't call packager on non Composite");
Expand All @@ -315,7 +320,7 @@ public void unpack (ISOComponent m, InputStream in)
ISOBitMap bitmap = new ISOBitMap (-1);
getBitMapfieldPackager().unpack(bitmap, in);
bmap = (BitSet) bitmap.getValue();
if (logger != null)
if (evt != null)
evt.addMessage ("<bitmap>"+bmap.toString()+"</bitmap>");
m.set (bitmap);
maxField = Math.min(maxField, bmap.size());
Expand All @@ -331,7 +336,7 @@ public void unpack (ISOComponent m, InputStream in)

ISOComponent c = fld[i].createComponent(i);
fld[i].unpack (c, in);
if (logger != null) {
if (evt != null) {
evt.addMessage ("<unpack fld=\"" + i
+"\" packager=\""
+fld[i].getClass().getName()+ "\">");
Expand All @@ -354,7 +359,7 @@ public void unpack (ISOComponent m, InputStream in)
if (bmap == null || bmap.get(i)) {
ISOComponent c = fld[i+128].createComponent(i);
fld[i+128].unpack (c, in);
if (logger != null) {
if (evt != null) {
evt.addMessage ("<unpack fld=\"" + i+128
+"\" packager=\""
+fld[i+128].getClass().getName()+ "\">");
Expand All @@ -368,15 +373,18 @@ public void unpack (ISOComponent m, InputStream in)
}
}
} catch (ISOException e) {
evt.addMessage (e);
if (evt != null)
evt.addMessage (e);
throw e;
} catch (EOFException e) {
throw e;
} catch (Exception e) {
evt.addMessage (e);
if (evt != null)
evt.addMessage (e);
throw new ISOException (e);
} finally {
Logger.log (evt);
if (evt != null)
Logger.log (evt);
}
}
/**
Expand Down

0 comments on commit d467755

Please sign in to comment.