@SuppressWarnings("nls")
    protected void processQueue() {
        try {
            RequestMetric metric = queue.take();
            QueryRunner run = new QueryRunner(ds);

            Calendar cal = Calendar.getInstance();
            cal.setTimeZone(TimeZone.getTimeZone("UTC"));
            cal.setTime(metric.getRequestStart());

            long rstart = cal.getTimeInMillis();
            long rend = metric.getRequestEnd().getTime();
            long duration = metric.getRequestDuration();
            cal.set(Calendar.MILLISECOND, 0);
            cal.set(Calendar.SECOND, 0);
            long minute = cal.getTimeInMillis();
            cal.set(Calendar.MINUTE, 0);
            long hour = cal.getTimeInMillis();
            cal.set(Calendar.HOUR_OF_DAY, 0);
            long day = cal.getTimeInMillis();
            cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
            long week = cal.getTimeInMillis();
            cal.set(Calendar.DAY_OF_MONTH, 1);
            long month = cal.getTimeInMillis();
            String api_org_id = metric.getApiOrgId();
            String api_id = metric.getApiId();
            String api_version = metric.getApiVersion();
            String client_org_id = metric.getClientOrgId();
            String client_id = metric.getClientId();
            String client_version = metric.getClientVersion();
            String plan = metric.getPlanId();
            String user_id = metric.getUser();
            String rtype = null;
            if (metric.isFailure()) {
                rtype = "failure";
            } else if (metric.isError()) {
                rtype = "error";
            }
            long bytes_up = metric.getBytesUploaded();
            long bytes_down = metric.getBytesDownloaded();

            // Now insert a row for the metric.
            // plan quoted as it's a keyword in MSSQL.
            run.update("INSERT INTO gw_requests ("
                    + "rstart, rend, duration, month, week, day, hour, minute, "
                    + "api_org_id, api_id, api_version, "
                    + "client_org_id, client_id, client_version, `plan`, "
                    + "user_id, resp_type, bytes_up, bytes_down) VALUES ("
                    + "?, ?, ?, ?, ?, ?, ?, ?,"
                    + "?, ?, ?,"
                    + "?, ?, ?, ?,"
                    + "?, ?, ?, ?)",
                    rstart, rend, duration, month, week, day, hour, minute,
                    api_org_id, api_id, api_version,
                    client_org_id, client_id, client_version, plan,
                    user_id, rtype, bytes_up, bytes_down
                    );
        } catch (InterruptedException ie) {
            // This means that the thread was stopped.
            LOGGER.trace("Metrics was stopped {0}", ie.getMessage());
        } catch (Exception e) {
            LOGGER.error(e, "An unexpected error occurred when attempting to add a metric "
                + "to the database. {0}", e.getMessage());
        }
    }
Process the next item in the queue.
gateway/engine/jdbc/src/main/java/io/apiman/gateway/engine/jdbc/JdbcMetrics.java