org.apache.edgent.function.Functions.synchronizedConsumer()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(1.9k)|赞(0)|评价(0)|浏览(95)

本文整理了Java中org.apache.edgent.function.Functions.synchronizedConsumer()方法的一些代码示例,展示了Functions.synchronizedConsumer()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Functions.synchronizedConsumer()方法的具体详情如下:
包路径:org.apache.edgent.function.Functions
类名称:Functions
方法名:synchronizedConsumer

Functions.synchronizedConsumer介绍

[英]Return a thread-safe version of a Consumer function. If the function is guaranteed to be immutable (stateless) then the function is returned, as it is thread safe, otherwise a wrapper is returned that grabs synchronization on function when calling Consumer#accept(Object).
If function implements AutoCloseable then the function is assumed to be stateful and a thread-safe version is returned.
[中]返回使用者函数的线程安全版本。如果函数被保证是不可变的(无状态的),那么函数将返回,因为它是线程安全的,否则将返回一个包装器,在调用Consumer#accept(Object)时获取函数的同步。
如果函数实现了AutoCloseable,则假定该函数是有状态的,并返回线程安全版本。

代码示例

代码示例来源:origin: apache/incubator-edgent

@Override
  public TSink<T> sink(Consumer<T> sinker) {
    return sink(new Sink<>(Functions.synchronizedConsumer(sinker)));
  }
}

代码示例来源:origin: org.apache.edgent/edgent-spi-topology

@Override
public TStream<T> peek(Consumer<T> peeker) {
  peeker = Functions.synchronizedConsumer(peeker);
  connector.peek(new Peek<T>(peeker));
  return this;
}

代码示例来源:origin: org.apache.edgent/edgent-spi-topology

@Override
  public TSink<T> sink(Consumer<T> sinker) {
    return sink(new Sink<>(Functions.synchronizedConsumer(sinker)));
  }
}

代码示例来源:origin: apache/incubator-edgent

@Override
public TStream<T> peek(Consumer<T> peeker) {
  peeker = Functions.synchronizedConsumer(peeker);
  connector.peek(new Peek<T>(peeker));
  return this;
}

代码示例来源:origin: apache/incubator-edgent

assertSame(f1, Functions.synchronizedConsumer(f1));
assertSame(f2, Functions.synchronizedConsumer(f2));
assertNotSame(f3, Functions.synchronizedConsumer(f3));
Consumer<Integer> f4s = Functions.synchronizedConsumer(f4);
assertNotSame(f4, f4s);
f4s.accept(2421);
assertNotSame(f5,  Functions.synchronizedConsumer(f5));

相关文章