/**
 * Copyright 2015 Palantir Technologies
 *
 * Licensed under the BSD-3 License (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://opensource.org/licenses/BSD-3-Clause
 *
 * 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 com.palantir.atlasdb.keyvalue.rocksdb.impl;

import org.rocksdb.RocksDB;
import org.rocksdb.RocksDBException;

import com.google.common.base.Throwables;
import com.palantir.atlasdb.keyvalue.rocksdb.impl.ColumnFamilyMap.ColumnFamily;

public class RocksDbMXBeanImpl implements RocksDbMXBean {
    private final RocksDB db;
    private final ColumnFamilyMap cfs;

    public RocksDbMXBeanImpl(RocksDB db, ColumnFamilyMap cfs) {
        this.db = db;
        this.cfs = cfs;
    }

    @Override
    public String[] listTableNames() {
        return cfs.getTableNames().toArray(new String[0]);
    }

    @Override
    public void forceCompaction() {
        try {
            db.compactRange();
        } catch (RocksDBException e) {
            throw Throwables.propagate(e);
        }
    }

    @Override
    public void forceCompaction(String tableName) {
        try (ColumnFamily cf = cfs.get(tableName)) {
            if (cf == null) {
                throw new IllegalArgumentException("Unknown table name: " + tableName);
            }
            db.compactRange(cf.getHandle());
        } catch (RocksDBException e) {
            throw Throwables.propagate(e);
        }
    }

    @Override
    public String getProperty(String property) {
        try {
            return db.getProperty(property);
        } catch (RocksDBException e) {
            throw Throwables.propagate(e);
        }
    }

    @Override
    public String getProperty(String tableName, String property) {
        try (ColumnFamily cf = cfs.get(tableName)) {
            if (cf == null) {
                throw new IllegalArgumentException("Unknown table name: " + tableName);
            }
            return db.getProperty(cf.getHandle(), property);
        } catch (RocksDBException e) {
            throw Throwables.propagate(e);
        }
    }
}

@@ -1250,126 +1250,171 @@
     
-try %7B%0A            db.compactRange();%0A        %7D catch (RocksDBException e) %7B%0A            throw Throwables.propagate(e);
+for (String tableName : cfs.getTableNames()) %7B%0A            if (cfs.getTableNames().contains(tableName)) %7B%0A                forceCompaction(tableName);%0A            %7D
 %0A   
@@ -1897,95 +1897,158 @@
     
+S
 tr
-y %7B%0A            return db.getProperty(property);%0A        %7D catch (RocksDBException 
+ingBuilder s = new StringBuilder();%0A        for (String tableName : cfs.getTableNames()) %7B%0A            if (cfs.getTableNames().contains(tableNam
 e)
+)
  %7B%0A 
@@ -2062,36 +2062,98 @@
     
+   
-throw Throwables.propagate(e
+ s.append(tableName).append(%22 : %22).append(getProperty(tableName, property)).append(%22%5Cn%22
 );%0A 
@@ -2151,33 +2151,76 @@
 (%22%5Cn%22);%0A        
+ 
-%7D
+   %7D%0A        %7D%0A        return s.toString();
 %0A    %7D%0A%0A    @Ove

fix rocks mxbean to do bulk operations as intended