use of org.jpos.util.LogEvent in project jPOS by jpos.
the class XMLPackager method unpack.
public synchronized void unpack(ISOComponent c, InputStream in) throws ISOException, IOException {
LogEvent evt = new LogEvent(this, "unpack");
try {
if (!(c instanceof ISOMsg))
throw new ISOException("Can't call packager on non Composite");
while (// purge from possible previous error
!stk.empty()) stk.pop();
reader.parse(new InputSource(in));
if (stk.empty())
throw new ISOException("error parsing");
ISOMsg m = (ISOMsg) c;
ISOMsg m1 = (ISOMsg) stk.pop();
m.merge(m1);
m.setHeader(m1.getHeader());
if (logger != null)
evt.addMessage(m);
} catch (ISOException e) {
evt.addMessage(e);
throw e;
} catch (SAXException e) {
evt.addMessage(e);
throw new ISOException(e.toString());
} finally {
Logger.log(evt);
}
}
use of org.jpos.util.LogEvent in project jPOS by jpos.
the class XMLPackager method unpack.
public synchronized int unpack(ISOComponent c, byte[] b) throws ISOException {
LogEvent evt = new LogEvent(this, "unpack");
try {
if (!(c instanceof ISOMsg))
throw new ISOException("Can't call packager on non Composite");
while (// purge from possible previous error
!stk.empty()) stk.pop();
InputSource src = new InputSource(new ByteArrayInputStream(b));
reader.parse(src);
if (stk.empty())
throw new ISOException("error parsing");
ISOMsg m = (ISOMsg) c;
ISOMsg m1 = (ISOMsg) stk.pop();
m.merge(m1);
m.setHeader(m1.getHeader());
if (logger != null)
evt.addMessage(m);
return b.length;
} catch (ISOException e) {
evt.addMessage(e);
throw e;
} catch (IOException e) {
evt.addMessage(e);
throw new ISOException(e.toString());
} catch (SAXException e) {
evt.addMessage(e);
throw new ISOException(e.toString());
} finally {
Logger.log(evt);
}
}
use of org.jpos.util.LogEvent in project jPOS by jpos.
the class Q2 method waitForChanges.
private boolean waitForChanges(WatchService service) throws InterruptedException {
WatchKey key = service.poll(SCAN_INTERVAL, TimeUnit.MILLISECONDS);
if (key != null) {
LogEvent evt = getLog().createInfo();
for (WatchEvent<?> ev : key.pollEvents()) {
if (ev.kind() == StandardWatchEventKinds.ENTRY_CREATE) {
evt.addMessage(String.format("created %s/%s", deployDir.getName(), ev.context()));
} else if (ev.kind() == StandardWatchEventKinds.ENTRY_DELETE) {
evt.addMessage(String.format("removed %s/%s", deployDir.getName(), ev.context()));
} else if (ev.kind() == StandardWatchEventKinds.ENTRY_MODIFY) {
evt.addMessage(String.format("modified %s/%s", deployDir.getName(), ev.context()));
}
}
Logger.log(evt);
if (!key.reset()) {
getLog().warn(String.format("deploy directory '%s' no longer valid", deployDir.getAbsolutePath()));
// deploy directory no longer valid
return false;
}
}
return true;
}
use of org.jpos.util.LogEvent in project jPOS by jpos.
the class Q2 method deploy.
private boolean deploy(File f) {
LogEvent evt = log != null ? log.createInfo() : null;
try {
QEntry qentry = dirMap.get(f);
SAXBuilder builder = createSAXBuilder();
Document doc;
if (decorator != null && !f.getName().equals(LOGGER_CONFIG)) {
doc = decrypt(builder.build(new StringReader(decorator.decorateFile(f))));
} else {
doc = decrypt(builder.build(f));
}
Element rootElement = doc.getRootElement();
String iuuid = rootElement.getAttributeValue("instance");
if (iuuid != null) {
UUID uuid = UUID.fromString(iuuid);
if (!uuid.equals(getInstanceId())) {
deleteFile(f, iuuid);
return false;
}
}
String enabledAttribute = rootElement.getAttributeValue("enabled", "true");
if ("true".equalsIgnoreCase(enabledAttribute) || "yes".equalsIgnoreCase(enabledAttribute)) {
if (evt != null)
evt.addMessage("deploy: " + f.getCanonicalPath());
Object obj = factory.instantiate(this, rootElement);
qentry.setObject(obj);
ObjectInstance instance = factory.createQBean(this, doc.getRootElement(), obj);
qentry.setInstance(instance);
} else if (evt != null) {
evt.addMessage("deploy ignored (enabled='" + enabledAttribute + "'): " + f.getCanonicalPath());
}
} catch (InstanceAlreadyExistsException e) {
/*
* Ok, the file we tried to deploy, holds an object
* that already has been deployed.
*
* Rename it out of the way.
*
*/
tidyFileAway(f, DUPLICATE_EXTENSION);
if (evt != null)
evt.addMessage(e);
return false;
} catch (Exception e) {
if (evt != null)
evt.addMessage(e);
tidyFileAway(f, ERROR_EXTENSION);
// This will also save deploy error repeats...
return false;
} catch (Error e) {
if (evt != null)
evt.addMessage(e);
tidyFileAway(f, ENV_EXTENSION);
// This will also save deploy error repeats...
return false;
} finally {
if (evt != null)
Logger.log(evt);
}
return true;
}
use of org.jpos.util.LogEvent in project jPOS by jpos.
the class Q2 method logVersion.
private void logVersion() {
long now = System.currentTimeMillis();
if (now - lastVersionLog > 3600000L) {
LogEvent evt = getLog().createLogEvent("version");
evt.addMessage(getVersionString());
Logger.log(evt);
lastVersionLog = now;
while ((PGPHelper.checkLicense() & 0xE0000) != 0) relax();
}
}
Aggregations