Search in sources :

Example 61 with T2

use of org.apache.ignite.internal.util.typedef.T2 in project ignite by apache.

the class IgniteCachePeekModesAbstractTest method offheapKeys.

/**
     * @param nodeIdx Node index.
     * @return Tuple with primary and backup keys.
     */
private T2<List<Integer>, List<Integer>> offheapKeys(int nodeIdx) {
    GridCacheAdapter<Integer, String> internalCache = ((IgniteKernal) ignite(nodeIdx)).context().cache().internalCache(DEFAULT_CACHE_NAME);
    // TODO GG-11148.
    Iterator<Map.Entry<Integer, String>> offheapIt = Collections.EMPTY_MAP.entrySet().iterator();
    //        if (internalCache.context().isNear())
    //            offheapIt = internalCache.context().near().dht().context().swap().lazyOffHeapIterator(false);
    //        else
    //            offheapIt = internalCache.context().swap().lazyOffHeapIterator(false);
    Affinity aff = ignite(nodeIdx).affinity(DEFAULT_CACHE_NAME);
    ClusterNode node = ignite(nodeIdx).cluster().localNode();
    List<Integer> primary = new ArrayList<>();
    List<Integer> backups = new ArrayList<>();
    while (offheapIt.hasNext()) {
        Map.Entry<Integer, String> e = offheapIt.next();
        if (aff.isPrimary(node, e.getKey()))
            primary.add(e.getKey());
        else {
            assertTrue(aff.isBackup(node, e.getKey()));
            backups.add(e.getKey());
        }
    }
    return new T2<>(primary, backups);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) ArrayList(java.util.ArrayList) Affinity(org.apache.ignite.cache.affinity.Affinity) Map(java.util.Map) T2(org.apache.ignite.internal.util.typedef.T2)

Example 62 with T2

use of org.apache.ignite.internal.util.typedef.T2 in project ignite by apache.

the class GridCacheNearMultiNodeSelfTest method testMappings.

/**  Test mappings. */
public void testMappings() {
    mapDebug = false;
    int cnt = 100000;
    Map<UUID, T2<Set<Integer>, Set<Integer>>> map = mapKeys(cnt);
    for (ClusterNode n : grid(0).cluster().nodes()) {
        Set<Integer> primary = map.get(n.id()).get1();
        Set<Integer> backups = map.get(n.id()).get2();
        if (backups == null)
            backups = Collections.emptySet();
        info("Grid node [primaries=" + primary.size() + ", backups=" + backups.size() + ']');
        assert !F.isEmpty(primary);
        assertEquals(backups.size(), cnt - primary.size());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClusterNode(org.apache.ignite.cluster.ClusterNode) UUID(java.util.UUID) T2(org.apache.ignite.internal.util.typedef.T2)

Example 63 with T2

use of org.apache.ignite.internal.util.typedef.T2 in project ignite by apache.

the class IgfsServerManagerIpcEndpointRegistrationAbstractSelfTest method checkRegisteredIpcEndpoints.

/**
     * Counts all registered IPC endpoints.
     *
     * @return Tuple2 where (tcp endpoints count, shmem endpoints count).
     * @throws Exception If failed.
     */
protected T2<Integer, Integer> checkRegisteredIpcEndpoints() throws Exception {
    GridKernalContext ctx = ((IgniteKernal) grid()).context();
    int tcp = 0;
    int shmem = 0;
    for (GridPortRecord record : ctx.ports().records()) {
        if (record.clazz() == IpcSharedMemoryServerEndpoint.class)
            shmem++;
        else if (record.clazz() == IpcServerTcpEndpoint.class)
            tcp++;
    }
    return new T2<>(tcp, shmem);
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridKernalContext(org.apache.ignite.internal.GridKernalContext) GridPortRecord(org.apache.ignite.internal.processors.port.GridPortRecord) IpcServerTcpEndpoint(org.apache.ignite.internal.util.ipc.loopback.IpcServerTcpEndpoint) IpcServerTcpEndpoint(org.apache.ignite.internal.util.ipc.loopback.IpcServerTcpEndpoint) IpcSharedMemoryServerEndpoint(org.apache.ignite.internal.util.ipc.shmem.IpcSharedMemoryServerEndpoint) T2(org.apache.ignite.internal.util.typedef.T2)

Example 64 with T2

use of org.apache.ignite.internal.util.typedef.T2 in project ignite by apache.

the class WebSessionFilter method doFilterV1.

/**
     * @param httpReq Request.
     * @param res Response.
     * @param chain Filter chain.
     * @return Session ID.
     * @throws IOException In case of I/O error.
     * @throws ServletException In case of servlet error.
     * @throws CacheException In case of other error.
     */
private String doFilterV1(HttpServletRequest httpReq, ServletResponse res, FilterChain chain) throws IOException, ServletException, CacheException {
    WebSession cached = null;
    String sesId = httpReq.getRequestedSessionId();
    if (sesId != null) {
        sesId = transformSessionId(sesId);
        for (int i = 0; i < retries; i++) {
            try {
                cached = cache.get(sesId);
                break;
            } catch (CacheException | IgniteException | IllegalStateException e) {
                handleLoadSessionException(sesId, i, e);
            }
        }
        if (cached != null) {
            if (log.isDebugEnabled())
                log.debug("Using cached session for ID: " + sesId);
            if (cached.isNew())
                cached = new WebSession(cached.getId(), cached, false);
        } else {
            if (log.isDebugEnabled())
                log.debug("Cached session was invalidated and doesn't exist: " + sesId);
            HttpSession ses = httpReq.getSession(false);
            if (ses != null) {
                try {
                    ses.invalidate();
                } catch (IllegalStateException ignore) {
                // Session was already invalidated.
                }
            }
            cached = createSession(httpReq);
        }
    } else
        cached = createSession(httpReq);
    assert cached != null;
    sesId = cached.getId();
    cached.servletContext(ctx);
    cached.filter(this);
    cached.resetUpdates();
    cached.genSes(httpReq.getSession(false));
    httpReq = new RequestWrapper(httpReq, cached);
    chain.doFilter(httpReq, res);
    HttpSession ses = httpReq.getSession(false);
    if (ses != null && ses instanceof WebSession) {
        Collection<T2<String, Object>> updates = ((WebSession) ses).updates();
        if (updates != null)
            updateAttributes(transformSessionId(sesId), updates, ses.getMaxInactiveInterval());
    }
    return sesId;
}
Also used : CacheException(javax.cache.CacheException) IgniteException(org.apache.ignite.IgniteException) HttpSession(javax.servlet.http.HttpSession) HttpServletRequestWrapper(javax.servlet.http.HttpServletRequestWrapper) T2(org.apache.ignite.internal.util.typedef.T2)

Aggregations

T2 (org.apache.ignite.internal.util.typedef.T2)64 ArrayList (java.util.ArrayList)25 HashMap (java.util.HashMap)24 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)19 Map (java.util.Map)15 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)15 ClusterNode (org.apache.ignite.cluster.ClusterNode)14 UUID (java.util.UUID)13 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)13 Ignite (org.apache.ignite.Ignite)13 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)12 List (java.util.List)11 HashSet (java.util.HashSet)10 ConcurrentMap (java.util.concurrent.ConcurrentMap)10 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)8 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 CacheException (javax.cache.CacheException)7 CacheEntryEvent (javax.cache.event.CacheEntryEvent)7 Set (java.util.Set)5