Search in sources :

Example 6 with LoggingLevel

use of org.apache.camel.LoggingLevel in project camel by apache.

the class FileProcessStrategyFactory method getExclusiveReadLockStrategy.

@SuppressWarnings("unchecked")
private static GenericFileExclusiveReadLockStrategy<File> getExclusiveReadLockStrategy(Map<String, Object> params) {
    GenericFileExclusiveReadLockStrategy<File> strategy = (GenericFileExclusiveReadLockStrategy<File>) params.get("exclusiveReadLockStrategy");
    if (strategy != null) {
        return strategy;
    }
    // no explicit strategy set then fallback to readLock option
    String readLock = (String) params.get("readLock");
    if (ObjectHelper.isNotEmpty(readLock)) {
        if ("none".equals(readLock) || "false".equals(readLock)) {
            return null;
        } else if ("markerFile".equals(readLock)) {
            strategy = new MarkerFileExclusiveReadLockStrategy();
        } else if ("fileLock".equals(readLock)) {
            strategy = new FileLockExclusiveReadLockStrategy();
        } else if ("rename".equals(readLock)) {
            strategy = new FileRenameExclusiveReadLockStrategy();
        } else if ("changed".equals(readLock)) {
            FileChangedExclusiveReadLockStrategy readLockStrategy = new FileChangedExclusiveReadLockStrategy();
            Long minLength = (Long) params.get("readLockMinLength");
            if (minLength != null) {
                readLockStrategy.setMinLength(minLength);
            }
            Long minAge = (Long) params.get("readLockMinAge");
            if (null != minAge) {
                readLockStrategy.setMinAge(minAge);
            }
            strategy = readLockStrategy;
        } else if ("idempotent".equals(readLock)) {
            FileIdempotentRepositoryReadLockStrategy readLockStrategy = new FileIdempotentRepositoryReadLockStrategy();
            Boolean readLockRemoveOnRollback = (Boolean) params.get("readLockRemoveOnRollback");
            if (readLockRemoveOnRollback != null) {
                readLockStrategy.setRemoveOnRollback(readLockRemoveOnRollback);
            }
            Boolean readLockRemoveOnCommit = (Boolean) params.get("readLockRemoveOnCommit");
            if (readLockRemoveOnCommit != null) {
                readLockStrategy.setRemoveOnCommit(readLockRemoveOnCommit);
            }
            IdempotentRepository repo = (IdempotentRepository) params.get("readLockIdempotentRepository");
            if (repo != null) {
                readLockStrategy.setIdempotentRepository(repo);
            }
            strategy = readLockStrategy;
        } else if ("idempotent-changed".equals(readLock)) {
            FileIdempotentChangedRepositoryReadLockStrategy readLockStrategy = new FileIdempotentChangedRepositoryReadLockStrategy();
            Boolean readLockRemoveOnRollback = (Boolean) params.get("readLockRemoveOnRollback");
            if (readLockRemoveOnRollback != null) {
                readLockStrategy.setRemoveOnRollback(readLockRemoveOnRollback);
            }
            Boolean readLockRemoveOnCommit = (Boolean) params.get("readLockRemoveOnCommit");
            if (readLockRemoveOnCommit != null) {
                readLockStrategy.setRemoveOnCommit(readLockRemoveOnCommit);
            }
            IdempotentRepository repo = (IdempotentRepository) params.get("readLockIdempotentRepository");
            if (repo != null) {
                readLockStrategy.setIdempotentRepository(repo);
            }
            Long minLength = (Long) params.get("readLockMinLength");
            if (minLength != null) {
                readLockStrategy.setMinLength(minLength);
            }
            Long minAge = (Long) params.get("readLockMinAge");
            if (null != minAge) {
                readLockStrategy.setMinAge(minAge);
            }
            strategy = readLockStrategy;
        } else if ("idempotent-rename".equals(readLock)) {
            FileIdempotentRenameRepositoryReadLockStrategy readLockStrategy = new FileIdempotentRenameRepositoryReadLockStrategy();
            Boolean readLockRemoveOnRollback = (Boolean) params.get("readLockRemoveOnRollback");
            if (readLockRemoveOnRollback != null) {
                readLockStrategy.setRemoveOnRollback(readLockRemoveOnRollback);
            }
            Boolean readLockRemoveOnCommit = (Boolean) params.get("readLockRemoveOnCommit");
            if (readLockRemoveOnCommit != null) {
                readLockStrategy.setRemoveOnCommit(readLockRemoveOnCommit);
            }
            IdempotentRepository repo = (IdempotentRepository) params.get("readLockIdempotentRepository");
            if (repo != null) {
                readLockStrategy.setIdempotentRepository(repo);
            }
            strategy = readLockStrategy;
        }
        if (strategy != null) {
            Long timeout = (Long) params.get("readLockTimeout");
            if (timeout != null) {
                strategy.setTimeout(timeout);
            }
            Long checkInterval = (Long) params.get("readLockCheckInterval");
            if (checkInterval != null) {
                strategy.setCheckInterval(checkInterval);
            }
            LoggingLevel readLockLoggingLevel = (LoggingLevel) params.get("readLockLoggingLevel");
            if (readLockLoggingLevel != null) {
                strategy.setReadLockLoggingLevel(readLockLoggingLevel);
            }
            Boolean readLockMarkerFile = (Boolean) params.get("readLockMarkerFile");
            if (readLockMarkerFile != null) {
                strategy.setMarkerFiler(readLockMarkerFile);
            }
            Boolean readLockDeleteOrphanLockFiles = (Boolean) params.get("readLockDeleteOrphanLockFiles");
            if (readLockDeleteOrphanLockFiles != null) {
                strategy.setDeleteOrphanLockFiles(readLockDeleteOrphanLockFiles);
            }
        }
    }
    return strategy;
}
Also used : GenericFileExclusiveReadLockStrategy(org.apache.camel.component.file.GenericFileExclusiveReadLockStrategy) LoggingLevel(org.apache.camel.LoggingLevel) IdempotentRepository(org.apache.camel.spi.IdempotentRepository) File(java.io.File)

