Search in sources :

Example 31 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.
     */
@SuppressWarnings("unchecked")
private void handleMessage(UUID nodeId, GridCacheMessage cacheMsg) {
    int msgIdx = cacheMsg.lookupIndex();
    IgniteBiInClosure<UUID, GridCacheMessage> c = null;
    if (msgIdx >= 0) {
        Map<Integer, IgniteBiInClosure[]> idxClsHandlers0 = idxClsHandlers;
        IgniteBiInClosure[] cacheClsHandlers = idxClsHandlers0.get(cacheMsg.cacheId());
        if (cacheClsHandlers != null)
            c = cacheClsHandlers[msgIdx];
    }
    if (c == null)
        c = clsHandlers.get(new ListenerKey(cacheMsg.cacheId(), cacheMsg.getClass()));
    if (c == null) {
        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(", cacheDesc=").append(cctx.cache().cacheDescriptor(cacheMsg.cacheId())).append(']');
        msg0.append(U.nl()).append("Registered listeners:");
        Map<Integer, IgniteBiInClosure[]> idxClsHandlers0 = idxClsHandlers;
        for (Map.Entry<Integer, IgniteBiInClosure[]> e : idxClsHandlers0.entrySet()) msg0.append(U.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());
        return;
    }
    onMessage0(nodeId, cacheMsg, c);
}
Also used : IgniteBiInClosure(org.apache.ignite.lang.IgniteBiInClosure) UUID(java.util.UUID) IgniteLogger(org.apache.ignite.IgniteLogger) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 32 with IgniteLogger

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

the class GridResourceLoggerInjector method resource.

/**
 * @param ann Annotation.
 * @param target Target.
 * @return Logger.
 */
@SuppressWarnings("IfMayBeConditional")
private IgniteLogger resource(LoggerResource ann, Object target) {
    Class<?> cls = ann.categoryClass();
    String cat = ann.categoryName();
    IgniteLogger rsrc = getResource();
    if (cls != null && cls != Void.class)
        rsrc = rsrc.getLogger(cls);
    else if (cat != null && !cat.isEmpty())
        rsrc = rsrc.getLogger(cat);
    else
        rsrc = rsrc.getLogger(target.getClass());
    return rsrc;
}
Also used : IgniteLogger(org.apache.ignite.IgniteLogger)

Example 33 with IgniteLogger

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

the class SensitiveInfoTestLoggerProxy method readResolve.

/**
 * Reconstructs object on unmarshalling.
 *
 * @return Reconstructed object.
 * @throws ObjectStreamException Thrown in case of unmarshalling error.
 */
protected Object readResolve() throws ObjectStreamException {
    try {
        IgniteBiTuple<String, Object> t = stash.get();
        Object ctgrR = t.get2();
        IgniteLogger log = IgnitionEx.localIgnite().log();
        return ctgrR != null ? log.getLogger(ctgrR) : log;
    } catch (IllegalStateException e) {
        throw U.withCause(new InvalidObjectException(e.getMessage()), e);
    } finally {
        stash.remove();
    }
}
Also used : InvalidObjectException(java.io.InvalidObjectException) IgniteLogger(org.apache.ignite.IgniteLogger)

Example 34 with IgniteLogger

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

the class GridCachePutAllTask method map.

/**
 * {@inheritDoc}
 */
