ryan-highley commented on code in PR #15088: URL: https://github.com/apache/camel/pull/15088#discussion_r1714157232
########## components/camel-tahu/src/main/java/org/apache/camel/component/tahu/CamelBdSeqManager.java: ########## @@ -0,0 +1,93 @@ +/* + * 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.camel.component.tahu; + +import java.io.File; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; + +import org.apache.commons.io.FileUtils; +import org.eclipse.tahu.message.BdSeqManager; +import org.eclipse.tahu.message.model.EdgeNodeDescriptor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; + +public final class CamelBdSeqManager implements BdSeqManager { + + private static final Logger LOG = LoggerFactory.getLogger(CamelBdSeqManager.class); + + private static final Charset bdSeqNumFileCharset = StandardCharsets.UTF_8; + + private final File bdSeqNumFile; + + private final Marker loggingMarker; + + CamelBdSeqManager(EdgeNodeDescriptor edgeNodeDescriptor) { + loggingMarker = MarkerFactory.getMarker(edgeNodeDescriptor.getDescriptorString()); + LOG.trace(loggingMarker, "CamelBdSeqManager constructor called"); + + String bdSeqNumFileName = FileUtils.getTempDirectoryPath() + "/CamelTahuTemp/" + + edgeNodeDescriptor.getDescriptorString() + "/bdSeqMgr"; + + bdSeqNumFile = new File(bdSeqNumFileName); + + LOG.trace(loggingMarker, "CamelBdSeqManager constructor complete"); + } + + // This method is NOT intended to increment the stored value, only to retrieve it + @Override + public long getNextDeathBdSeqNum() { + LOG.trace(loggingMarker, "BdSeqManager getNextDeathBdSeqNum called"); + try { + long bdSeqNum = 0L; + if (bdSeqNumFile.exists() && FileUtils.sizeOf(bdSeqNumFile) > 0L) { + String bdSeqFileContents = FileUtils.readFileToString(bdSeqNumFile, bdSeqNumFileCharset); + + bdSeqNum = normalizeBdSeq(Long.parseLong(bdSeqFileContents)); + + LOG.debug(loggingMarker, "Next Death bdSeq number: {}", bdSeqNum); + } + return bdSeqNum; + } catch (Exception e) { + LOG.debug(loggingMarker, "Failed to get the bdSeq number from the persistent directory", e); + storeNextDeathBdSeqNum(0); Review Comment: Updated to `warn` The exception is passed to the Logger so the condition would be logged with the IOException or NumberFormatException cause. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org