use of nl.nn.adapterframework.statistics.StatisticsKeeper in project iaf by ibissource.
the class MonitoringPipeProcessor method processPipe.
public PipeRunResult processPipe(PipeLine pipeLine, IPipe pipe, String messageId, Object message, IPipeLineSession pipeLineSession) throws PipeRunException {
PipeRunResult pipeRunResult = null;
IExtendedPipe pe = null;
if (pipe instanceof IExtendedPipe) {
pe = (IExtendedPipe) pipe;
}
long pipeStartTime = System.currentTimeMillis();
if (log.isDebugEnabled()) {
// for performance reasons
StringBuffer sb = new StringBuffer();
String ownerName = pipeLine.getOwner() == null ? "<null>" : pipeLine.getOwner().getName();
String pipeName = pipe == null ? "<null>" : pipe.getName();
sb.append("Pipeline of adapter [" + ownerName + "] messageId [" + messageId + "] is about to call pipe [" + pipeName + "]");
boolean lir = false;
if (AppConstants.getInstance().getProperty("log.logIntermediaryResults") != null) {
if (AppConstants.getInstance().getProperty("log.logIntermediaryResults").equalsIgnoreCase("true")) {
lir = true;
}
}
if (pipe instanceof AbstractPipe) {
AbstractPipe ap = (AbstractPipe) pipe;
if (StringUtils.isNotEmpty(ap.getLogIntermediaryResults())) {
lir = Boolean.valueOf(ap.getLogIntermediaryResults());
}
}
if (lir) {
sb.append(" current result [" + message + "] ");
}
log.debug(sb.toString());
}
// start it
long pipeDuration = -1;
try {
pipeRunResult = pipeProcessor.processPipe(pipeLine, pipe, messageId, message, pipeLineSession);
} catch (PipeRunException pre) {
if (pe != null) {
pe.throwEvent(IExtendedPipe.PIPE_EXCEPTION_MONITORING_EVENT);
}
throw pre;
} catch (RuntimeException re) {
if (pe != null) {
pe.throwEvent(IExtendedPipe.PIPE_EXCEPTION_MONITORING_EVENT);
}
throw new PipeRunException(pipe, "Uncaught runtime exception running pipe '" + (pipe == null ? "null" : pipe.getName()) + "'", re);
} finally {
long pipeEndTime = System.currentTimeMillis();
pipeDuration = pipeEndTime - pipeStartTime;
StatisticsKeeper sk = pipeLine.getPipeStatistics(pipe);
if (sk == null) {
log.warn("Could not get statistics for pipe [+" + pipe.getName() + "]");
} else {
sk.addValue(pipeDuration);
}
if (pe != null) {
if (pe.getDurationThreshold() >= 0 && pipeDuration > pe.getDurationThreshold()) {
durationLog.info("Pipe [" + pe.getName() + "] of [" + pipeLine.getOwner().getName() + "] duration [" + pipeDuration + "] ms exceeds max [" + pe.getDurationThreshold() + "], message [" + message + "]");
pe.throwEvent(IExtendedPipe.LONG_DURATION_MONITORING_EVENT);
}
}
}
return pipeRunResult;
}
use of nl.nn.adapterframework.statistics.StatisticsKeeper in project iaf by ibissource.
the class CounterSwitchPipe method doPipe.
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
String forward = "";
PipeForward pipeForward = null;
StatisticsKeeper sk = getPipeLine().getPipeStatistics(this);
if (sk != null) {
long count = sk.getCount();
forward = "" + (getDivisor() - (count % getDivisor()));
}
log.debug(getLogPrefix(session) + "determined forward [" + forward + "]");
pipeForward = findForward(forward);
if (pipeForward == null) {
throw new PipeRunException(this, getLogPrefix(null) + "cannot find forward or pipe named [" + forward + "]");
}
log.debug(getLogPrefix(session) + "resolved forward [" + forward + "] to path [" + pipeForward.getPath() + "]");
return new PipeRunResult(pipeForward, input);
}
use of nl.nn.adapterframework.statistics.StatisticsKeeper in project iaf by ibissource.
the class Adapter method configure.
/*
* This function is called by Configuration.registerAdapter,
* to make configuration information available to the Adapter. <br/><br/>
* This method also performs
* a <code>Pipeline.configurePipes()</code>, as to configure the individual pipes.
* @see nl.nn.adapterframework.core.Pipeline#configurePipes
*/
public void configure() throws ConfigurationException {
configurationSucceeded = false;
log.debug("configuring adapter [" + getName() + "]");
messageKeeper = getMessageKeeper();
statsMessageProcessingDuration = new StatisticsKeeper(getName());
if (pipeline == null) {
String msg = "No pipeline configured for adapter [" + getName() + "]";
messageKeeper.add(msg, MessageKeeperMessage.ERROR_LEVEL);
throw new ConfigurationException(msg);
}
try {
pipeline.setAdapter(this);
pipeline.configure();
messageKeeper.add("Adapter [" + name + "] pipeline successfully configured");
Iterator<IReceiver> it = receivers.iterator();
while (it.hasNext()) {
IReceiver receiver = it.next();
configureReceiver(receiver);
}
configurationSucceeded = true;
} catch (ConfigurationException e) {
error(true, "error initializing pipeline", e);
}
List<String> hrs = new ArrayList<String>();
for (IPipe pipe : pipeline.getPipes()) {
if (pipe instanceof AbstractPipe) {
AbstractPipe aPipe = (AbstractPipe) pipe;
if (aPipe.getHideRegex() != null) {
if (!hrs.contains(aPipe.getHideRegex())) {
hrs.add(aPipe.getHideRegex());
}
}
}
}
StringBuilder sb = new StringBuilder();
for (String hr : hrs) {
if (sb.length() > 0) {
sb.append("|");
}
sb.append("(");
sb.append(hr);
sb.append(")");
}
if (sb.length() > 0) {
composedHideRegex = sb.toString();
}
}
use of nl.nn.adapterframework.statistics.StatisticsKeeper in project iaf by ibissource.
the class PipeLine method handlePipeStat.
private void handlePipeStat(INamedObject pipe, Map<String, StatisticsKeeper> pipelineStatistics, Object pipeStatsData, StatisticsKeeperIterationHandler handler, boolean deep, int action) throws SenderException {
if (pipe == null) {
return;
}
StatisticsKeeper pstat = pipelineStatistics.get(pipe.getName());
handler.handleStatisticsKeeper(pipeStatsData, pstat);
if (deep && pipe instanceof HasStatistics) {
((HasStatistics) pipe).iterateOverStatistics(handler, pipeStatsData, action);
}
}
use of nl.nn.adapterframework.statistics.StatisticsKeeper in project iaf by ibissource.
the class JobDef method configure.
public void configure(Configuration config) throws ConfigurationException {
MessageKeeper messageKeeper = getMessageKeeper();
statsKeeper = new StatisticsKeeper(getName());
if (StringUtils.isEmpty(getFunction())) {
throw new ConfigurationException("jobdef [" + getName() + "] function must be specified");
}
if (!(getFunction().equalsIgnoreCase(JOB_FUNCTION_STOP_ADAPTER) || getFunction().equalsIgnoreCase(JOB_FUNCTION_START_ADAPTER) || getFunction().equalsIgnoreCase(JOB_FUNCTION_STOP_RECEIVER) || getFunction().equalsIgnoreCase(JOB_FUNCTION_START_RECEIVER) || getFunction().equalsIgnoreCase(JOB_FUNCTION_SEND_MESSAGE) || getFunction().equalsIgnoreCase(JOB_FUNCTION_QUERY) || getFunction().equalsIgnoreCase(JOB_FUNCTION_DUMPSTATS) || getFunction().equalsIgnoreCase(JOB_FUNCTION_DUMPSTATSFULL) || getFunction().equalsIgnoreCase(JOB_FUNCTION_CLEANUPDB) || getFunction().equalsIgnoreCase(JOB_FUNCTION_CLEANUPFS) || getFunction().equalsIgnoreCase(JOB_FUNCTION_RECOVER_ADAPTERS) || getFunction().equalsIgnoreCase(JOB_FUNCTION_CHECK_RELOAD))) {
throw new ConfigurationException("jobdef [" + getName() + "] function [" + getFunction() + "] must be one of [" + JOB_FUNCTION_STOP_ADAPTER + "," + JOB_FUNCTION_START_ADAPTER + "," + JOB_FUNCTION_STOP_RECEIVER + "," + JOB_FUNCTION_START_RECEIVER + "," + JOB_FUNCTION_SEND_MESSAGE + "," + JOB_FUNCTION_QUERY + "," + JOB_FUNCTION_DUMPSTATS + "," + JOB_FUNCTION_DUMPSTATSFULL + "," + JOB_FUNCTION_CLEANUPDB + "," + JOB_FUNCTION_CLEANUPFS + JOB_FUNCTION_RECOVER_ADAPTERS + JOB_FUNCTION_CHECK_RELOAD + "]");
}
if (getFunction().equalsIgnoreCase(JOB_FUNCTION_DUMPSTATS)) {
// nothing special for now
} else if (getFunction().equalsIgnoreCase(JOB_FUNCTION_DUMPSTATSFULL)) {
// nothing special for now
} else if (getFunction().equalsIgnoreCase(JOB_FUNCTION_CLEANUPDB)) {
// nothing special for now
} else if (getFunction().equalsIgnoreCase(JOB_FUNCTION_CLEANUPFS)) {
// nothing special for now
} else if (getFunction().equalsIgnoreCase(JOB_FUNCTION_RECOVER_ADAPTERS)) {
// nothing special for now
} else if (getFunction().equalsIgnoreCase(JOB_FUNCTION_CHECK_RELOAD)) {
// nothing special for now
} else if (getFunction().equalsIgnoreCase(JOB_FUNCTION_QUERY)) {
if (StringUtils.isEmpty(getJmsRealm())) {
throw new ConfigurationException("jobdef [" + getName() + "] for function [" + getFunction() + "] a jmsRealm must be specified");
}
} else {
if (StringUtils.isEmpty(getAdapterName())) {
throw new ConfigurationException("jobdef [" + getName() + "] for function [" + getFunction() + "] a adapterName must be specified");
}
if (config.getRegisteredAdapter(getAdapterName()) == null) {
String msg = "Jobdef [" + getName() + "] got error: adapter [" + getAdapterName() + "] not registered.";
throw new ConfigurationException(msg);
}
if (getFunction().equalsIgnoreCase(JOB_FUNCTION_STOP_RECEIVER) || getFunction().equalsIgnoreCase(JOB_FUNCTION_START_RECEIVER)) {
if (StringUtils.isEmpty(getReceiverName())) {
throw new ConfigurationException("jobdef [" + getName() + "] for function [" + getFunction() + "] a receiverName must be specified");
}
if (StringUtils.isNotEmpty(getReceiverName())) {
if (!config.isRegisteredReceiver(getAdapterName(), getReceiverName())) {
String msg = "Jobdef [" + getName() + "] got error: adapter [" + getAdapterName() + "] receiver [" + getReceiverName() + "] not registered.";
throw new ConfigurationException(msg);
}
}
}
}
if (getLocker() != null) {
getLocker().configure();
}
txDef = SpringTxManagerProxy.getTransactionDefinition(getTransactionAttributeNum(), getTransactionTimeout());
messageKeeper.add("job successfully configured");
}
Aggregations