• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java StopWatch类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.nifi.util.StopWatch的典型用法代码示例。如果您正苦于以下问题:Java StopWatch类的具体用法?Java StopWatch怎么用?Java StopWatch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



StopWatch类属于org.apache.nifi.util包,在下文中一共展示了StopWatch类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: enrich

import org.apache.nifi.util.StopWatch; //导入依赖的package包/类
@Override
public FlowFile enrich(ProcessSession session, FlowFile ff, Map<String, String> content) {
    StopWatch stopWatch = new StopWatch(true);
    ff = session.write(ff, new StreamingJSONAppender(this.field, makeJsonFromMapOfJsons(content)));
    session.getProvenanceReporter().modifyContent(ff, stopWatch.getElapsed(TimeUnit.MILLISECONDS));
    return ff;
}
 
开发者ID:qntfy,项目名称:nifi-redis,代码行数:8,代码来源:JSONFlowFileEnricherImpl.java


示例2: CheckedStopWatch

import org.apache.nifi.util.StopWatch; //导入依赖的package包/类
CheckedStopWatch(long timeframeMilliseconds) {
    this.stopWatch = new StopWatch(false);
    this.timeFrameMilliseconds = timeframeMilliseconds;
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:5,代码来源:AttributeTumblingWindow.java


示例3: onTrigger

import org.apache.nifi.util.StopWatch; //导入依赖的package包/类
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
    FlowFile flowFile = session.get();
    if ( flowFile == null ) {
        return;
    }

    final String outboundAddress = context.getProperty(OUTBOUND_ADDRESS).evaluateAttributeExpressions(flowFile).getValue();

    try {
        final StopWatch stopWatch = new StopWatch(true);

        final byte[] buffer = new byte[(int) flowFile.getSize()];

        session.read(flowFile, new InputStreamCallback() {
            @Override
            public void process(final InputStream in) throws IOException {
                StreamUtils.fillBuffer(in, buffer, false);
            }
        });

        // TODO detect flowFile MIME_TYPE and convert buffer into JSON, String or buffer
        JsonObject message = new JsonObject(new String(buffer, StandardCharsets.UTF_8));

        if(attributePattern != null) {
            DeliveryOptions options = new DeliveryOptions();
            for(String attributeName : flowFile.getAttributes().keySet()) {
                if (attributePattern != null && attributePattern.matcher(attributeName).matches()) {
                    options.addHeader(attributeName, flowFile.getAttribute(attributeName));
                }
            }
            put(outboundAddress, message, options);
        } else {
            put(outboundAddress, message);
        }

        final Map<String, String> attributes = new HashMap<>();
        attributes.put("eventbus.address", outboundAddress);
        flowFile = session.putAllAttributes(flowFile, attributes);
        session.getProvenanceReporter().receive(flowFile, outboundAddress, "sent message to eventBus", stopWatch.getElapsed(TimeUnit.MILLISECONDS));
        getLogger().info("Successfully sent {} ({}) to EventBuss in {} millis", new Object[]{flowFile, flowFile.getSize(), stopWatch.getElapsed(TimeUnit.MILLISECONDS)});
        session.transfer(flowFile, REL_SUCCESS);
    } catch (ProcessException pe) {
        getLogger().error("Failed to send {} to EventBuss due to {}; routing to failure", new Object[] {flowFile, pe.toString()}, pe);
        session.transfer(flowFile, REL_FAILURE);
    }
}
 
开发者ID:xmlking,项目名称:nifi-websocket,代码行数:48,代码来源:PublishEventBus.java


示例4: onTrigger

import org.apache.nifi.util.StopWatch; //导入依赖的package包/类
@Override
    public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
        final ProcessorLog logger = getLogger();
        final Message<JsonObject> message = messageQueue.poll();
        if (message == null) {
            context.yield();
            return;
        }

        FlowFile flowFile = session.create();
        try {
            final StopWatch stopWatch = new StopWatch(true);

            flowFile = session.write(flowFile, new OutputStreamCallback() {
                @Override
                public void process(final OutputStream out) throws IOException {
                    out.write(message.body().encode().getBytes(StandardCharsets.UTF_8));
                }
            });

            if (flowFile.getSize() == 0L) {
                session.remove(flowFile);
            } else {
                final Map<String, String> attributes = new HashMap<>();

                if (headerPattern != null) {
                    MultiMap headers = message.headers();
                    headers.names()
                            .stream()
                            .filter(headerName -> headerPattern.matcher(headerName).matches())
                            .forEach(headerName -> attributes.put(headerName, headers.get(headerName)));

//                    attributes.putAll(
//                        headers.entries()
//                                .stream()
//                                .filter(entry -> headerPattern.matcher(entry.getKey()).matches())
//                                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
//                    );
                }
                attributes.put(CoreAttributes.MIME_TYPE.key(), "application/json");
                attributes.put(CoreAttributes.FILENAME.key(), flowFile.getAttribute(CoreAttributes.FILENAME.key()) + ".json");
                attributes.put("eventbus.address", message.address());

                flowFile = session.putAllAttributes(flowFile, attributes);
                session.getProvenanceReporter().receive(flowFile, message.address(), "received eventBus message", stopWatch.getElapsed(TimeUnit.MILLISECONDS));
                getLogger().info("Successfully received {} ({}) from EventBus in {} millis", new Object[]{flowFile, flowFile.getSize(), stopWatch.getElapsed(TimeUnit.MILLISECONDS)});
                session.transfer(flowFile, REL_SUCCESS);
            }
        } catch (Exception e) {
            session.remove(flowFile);
            throw e;
        }
    }
 
开发者ID:xmlking,项目名称:nifi-websocket,代码行数:54,代码来源:GetEventBus.java



注:本文中的org.apache.nifi.util.StopWatch类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RCData类代码示例发布时间:2022-05-23
下一篇:
Java PlaceNode2类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap