Search in sources :

Example 26 with IgniteLogger

use of org.apache.ignite.IgniteLogger in project ignite by apache.

the class GridCacheAbstractLoadTest method initLogger.

/**
 * Initializes logger.
 *
 * @param log Log file name.
 * @return Logger.
 * @throws IgniteCheckedException If file initialization failed.
 */
protected IgniteLogger initLogger(String log) throws IgniteCheckedException {
    Logger impl = Logger.getRootLogger();
    impl.removeAllAppenders();
    String fileName = U.getIgniteHome() + "/work/log/" + log;
    // Configure output that should go to System.out
    RollingFileAppender fileApp;
    String fmt = "[%d{ISO8601}][%-5p][%t][%c{1}] %m%n";
    try {
        fileApp = new RollingFileAppender(new PatternLayout(fmt), fileName);
        fileApp.setMaxBackupIndex(0);
        fileApp.setAppend(false);
        // fileApp.rollOver();
        fileApp.activateOptions();
    } catch (IOException e) {
        throw new IgniteCheckedException("Unable to initialize file appender.", e);
    }
    LevelRangeFilter lvlFilter = new LevelRangeFilter();
    lvlFilter.setLevelMin(Level.DEBUG);
    fileApp.addFilter(lvlFilter);
    impl.addAppender(fileApp);
    // Configure output that should go to System.out
    ConsoleAppender conApp = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_OUT);
    lvlFilter = new LevelRangeFilter();
    lvlFilter.setLevelMin(Level.DEBUG);
    lvlFilter.setLevelMax(Level.INFO);
    conApp.addFilter(lvlFilter);
    conApp.activateOptions();
    impl.addAppender(conApp);
    // Configure output that should go to System.err
    conApp = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_ERR);
    conApp.setThreshold(Level.WARN);
    conApp.activateOptions();
    impl.addAppender(conApp);
    impl.setLevel(Level.INFO);
    return new GridTestLog4jLogger(false);
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) RollingFileAppender(org.apache.log4j.RollingFileAppender) PatternLayout(org.apache.log4j.PatternLayout) LevelRangeFilter(org.apache.log4j.varia.LevelRangeFilter) IOException(java.io.IOException) IgniteLogger(org.apache.ignite.IgniteLogger) Logger(org.apache.log4j.Logger) GridTestLog4jLogger(org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger) GridTestLog4jLogger(org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger)

Example 27 with IgniteLogger

use of org.apache.ignite.IgniteLogger in project ignite by apache.

the class GridToStringBuilderSelfTest method testToStringPerformance.

/**
 * JUnit.
 */
public void testToStringPerformance() {
    TestClass1 obj = new TestClass1();
    IgniteLogger log = log();
    // Warm up.
    obj.toStringAutomatic();
    long start = System.currentTimeMillis();
    for (int i = 0; i < 100000; i++) obj.toStringManual();
    log.info("Manual toString() took: " + (System.currentTimeMillis() - start) + "ms");
    start = System.currentTimeMillis();
    for (int i = 0; i < 100000; i++) obj.toStringAutomatic();
    log.info("Automatic toString() took: " + (System.currentTimeMillis() - start) + "ms");
}
Also used : IgniteLogger(org.apache.ignite.IgniteLogger)

Example 28 with IgniteLogger

use of org.apache.ignite.IgniteLogger in project ignite by apache.

the class CacheContinuousQueryHandler method notifyCallback0.

/**
 * @param nodeId Node id.
 * @param ctx Kernal context.
 * @param entries Entries.
 */
