rdblue commented on a change in pull request #166: Update Hive Metastore tables for Spark URL: https://github.com/apache/incubator-iceberg/pull/166#discussion_r277902535
########## File path: hive/src/main/java/org/apache/iceberg/hive/ClientPool.java ########## @@ -0,0 +1,141 @@ +/* + * 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.iceberg.hive; + +import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.io.Closeable; +import java.io.IOException; +import java.util.Deque; +import java.util.function.Consumer; + +abstract class ClientPool<C, E extends Exception> implements Closeable { + private static final Logger LOG = LoggerFactory.getLogger(ClientPool.class); + + private final int poolSize; + private final Deque<C> clients; + private final Consumer<C> reconnectFunc; + private final Class<E> reconnectExc; + private final Consumer<C> closeFunc; + private final Object signal = new Object(); + private volatile int currentSize; + private boolean closed; + private int runs = 0; + + ClientPool(int poolSize, Consumer<C> reconnectFunc, Class<E> reconnectExc, Consumer<C> closeFunc) { + this.poolSize = poolSize; + this.reconnectFunc = reconnectFunc; + this.reconnectExc = reconnectExc; + this.closeFunc = closeFunc; + this.clients = Lists.newLinkedList(); + this.currentSize = 0; + this.closed = false; + } + + interface Action<R, C, E extends Exception> { + R run(C client) throws E; + } + + public <R> R run(Action<R, C, E> action) throws E, InterruptedException { + runs += 1; + C client = get(); + try { + return action.run(client); + + } catch (Exception exc) { + if (reconnectExc.isInstance(exc)) { Review comment: It depends on other uses. This is fine for now, so I'd prefer to keep it simple until we have more uses. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
