Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 610B9200C1B for ; Tue, 14 Feb 2017 18:49:50 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 5FAB6160B5F; Tue, 14 Feb 2017 17:49:50 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id A8EC8160B45 for ; Tue, 14 Feb 2017 18:49:49 +0100 (CET) Received: (qmail 90550 invoked by uid 500); 14 Feb 2017 17:49:48 -0000 Mailing-List: contact issues-help@nifi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@nifi.apache.org Delivered-To: mailing list issues@nifi.apache.org Received: (qmail 90541 invoked by uid 99); 14 Feb 2017 17:49:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Feb 2017 17:49:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B1990DFCA3; Tue, 14 Feb 2017 17:49:48 +0000 (UTC) From: markap14 To: issues@nifi.apache.org Reply-To: issues@nifi.apache.org References: In-Reply-To: Subject: [GitHub] nifi pull request #1493: NIFI-3356: Initial implementation of writeahead pro... Content-Type: text/plain Message-Id: <20170214174948.B1990DFCA3@git1-us-west.apache.org> Date: Tue, 14 Feb 2017 17:49:48 +0000 (UTC) archived-at: Tue, 14 Feb 2017 17:49:50 -0000 Github user markap14 commented on a diff in the pull request: https://github.com/apache/nifi/pull/1493#discussion_r101097703 --- Diff: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/claim/ContentClaimWriteCache.java --- @@ -0,0 +1,168 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.nifi.controller.repository.claim; + +import java.io.BufferedOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Map; +import java.util.Queue; + +import org.apache.nifi.controller.repository.ContentRepository; +import org.apache.nifi.stream.io.ByteCountingOutputStream; + +public class ContentClaimWriteCache { + private final ContentRepository contentRepo; + private final Map streamMap = new HashMap<>(); + private final Queue queue = new LinkedList<>(); + private final int bufferSize; + + public ContentClaimWriteCache(final ContentRepository contentRepo) { + this(contentRepo, 8192); + } + + public ContentClaimWriteCache(final ContentRepository contentRepo, final int bufferSize) { + this.contentRepo = contentRepo; + this.bufferSize = bufferSize; + } + + public void reset() throws IOException { + try { + forEachStream(OutputStream::close); + } finally { + streamMap.clear(); + queue.clear(); + } + } + + public ContentClaim getContentClaim() throws IOException { + final ContentClaim contentClaim = queue.poll(); + if (contentClaim != null) { + contentRepo.incrementClaimaintCount(contentClaim); + return contentClaim; + } + + final ContentClaim claim = contentRepo.create(false); + registerStream(claim); + return claim; + } + + private ByteCountingOutputStream registerStream(final ContentClaim contentClaim) throws IOException { + final OutputStream out = contentRepo.write(contentClaim); + final OutputStream buffered = new BufferedOutputStream(out, bufferSize); + final ByteCountingOutputStream bcos = new ByteCountingOutputStream(buffered); + streamMap.put(contentClaim.getResourceClaim(), bcos); + return bcos; + } + + public OutputStream write(final ContentClaim claim) throws IOException { --- End diff -- I called it write() to mimic the naming using in ContentRepository, as this made the transition of StandardProcessSession a little easier to comprehend. At least that was my intention :) --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---