sruehl commented on code in PR #747: URL: https://github.com/apache/plc4x/pull/747#discussion_r1072118836
########## plc4j/tools/connection-cache/src/main/java/org/apache/plc4x/java/utils/cache/CachedPlcConnectionManager.java: ########## @@ -0,0 +1,119 @@ +/* + * 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 + * + * https://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.plc4x.java.utils.cache; + +import org.apache.plc4x.java.DefaultPlcDriverManager; +import org.apache.plc4x.java.api.PlcConnection; +import org.apache.plc4x.java.api.PlcConnectionManager; +import org.apache.plc4x.java.api.authentication.PlcAuthentication; +import org.apache.plc4x.java.api.exceptions.PlcConnectionException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.time.Duration; +import java.util.*; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +public class CachedPlcConnectionManager implements PlcConnectionManager { + + private static final Logger LOG = LoggerFactory.getLogger(CachedPlcConnectionManager.class); + + private final PlcConnectionManager connectionManager; + private final Duration maxLeaseTime; + private final Duration maxWaitTime; + + private final Map<String, ConnectionContainer> connectionContainers; + + public static Builder getBuilder() { + return new Builder(new DefaultPlcDriverManager()); + } + + public static Builder getBuilder(PlcConnectionManager connectionManager) { + return new Builder(connectionManager); + } + + public CachedPlcConnectionManager(PlcConnectionManager connectionManager, Duration maxLeaseTime, Duration maxWaitTime) { + this.connectionManager = connectionManager; + this.maxLeaseTime = maxLeaseTime; + this.maxWaitTime = maxWaitTime; + this.connectionContainers = new HashMap<>(); + } + + public PlcConnection getConnection(String url) throws PlcConnectionException { + ConnectionContainer connectionContainer; + synchronized (connectionContainers) { Review Comment: an alternative here might be the use of the ConcurrentHashMap -- 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: dev-unsubscr...@plc4x.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org