Search in sources :

Example 1 with FileLoaderRuntimeException

use of org.apache.phoenix.pherf.exception.FileLoaderRuntimeException in project phoenix by apache.

the class MonitorManager method readResults.

/**
     * This method should really only be used for testing
     *
     * @return List < {@link org.apache.phoenix.pherf.result.Result} >
     * @throws IOException
     */
public synchronized List<Result> readResults() throws Exception {
    ResultHandler handler = null;
    try {
        if (resultHandler.isClosed()) {
            handler = new CSVFileResultHandler();
            handler.setResultFileDetails(ResultFileDetails.CSV);
            handler.setResultFileName(PherfConstants.MONITOR_FILE_NAME);
            return handler.read();
        } else {
            return resultHandler.read();
        }
    } catch (Exception e) {
        throw new FileLoaderRuntimeException("Could not close monitor results.", e);
    } finally {
        if (handler != null) {
            handler.close();
        }
    }
}
Also used : CSVFileResultHandler(org.apache.phoenix.pherf.result.impl.CSVFileResultHandler) FileLoaderRuntimeException(org.apache.phoenix.pherf.exception.FileLoaderRuntimeException) ResultHandler(org.apache.phoenix.pherf.result.ResultHandler) CSVFileResultHandler(org.apache.phoenix.pherf.result.impl.CSVFileResultHandler) IOException(java.io.IOException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) FileLoaderRuntimeException(org.apache.phoenix.pherf.exception.FileLoaderRuntimeException)

Example 2 with FileLoaderRuntimeException

use of org.apache.phoenix.pherf.exception.FileLoaderRuntimeException in project phoenix by apache.

the class MonitorManager method execute.

@Override
public Runnable execute() {
    return new Runnable() {

        @Override
        public void run() {
            try {
                while (!shouldStop()) {
                    isRunning.set(true);
                    List rowValues = new ArrayList<String>();
                    synchronized (resultHandler) {
                        for (MonitorDetails monitorDetails : MONITOR_DETAILS_LIST) {
                            rowValues.clear();
                            try {
                                StandardMBean bean = new StandardMBean(monitorDetails.getMonitor(), Monitor.class);
                                Calendar calendar = new GregorianCalendar();
                                rowValues.add(monitorDetails);
                                rowValues.add(((Monitor) bean.getImplementation()).getStat());
                                rowValues.add(DateUtil.DEFAULT_MS_DATE_FORMATTER.format(calendar.getTime()));
                                Result result = new Result(ResultFileDetails.CSV, ResultFileDetails.CSV_MONITOR.getHeader().toString(), rowValues);
                                resultHandler.write(result);
                            } catch (Exception e) {
                                throw new FileLoaderRuntimeException("Could not log monitor result.", e);
                            }
                            rowCount.getAndIncrement();
                        }
                        try {
                            resultHandler.flush();
                            Thread.sleep(getMonitorFrequency());
                        } catch (Exception e) {
                            Thread.currentThread().interrupt();
                            e.printStackTrace();
                        }
                    }
                }
            } finally {
                try {
                    isRunning.set(false);
                    if (resultHandler != null) {
                        resultHandler.close();
                    }
                } catch (Exception e) {
                    throw new FileLoaderRuntimeException("Could not close monitor results.", e);
                }
            }
        }
    };
}
Also used : FileLoaderRuntimeException(org.apache.phoenix.pherf.exception.FileLoaderRuntimeException) StandardMBean(javax.management.StandardMBean) IOException(java.io.IOException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) FileLoaderRuntimeException(org.apache.phoenix.pherf.exception.FileLoaderRuntimeException) Result(org.apache.phoenix.pherf.result.Result)

Aggregations

IOException (java.io.IOException)2 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)2 FileLoaderRuntimeException (org.apache.phoenix.pherf.exception.FileLoaderRuntimeException)2 StandardMBean (javax.management.StandardMBean)1 Result (org.apache.phoenix.pherf.result.Result)1 ResultHandler (org.apache.phoenix.pherf.result.ResultHandler)1 CSVFileResultHandler (org.apache.phoenix.pherf.result.impl.CSVFileResultHandler)1