@Override
public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> subgrid, @Nullable final Collection<Integer> data) {
    assert !subgrid.isEmpty();
    // Give preference to wanted node. Otherwise, take the first one.
    ClusterNode targetNode = F.find(subgrid, subgrid.get(0), new IgnitePredicate<ClusterNode>() {

        /**
         * {@inheritDoc}
         */
        @Override
        public boolean apply(ClusterNode e) {
            return preferredNode.equals(e.id());
        }
    });
    return Collections.singletonMap(new ComputeJobAdapter() {

        @LoggerResource
        private IgniteLogger log;

        @IgniteInstanceResource
        private Ignite ignite;

        @Override
        public Object execute() {
            if (DEBUG_DATA)
                log.info("Going to put data: " + data);
            else
                log.info("Going to put data [size=" + data.size() + ']');
            IgniteCache<Object, Object> cache = ignite.cache(cacheName);
            assert cache != null;
            HashMap<Integer, Integer> putMap = U.newLinkedHashMap(TX_BOUND);
            Iterator<Integer> it = data.iterator();
            int cnt = 0;
            final int RETRIES = 5;
            while (it.hasNext()) {
                Integer val = it.next();
                putMap.put(val, val);
                if (++cnt == TX_BOUND) {
                    if (DEBUG_DATA)
                        log.info("Putting keys to cache: " + putMap.keySet());
                    else
                        log.info("Putting keys to cache [size=" + putMap.size() + ']');
                    for (int i = 0; i < RETRIES; i++) {
                        try {
                            cache.putAll(putMap);
                            break;
                        } catch (CacheException e) {
                            if (i < RETRIES - 1)
                                log.info("Put error, will retry: " + e);
                            else
                                throw new IgniteException(e);
                        }
                    }
                    cnt = 0;
                    putMap = U.newLinkedHashMap(TX_BOUND);
                }
            }
            assert cnt < TX_BOUND;
            assert putMap.size() == (data.size() % TX_BOUND) : "putMap.size() = " + putMap.size();
            if (DEBUG_DATA)
                log.info("Putting keys to cache: " + putMap.keySet());
            else
                log.info("Putting keys to cache [size=" + putMap.size() + ']');
            for (int i = 0; i < RETRIES; i++) {
                try {
                    cache.putAll(putMap);
                    break;
                } catch (CacheException e) {
                    if (i < RETRIES - 1)
                        log.info("Put error, will retry: " + e);
                    else
                        throw new IgniteException(e);
                }
            }
            if (DEBUG_DATA)
                log.info("Finished putting data: " + data);
            else
                log.info("Finished putting data [size=" + data.size() + ']');
            return data;
        }
    }, targetNode);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) LoggerResource(org.apache.ignite.resources.LoggerResource) HashMap(java.util.HashMap) CacheException(javax.cache.CacheException) IgniteCache(org.apache.ignite.IgniteCache) ComputeJobAdapter(org.apache.ignite.compute.ComputeJobAdapter) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteException(org.apache.ignite.IgniteException) Iterator(java.util.Iterator) Ignite(org.apache.ignite.Ignite) IgniteLogger(org.apache.ignite.IgniteLogger)

Example 35 with IgniteLogger

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

the class JdbcBatchUpdateTask method doSingleUpdate.

/**
 * Performs update.
 *
 * @param cache Cache.
 * @param sqlText SQL text.
 * @param args Parameters.
 * @return Update counter.
 * @throws SQLException If failed.
 */
private Integer doSingleUpdate(IgniteCache<?, ?> cache, String sqlText, List<Object> args) throws SQLException {
    SqlFieldsQuery qry = new SqlFieldsQueryEx(sqlText, false);
    qry.setPageSize(fetchSize);
    qry.setLocal(locQry);
    qry.setCollocated(collocatedQry);
    qry.setDistributedJoins(distributedJoins);
    qry.setSchema(schemaName);
    qry.setArgs(args == null ? null : args.toArray());
    QueryCursorImpl<List<?>> qryCursor = (QueryCursorImpl<List<?>>) cache.withKeepBinary().query(qry);
    if (qryCursor.isQuery()) {
        throw createJdbcSqlException(getError("Query produced result set", qry), IgniteQueryErrorCode.STMT_TYPE_MISMATCH);
    }
    List<List<?>> rows = qryCursor.getAll();
    if (F.isEmpty(rows))
        return SUCCESS_NO_INFO;
    if (rows.size() != 1)
        throw new SQLException(getError("Expected single row for update operation result", qry));
    List<?> row = rows.get(0);
    if (F.isEmpty(row) || row.size() != 1)
        throw new SQLException(getError("Expected row size of 1 for update operation", qry));
    Object objRes = row.get(0);
    if (!(objRes instanceof Long))
        throw new SQLException(getError("Unexpected update result type", qry));
    Long longRes = (Long) objRes;
    if (longRes > Integer.MAX_VALUE) {
        IgniteLogger log = ignite.log();
        if (log != null)
            log.warning(getError("Query updated row counter (" + longRes + ") exceeds integer range", qry));
        return Integer.MAX_VALUE;
    }
    return longRes.intValue();
}
Also used : SQLException(java.sql.SQLException) SqlFieldsQueryEx(org.apache.ignite.internal.processors.cache.query.SqlFieldsQueryEx) List(java.util.List) QueryCursorImpl(org.apache.ignite.internal.processors.cache.QueryCursorImpl) IgniteLogger(org.apache.ignite.IgniteLogger) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery)

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