HBASE-26921 Rewrite the counting cells part in TestMultiVersions (#4316)
[hbase.git] / hbase-thrift / src / test / java / org / apache / hadoop / hbase / thrift / ThriftServerRunner.java
bloba006045e71b24c43c8f713cc1093c4b29f3011a7
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.thrift;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22 import java.io.Closeable;
23 import java.io.IOException;
25 /**
26 * Run ThriftServer with passed arguments. Access the exception thrown after we complete run -- if
27 * an exception thrown -- via {@link #getRunException()}}. Call close to shutdown this Runner
28 * and hosted {@link ThriftServer}.
30 class ThriftServerRunner extends Thread implements Closeable {
31 private static final Logger LOG = LoggerFactory.getLogger(ThriftServerRunner.class);
32 Exception exception = null;
33 private final ThriftServer thriftServer;
34 private final String [] args;
36 ThriftServerRunner(ThriftServer thriftServer, String [] args) {
37 this.thriftServer = thriftServer;
38 this.args = args;
39 LOG.info("thriftServer={}, args={}", getThriftServer(), args);
42 ThriftServer getThriftServer() {
43 return this.thriftServer;
46 /**
47 * @return Empty unless {@link #run()} threw an exception; if it did, access it here.
49 Exception getRunException() {
50 return this.exception;
53 @Override public void run() {
54 try {
55 this.thriftServer.run(this.args);
56 } catch (Exception e) {
57 LOG.error("Run threw an exception", e);
58 this.exception = e;
62 @Override public void close() throws IOException {
63 LOG.info("Stopping {}", this);
64 this.thriftServer.stop();