/** * @param cls Class. * @param annCls Annotation class. * @return Annotation (or {@code null}). */ @Nullable public static <T extends Annotation> T getAnnotation(Class<?> cls, Class<T> annCls) { ConcurrentMap<Class<? extends Annotation>, GridTuple<Annotation>> clsAnns = anns.get(cls); if (clsAnns == null) { ConcurrentMap<Class<? extends Annotation>, GridTuple<Annotation>> old = anns.putIfAbsent(cls, clsAnns = new ConcurrentHashMap<>()); if (old != null) clsAnns = old; } GridTuple<T> ann = (GridTuple<T>)clsAnns.get(annCls); if (ann == null) { ann = F.t(U.getAnnotation(cls, annCls)); clsAnns.putIfAbsent(annCls, (GridTuple<Annotation>)ann); } return ann.get(); }
@Override public void handle(File file) { foundFiles.add(file); Long fileLastModified = clssTstampCache.get(file); if (fileLastModified == null || fileLastModified != file.lastModified()) { clssTstampCache.put(file, fileLastModified = file.lastModified()); changed.set(true); } // Calculate last modified file in folder. if (fileLastModified > lastModified.get()) lastModified.set(fileLastModified); } };
/** {@inheritDoc} */ @Nullable @Override public V load(final K key) { try { final GridTuple<V> val = new GridTuple<>(); doInvoke(new IgniteInClosureX<BinaryRawWriterEx>() { @Override public void applyx(BinaryRawWriterEx writer) throws IgniteCheckedException { writer.writeByte(OP_LOAD); writer.writeLong(session()); writer.writeString(ses.cacheName()); writer.writeObject(key); } }, new IgniteInClosureX<BinaryRawReaderEx>() { @Override public void applyx(BinaryRawReaderEx reader) { val.set((V)reader.readObjectDetached()); } }); return val.get(); } catch (IgniteCheckedException e) { throw new CacheLoaderException(e); } }
mem = 90; final GridTuple<String> evicted = new GridTuple<>(); assertNull(evicted.get()); assertNull(evicted.get()); assertEquals(k2, evicted.get()); evicted.set(null); assertNull(evicted.get()); assertEquals(k1, evicted.get()); evicted.set(null); assertNull(evicted.get()); assertEquals(k1, evicted.get()); evicted.set(null);
@Override public void applyx(BinaryRawReaderEx reader) { val.set((V)reader.readObjectDetached()); } });
/** * Factory method returning new tuple with given parameter. * * @param v Parameter for tuple. * @param <V> Type of the tuple. * @return Newly created tuple. */ public static <V> GridTuple<V> t(@Nullable V v) { return new GridTuple<>(v); }
mem = 90; final GridTuple<String> evicted = new GridTuple<>(); assertNull(evicted.get()); assertNull(evicted.get()); assertEquals(k2, evicted.get()); evicted.set(null); assertNull(evicted.get()); assertEquals(k1, evicted.get()); evicted.set(null); assertNull(evicted.get()); assertEquals(k1, evicted.get()); evicted.set(null);
@Override public void onMessage(UUID nodeId, Object msg, byte plc) { assert nodeId != null; assert msg != null; synchronized (qryMux) { if (!(msg instanceof GridDeploymentResponse)) { U.error(log, "Received unknown peer class loading response [node=" + nodeId + ", msg=" + msg + ']'); } else res.set((GridDeploymentResponse)msg); qryMux.notifyAll(); } } };
/** * Factory method returning empty tuple. * * @param <V> Type of the tuple. * @return Newly created empty tuple. */ @Deprecated public static <V> GridTuple<V> t1() { return new GridTuple<>(); }
/** * Retrieves {@code IGNITE_HOME} property. The property is retrieved from system * properties or from environment in that order. * * @return {@code IGNITE_HOME} property. */ @Nullable public static String getIgniteHome() { GridTuple<String> ggHomeTup = ggHome; String ggHome0; if (ggHomeTup == null) { synchronized (IgniteUtils.class) { // Double check. ggHomeTup = ggHome; if (ggHomeTup == null) { // Resolve Ignite installation home directory. ggHome = F.t(ggHome0 = resolveProjectHome()); if (ggHome0 != null) System.setProperty(IGNITE_HOME, ggHome0); } else ggHome0 = ggHomeTup.get(); } } else ggHome0 = ggHomeTup.get(); return ggHome0; }
@Override public void onEvict(int part, int hash, byte[] k, byte[] v) { String key = new String(k); evicted.set(key); }
final GridTuple<GridDeploymentResponse> res = new GridTuple<>(); while (res.get() == null && timeout > 0) { qryMux.wait(timeout); if (res.get() == null) { U.warn(log, "Failed to receive peer response from node within duration [node=" + dstNode.id() + ", duration=" + (U.currentTimeMillis() - start) + ']'); log.debug("Received peer loading response [node=" + dstNode.id() + ", res=" + res.get() + ']'); return res.get();
@Override protected GridTuple<Integer> initialValue() { return new GridTuple<>(0); } };
/** * @param cls Class to get annotation for. * @param annCls Annotation class. * @return Annotation value. * @param <T> Annotation class. */ public <T extends Annotation> T annotation(Class<?> cls, Class<T> annCls) { ConcurrentMap<Class<? extends Annotation>, GridTuple<Annotation>> clsAnns = anns.get(cls); if (clsAnns == null) { ConcurrentMap<Class<? extends Annotation>, GridTuple<Annotation>> old = anns.putIfAbsent(cls, clsAnns = new ConcurrentHashMap<>()); if (old != null) clsAnns = old; } GridTuple<T> ann = (GridTuple<T>)clsAnns.get(annCls); if (ann == null) { ann = F.t(U.getAnnotation(cls, annCls)); clsAnns.putIfAbsent(annCls, (GridTuple<Annotation>)ann); } return ann.get(); }
@Override public void onEvict(int part, int hash, byte[] k, byte[] v) { String key = new String(k); evicted.set(key); }
/** {@inheritDoc} */ @Nullable @Override public V load(final K key) { try { final GridTuple<V> val = new GridTuple<>(); doInvoke(new IgniteInClosureX<BinaryRawWriterEx>() { @Override public void applyx(BinaryRawWriterEx writer) throws IgniteCheckedException { writer.writeByte(OP_LOAD); writer.writeLong(session()); writer.writeString(ses.cacheName()); writer.writeObject(key); } }, new IgniteInClosureX<BinaryRawReaderEx>() { @Override public void applyx(BinaryRawReaderEx reader) { val.set((V)reader.readObjectDetached()); } }); return val.get(); } catch (IgniteCheckedException e) { throw new CacheLoaderException(e); } }
/** * JUnit. */ @Test public void testGridTupleAsIterable() { String str = "A test string"; Iterable<String> tpl = new GridTuple<>(str); Iterator<String> iter = tpl.iterator(); assert iter != null; List<Object> elems = new ArrayList<>(); while (iter.hasNext()) elems.add(iter.next()); assert elems.size() == 1; assert str.equals(elems.get(0)); try { iter.next(); fail("NoSuchElementException must have been thrown."); } catch (NoSuchElementException e) { info("Caught expected exception: " + e); } }
/** * @param cls Class to create new instance of (using default constructor). * @return New instance. * @throws IgniteCheckedException If failed. */ @Nullable public <T> T newInstance(Class<T> cls) throws IgniteCheckedException { assert cls != null; GridTuple<Constructor<?>> t = dfltCtorsCache.get(cls); if (t == null) { try { Constructor<T> ctor = cls.getDeclaredConstructor(); if (ctor != null && !ctor.isAccessible()) ctor.setAccessible(true); dfltCtorsCache.putIfAbsent(cls, t = F.<Constructor<?>>t(ctor)); } catch (NoSuchMethodException e) { throw new IgniteCheckedException("Failed to find empty constructor for class: " + cls, e); } } Constructor<?> ctor = t.get(); if (ctor == null) return null; try { return (T)ctor.newInstance(); } catch (InstantiationException | InvocationTargetException | IllegalAccessException e) { throw new IgniteCheckedException("Failed to create new instance for class: " + cls, e); } }