private void notifyCallback0(UUID nodeId, final GridKernalContext ctx, Collection<CacheContinuousQueryEntry> entries) {
    final GridCacheContext cctx = cacheContext(ctx);
    if (cctx == null) {
        IgniteLogger log = ctx.log(CU.CONTINUOUS_QRY_LOG_CATEGORY);
        if (log.isDebugEnabled())
            log.debug("Failed to notify callback, cache is not found: " + cacheId);
        return;
    }
    final Collection<CacheEntryEvent<? extends K, ? extends V>> entries0 = new ArrayList<>(entries.size());
    for (CacheContinuousQueryEntry e : entries) {
        GridCacheDeploymentManager depMgr = cctx.deploy();
        ClassLoader ldr = depMgr.globalLoader();
        if (ctx.config().isPeerClassLoadingEnabled()) {
            GridDeploymentInfo depInfo = e.deployInfo();
            if (depInfo != null) {
                depMgr.p2pContext(nodeId, depInfo.classLoaderId(), depInfo.userVersion(), depInfo.deployMode(), depInfo.participants());
            }
        }
        try {
            e.unmarshal(cctx, ldr);
            Collection<CacheEntryEvent<? extends K, ? extends V>> evts = handleEvent(ctx, e);
            if (evts != null && !evts.isEmpty())
                entries0.addAll(evts);
        } catch (IgniteCheckedException ex) {
            if (ignoreClsNotFound)
                assert internal;
            else
                U.error(ctx.log(CU.CONTINUOUS_QRY_LOG_CATEGORY), "Failed to unmarshal entry.", ex);
        }
    }
    notifyLocalListener(entries0, returnValTrans);
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheDeploymentManager(org.apache.ignite.internal.processors.cache.GridCacheDeploymentManager) ArrayList(java.util.ArrayList) GridDeploymentInfo(org.apache.ignite.internal.managers.deployment.GridDeploymentInfo) IgniteLogger(org.apache.ignite.IgniteLogger) CacheEntryEvent(javax.cache.event.CacheEntryEvent)

Example 29 with IgniteLogger

use of org.apache.ignite.IgniteLogger in project ignite by apache.

the class GridCacheIoManager method handleMessage.

/**
 * @param nodeId Sender node ID.
 * @param cacheMsg Message.
 * @param msgHandlers Message handlers.
 * @param plc Message policy.
 */
@SuppressWarnings("unchecked")
private void handleMessage(UUID nodeId, GridCacheMessage cacheMsg, MessageHandlers msgHandlers, byte plc) {
    Lock lock = rw.readLock();
    lock.lock();
    try {
        int msgIdx = cacheMsg.lookupIndex();
        IgniteBiInClosure<UUID, GridCacheMessage> c = null;
        if (msgIdx >= 0) {
            Map<Integer, IgniteBiInClosure[]> idxClsHandlers0 = msgHandlers.idxClsHandlers;
            IgniteBiInClosure[] cacheClsHandlers = idxClsHandlers0.get(cacheMsg.handlerId());
            if (cacheClsHandlers != null)
                c = cacheClsHandlers[msgIdx];
        }
        if (c == null)
            c = msgHandlers.clsHandlers.get(new ListenerKey(cacheMsg.handlerId(), cacheMsg.getClass()));
        if (c == null) {
            if (processMissedHandler(nodeId, cacheMsg))
                return;
            IgniteLogger log = cacheMsg.messageLogger(cctx);
            StringBuilder msg0 = new StringBuilder("Received message without registered handler (will ignore) [");
            appendMessageInfo(cacheMsg, nodeId, msg0);
            msg0.append(", locTopVer=").append(cctx.exchange().readyAffinityVersion()).append(", msgTopVer=").append(cacheMsg.topologyVersion()).append(", desc=").append(descriptorForMessage(cacheMsg)).append(']');
            msg0.append(nl()).append("Registered listeners:");
            Map<Integer, IgniteBiInClosure[]> idxClsHandlers0 = msgHandlers.idxClsHandlers;
            for (Map.Entry<Integer, IgniteBiInClosure[]> e : idxClsHandlers0.entrySet()) msg0.append(nl()).append(e.getKey()).append("=").append(Arrays.toString(e.getValue()));
            if (cctx.kernalContext().isStopping()) {
                if (log.isDebugEnabled())
                    log.debug(msg0.toString());
            } else {
                U.error(log, msg0.toString());
                try {
                    cacheMsg.onClassError(new IgniteCheckedException("Failed to find message handler for message: " + cacheMsg));
                    processFailedMessage(nodeId, cacheMsg, c, plc);
                } catch (Exception e) {
                    U.error(log, "Failed to process failed message: " + e, e);
                }
            }
            return;
        }
        onMessage0(nodeId, cacheMsg, c, plc);
    } finally {
        lock.unlock();
    }
}
Also used : IgniteBiInClosure(org.apache.ignite.lang.IgniteBiInClosure) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException) StripedCompositeReadWriteLock(org.apache.ignite.internal.util.StripedCompositeReadWriteLock) Lock(java.util.concurrent.locks.Lock) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) UUID(java.util.UUID) IgniteLogger(org.apache.ignite.IgniteLogger) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 30 with IgniteLogger

use of org.apache.ignite.IgniteLogger in project ignite by apache.

the class GridCacheIoManager method addOrderedHandler.

/**
 * Adds ordered message handler.
 *
 * @param cctx Context.
 * @param cacheGrp {@code True} if cache group message, {@code false} if cache message.
 * @param topic Topic.
 * @param c Handler.
 */
@SuppressWarnings({ "unchecked" })
private void addOrderedHandler(GridCacheSharedContext cctx, boolean cacheGrp, Object topic, IgniteBiInClosure<UUID, ? extends GridCacheMessage> c) {
    MessageHandlers msgHandlers = cacheGrp ? grpHandlers : cacheHandlers;
    IgniteLogger log0 = log;
    if (msgHandlers.orderedHandlers.putIfAbsent(topic, c) == null) {
        cctx.gridIO().addMessageListener(topic, new OrderedMessageListener((IgniteBiInClosure<UUID, GridCacheMessage>) c));
        if (log0 != null && log0.isTraceEnabled())
            log0.trace("Registered ordered cache communication handler [topic=" + topic + ", handler=" + c + ']');
    } else if (log0 != null)
        U.warn(log0, "Failed to register ordered cache communication handler because it is already " + "registered for this topic [topic=" + topic + ", handler=" + c + ']');
}
Also used : IgniteBiInClosure(org.apache.ignite.lang.IgniteBiInClosure) IgniteLogger(org.apache.ignite.IgniteLogger)

Aggregations

IgniteLogger (org.apache.ignite.IgniteLogger)60 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)14 Ignite (org.apache.ignite.Ignite)12 IOException (java.io.IOException)10 LoggerResource (org.apache.ignite.resources.LoggerResource)10 IgniteException (org.apache.ignite.IgniteException)8 Map (java.util.Map)6 UUID (java.util.UUID)6 ClusterNode (org.apache.ignite.cluster.ClusterNode)6 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)6 IgniteInstanceResource (org.apache.ignite.resources.IgniteInstanceResource)6 HashMap (java.util.HashMap)5 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)5 IgniteBiInClosure (org.apache.ignite.lang.IgniteBiInClosure)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)4 URL (java.net.URL)3 Callable (java.util.concurrent.Callable)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3