Example 7 with LoggingLevel

use of org.apache.camel.LoggingLevel in project camel by apache.

the class CamelLogger method log.

public void log(String message, LoggingLevel loggingLevel) {
    LoggingLevel oldLogLevel = getLevel();
    setLevel(loggingLevel);
    log(message);
    setLevel(oldLogLevel);
}
Also used : LoggingLevel(org.apache.camel.LoggingLevel)

Example 8 with LoggingLevel

use of org.apache.camel.LoggingLevel in project camel by apache.

the class EnumConverterTest method testMandatoryConvertWithExchangeEnum.

public void testMandatoryConvertWithExchangeEnum() throws Exception {
    Exchange exchange = new DefaultExchange(context);
    LoggingLevel level = context.getTypeConverter().mandatoryConvertTo(LoggingLevel.class, exchange, "WARN");
    assertEquals(LoggingLevel.WARN, level);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) LoggingLevel(org.apache.camel.LoggingLevel)

Example 9 with LoggingLevel

use of org.apache.camel.LoggingLevel in project camel by apache.

the class EnumConverterTest method testCaseInsensitive.

public void testCaseInsensitive() throws Exception {
    Exchange exchange = new DefaultExchange(context);
    LoggingLevel level = context.getTypeConverter().mandatoryConvertTo(LoggingLevel.class, exchange, "Warn");
    assertEquals(LoggingLevel.WARN, level);
    level = context.getTypeConverter().mandatoryConvertTo(LoggingLevel.class, exchange, "warn");
    assertEquals(LoggingLevel.WARN, level);
    level = context.getTypeConverter().mandatoryConvertTo(LoggingLevel.class, exchange, "wARn");
    assertEquals(LoggingLevel.WARN, level);
    level = context.getTypeConverter().mandatoryConvertTo(LoggingLevel.class, exchange, "inFO");
    assertEquals(LoggingLevel.INFO, level);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) LoggingLevel(org.apache.camel.LoggingLevel)

Example 10 with LoggingLevel

use of org.apache.camel.LoggingLevel in project camel by apache.

the class LogComponent method createEndpoint.

protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    LoggingLevel level = getLoggingLevel(parameters);
    Logger providedLogger = getLogger(parameters);
    if (providedLogger == null) {
        // try to look up the logger in registry
        Map<String, Logger> availableLoggers = getCamelContext().getRegistry().findByTypeWithName(Logger.class);
        if (availableLoggers.size() == 1) {
            providedLogger = availableLoggers.values().iterator().next();
            LOG.info("Using custom Logger: {}", providedLogger);
        } else if (availableLoggers.size() > 1) {
            LOG.info("More than one {} instance found in the registry. Falling back to creating logger from URI {}.", Logger.class.getName(), uri);
        }
    }
    LogEndpoint endpoint = new LogEndpoint(uri, this);
    endpoint.setLevel(level.name());
    setProperties(endpoint, parameters);
    if (providedLogger == null) {
        endpoint.setLoggerName(remaining);
    } else {
        endpoint.setProvidedLogger(providedLogger);
    }
    // first, try to pick up the ExchangeFormatter from the registry
    ExchangeFormatter localFormatter = getCamelContext().getRegistry().lookupByNameAndType("logFormatter", ExchangeFormatter.class);
    if (localFormatter != null) {
        setProperties(localFormatter, parameters);
    } else if (localFormatter == null && exchangeFormatter != null) {
        // do not set properties, the exchangeFormatter is explicitly set, therefore the
        // user would have set its properties explicitly too
        localFormatter = exchangeFormatter;
    } else {
        // if no formatter is available in the Registry, create a local one of the default type, for a single use
        localFormatter = new DefaultExchangeFormatter();
        setProperties(localFormatter, parameters);
    }
    endpoint.setLocalFormatter(localFormatter);
    return endpoint;
}
Also used : LoggingLevel(org.apache.camel.LoggingLevel) ExchangeFormatter(org.apache.camel.spi.ExchangeFormatter) DefaultExchangeFormatter(org.apache.camel.processor.DefaultExchangeFormatter) DefaultExchangeFormatter(org.apache.camel.processor.DefaultExchangeFormatter) Logger(org.slf4j.Logger) CamelLogger(org.apache.camel.util.CamelLogger)

Aggregations

LoggingLevel (org.apache.camel.LoggingLevel)12 CamelLogger (org.apache.camel.util.CamelLogger)3 Exchange (org.apache.camel.Exchange)2 DefaultExchange (org.apache.camel.impl.DefaultExchange)2 ExchangeFormatter (org.apache.camel.spi.ExchangeFormatter)2 Logger (org.slf4j.Logger)2 File (java.io.File)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 Expression (org.apache.camel.Expression)1 Processor (org.apache.camel.Processor)1 GenericFileExclusiveReadLockStrategy (org.apache.camel.component.file.GenericFileExclusiveReadLockStrategy)1 CamelLogProcessor (org.apache.camel.processor.CamelLogProcessor)1 DefaultExchangeFormatter (org.apache.camel.processor.DefaultExchangeFormatter)1 LogProcessor (org.apache.camel.processor.LogProcessor)1 ThroughputLogger (org.apache.camel.processor.ThroughputLogger)1 IdempotentRepository (org.apache.camel.spi.IdempotentRepository)1