com.hazelcast.jet.pipeline.Sinks.socket()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(2.0k)|赞(0)|评价(0)|浏览(108)

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

Sinks.socket介绍

[英]Convenience for #socket(String,int,DistributedFunction,Charset) with Object.toString as the conversion function and UTF-8 as the charset.
[中]方便使用对象进行#套接字(字符串、int、DistributedFunction、字符集)。toString作为转换函数,UTF-8作为字符集。

代码示例

代码示例来源:origin: hazelcast/hazelcast-jet

/**
 * Convenience for {@link #socket(String, int, DistributedFunction,
 * Charset)} with {@code Object.toString} as the conversion function and
 * UTF-8 as the charset.
 */
@Nonnull
public static <T> Sink<T> socket(@Nonnull String host, int port) {
  return socket(host, port, Object::toString);
}

代码示例来源:origin: hazelcast/hazelcast-jet

/**
 * Convenience for {@link #socket(String, int, DistributedFunction,
 * Charset)} with UTF-8 as the charset.
 */
@Nonnull
public static <T> Sink<T> socket(
    @Nonnull String host,
    int port,
    @Nonnull DistributedFunction<? super T, ? extends String> toStringFn
) {
  return socket(host, port, toStringFn, UTF_8);
}

代码示例来源:origin: hazelcast/hazelcast-jet-code-samples

public static void main(String[] args) throws Exception {
    System.setProperty("hazelcast.logging.type", "log4j");

    NettyServer nettyServer = new NettyServer(PORT, DistributedConsumer.noop(), msg -> COUNTER.incrementAndGet());
    nettyServer.start();

    JetInstance jet = Jet.newJetInstance();
    Jet.newJetInstance();

    try {
      System.out.println("Populating map...");
      IMapJet<Integer, Integer> map = jet.getMap(SOURCE_NAME);
      IntStream.range(0, SOURCE_ITEM_COUNT).parallel().forEach(i -> map.put(i, i));

      Pipeline p = Pipeline.create();
      p.drawFrom(Sources.map(SOURCE_NAME))
       .drainTo(Sinks.socket(HOST, PORT, e -> e.getValue().toString(), UTF_8));

      System.out.println("Executing job...");
      jet.newJob(p).join();
    } finally {
      nettyServer.stop();
      Jet.shutdownAll();
    }

    System.out.println("Server read " + COUNTER.get() + " items from the socket.");
  }
}

相关文章