private Map<String, Supplier<AclLineMatchExpr>> createThunks( Map<String, IpAccessList> namedAcls) { ImmutableMap.Builder<String, Supplier<AclLineMatchExpr>> thunks = ImmutableMap.builder(); namedAcls.forEach( (name, acl) -> thunks.put(name, new NonRecursiveSupplier<>(() -> this.toAclLineMatchExpr(acl)))); return thunks.build(); }
ReferenceSourcesVisitor(Map<String, IpAccessList> namedAcls) { /** * Thunks used to include sources (on demand) referenced by ACLs referenced by PermittedByAcl * match exprs. NonRecursiveSupplier detects cyclic references and throws an exception rather * than going into an infinite loop. */ _namedAclThunks = toImmutableMap( namedAcls, Entry::getKey, entry -> new NonRecursiveSupplier<>( () -> { visit(entry.getValue()); return null; })); _referencedSources = ImmutableSet.builder(); }
public IpAccessListToBDD( @Nonnull BDDPacket pkt, @Nonnull BDDSourceManager bddSrcManager, @Nonnull HeaderSpaceToBDD headerSpaceToBDD, @Nonnull Map<String, IpAccessList> aclEnv) { /* * Use suppliers to convert each ACL in the environment on demand. Memoize to avoid converting * an ACL more than once. ACLs can refer to other ACLs in the environment, but if there is a * cyclic reference (direct or indirect), NonRecursiveSupplier will throw an exception (to avoid * going into an infinite loop). */ _aclEnv = new HashMap<>(); aclEnv.forEach( (name, acl) -> _aclEnv.put(name, Suppliers.memoize(new NonRecursiveSupplier<>(() -> toBdd(acl))))); _bddOps = new BDDOps(pkt.getFactory()); _bddSrcManager = bddSrcManager; _factory = pkt.getFactory(); _headerSpaceToBDD = headerSpaceToBDD; _pkt = pkt; }
public IpSpaceToBDD(BDDInteger var, Map<String, IpSpace> namedIpSpaces) { _bddInteger = var; _factory = var.getFactory(); _bddOps = new BDDOps(_factory); _namedIpSpaceBDDs = toImmutableMap( namedIpSpaces, Entry::getKey, entry -> Suppliers.memoize(new NonRecursiveSupplier<>(() -> this.visit(entry.getValue())))); }
@Test public void testNonReentrantSupplier() { Map<String, Supplier<String>> suppliers = new HashMap<>(); suppliers.put("foo", new NonRecursiveSupplier<>(() -> suppliers.get("bar").get())); suppliers.put("bar", new NonRecursiveSupplier<>(() -> suppliers.get("foo").get())); exception.expect(NonRecursiveSupplierException.class); suppliers.get("foo").get(); }
@Test public void testMemoize() { Map<String, Supplier<String>> suppliers = new HashMap<>(); suppliers.put( "foo", Suppliers.memoize(new NonRecursiveSupplier<>(() -> suppliers.get("bar").get()))); suppliers.put( "bar", Suppliers.memoize(new NonRecursiveSupplier<>(() -> suppliers.get("foo").get()))); exception.expect(NonRecursiveSupplierException.class); suppliers.get("foo").get(); } }