use of org.jpos.util.LogEvent in project jPOS by jpos.
the class PADChannel method receive.
@Override
public ISOMsg receive() throws IOException, ISOException {
byte[] header = null;
ISOMsg m = new ISOMsg();
m.setPackager(packager);
m.setSource(this);
int hLen = getHeaderLength();
LogEvent evt = new LogEvent(this, "receive");
try {
synchronized (serverInLock) {
if (hLen > 0) {
header = new byte[hLen];
serverIn.readFully(header);
}
m.unpack(serverIn);
}
m.setHeader(header);
m.setDirection(ISOMsg.INCOMING);
m = applyIncomingFilters(m, evt);
m.setDirection(ISOMsg.INCOMING);
evt.addMessage(m);
cnt[RX]++;
setChanged();
notifyObservers(m);
} catch (ISOException e) {
evt.addMessage(e);
throw e;
} catch (EOFException e) {
evt.addMessage("<peer-disconnect/>");
throw e;
} catch (InterruptedIOException e) {
evt.addMessage("<io-timeout/>");
throw e;
} catch (IOException e) {
if (usable)
evt.addMessage(e);
throw e;
} catch (Exception e) {
evt.addMessage(e);
throw new ISOException("unexpected exception", e);
} finally {
Logger.log(evt);
}
return m;
}
use of org.jpos.util.LogEvent in project jPOS by jpos.
the class Base1SubFieldPackager method pack.
/**
* Pack the subfield into a byte array
*/
public byte[] pack(ISOComponent m) throws ISOException {
LogEvent evt = new LogEvent(this, "pack");
try {
ISOComponent c;
List<byte[]> l = new ArrayList();
Map fields = m.getChildren();
int len = 0;
if (emitBitMap()) {
// BITMAP (-1 in HashTable)
c = (ISOComponent) fields.get(-1);
byte[] b = getBitMapfieldPackager().pack(c);
len += b.length;
l.add(b);
}
for (int i = getFirstField(); i <= m.getMaxField(); i++) {
if ((c = (ISOComponent) fields.get(i)) != null) {
try {
byte[] b = fld[i].pack(c);
len += b.length;
l.add(b);
} catch (Exception e) {
evt.addMessage("error packing field " + i);
evt.addMessage(c);
evt.addMessage(e);
throw new ISOException(e);
}
}
}
int k = 0;
byte[] d = new byte[len];
for (byte[] b : l) {
System.arraycopy(b, 0, d, k, b.length);
k += b.length;
}
if (// save a few CPU cycle if no logger available
logger != null)
evt.addMessage(ISOUtil.hexString(d));
return d;
} catch (ISOException e) {
evt.addMessage(e);
throw e;
} finally {
Logger.log(evt);
}
}
use of org.jpos.util.LogEvent in project jPOS by jpos.
the class SpaceMUX method notify.
public void notify(Object k, Object value) {
Object obj = sp.inp(k);
if (obj instanceof ISOMsg) {
ISOMsg m = (ISOMsg) obj;
try {
String key = getKey(m);
String req = key + ".req";
if (sp.inp(req) != null) {
sp.out(key, m);
return;
}
} catch (ISOException e) {
Logger.log(new LogEvent(this, "notify", e));
}
if (unhandled != null)
sp.out(unhandled, m, 120000);
}
}
use of org.jpos.util.LogEvent in project jPOS by jpos.
the class ConnectionPool method run.
public void run() {
Connection connection = null;
while (connection == null) {
try {
connection = makeNewConnection();
synchronized (this) {
availableConnections.addElement(connection);
connectionPending = false;
notifyAll();
}
} catch (Exception e) {
// SQLException or OutOfMemory
LogEvent evt = new LogEvent(this, "error");
evt.addMessage("An error occurred while trying to make a background connection");
evt.addMessage(e);
Logger.log(evt);
try {
// don't get too crazy about retrying
Thread.sleep(3000);
} catch (InterruptedException ie) {
// this one, we don't care.
}
}
}
}
use of org.jpos.util.LogEvent in project jPOS by jpos.
the class BSHLogListener method log.
public LogEvent log(LogEvent ev) {
LogEvent ret = ev;
boolean processed = false;
try {
String[] sources = replace(cfg.getAll("source"), patterns, new String[] { ev.getTag(), ev.getRealm() });
for (int i = 0; i < sources.length && ret != null; i++) {
try {
Interpreter bsh = new Interpreter();
BSHLogListener.ScriptInfo info = getScriptInfo(sources[i]);
NameSpace ns = info != null ? info.getNameSpace() : null;
if (ns != null)
bsh.setNameSpace(ns);
bsh.set("event", ret);
bsh.set("cfg", cfg);
File f = new File(sources[i]);
if (!cfg.getBoolean("preload-scripts")) {
if (f.exists() && f.canRead() && f.isFile()) {
// if(f.lastModified())
processed = true;
bsh.eval(new java.io.FileReader(f));
}
} else {
if (info == null)
scripts.put(sources[i], info = new ScriptInfo());
if (System.currentTimeMillis() > info.getLastCheck() + cfg.getLong("reload")) {
info.setLastCheck(System.currentTimeMillis());
if (f.exists() && f.canRead() && f.isFile()) {
if (info.getLastModified() != f.lastModified()) {
info.setLastModified(f.lastModified());
info.setCode(loadCode(f));
}
} else {
info.setCode(null);
}
}
if (info.getCode() != null) {
processed = true;
bsh.eval(new StringReader(info.getCode()));
} else
scripts.remove(sources[i]);
}
ret = (LogEvent) bsh.get("event");
Object saveNS = bsh.get("saveNameSpace");
boolean saveNameSpace = saveNS instanceof Boolean ? (Boolean) saveNS : cfg.getBoolean("save-name-space");
if (saveNameSpace) {
if (info != null)
info.setNameSpace(bsh.getNameSpace());
else
scripts.put(sources[i], new ScriptInfo(bsh.getNameSpace()));
} else if (info != null)
info.setNameSpace(null);
} catch (Exception e) {
ret.addMessage(e);
}
}
return !processed && cfg.getBoolean("filter-by-default") ? null : ret;
} catch (Exception e) {
if (ret != null) {
ret.addMessage(e);
}
return ret;
}
}
Aggregations