/*- * ============LICENSE_START======================================================= * onap * ================================================================================ * Copyright (C) 2016 - 2017 ONAP * ================================================================================ * Licensed 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. * ============LICENSE_END========================================================= */ package org.onap.ccsdk.sli.core.dblib.pm; import java.util.Iterator; import java.util.Properties; import java.util.Set; import java.util.Timer; import java.util.TimerTask; import java.util.TreeSet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.atomic.AtomicLong; public class PollingWorker implements Runnable { private Logger LOGGER = LoggerFactory.getLogger(PollingWorker.class); private static PollingWorker self = null; private LinkedBlockingQueue tasks = new LinkedBlockingQueue(100); private long interval = 1000L; private Thread worker = null; private AtomicLong[] counters = null; private int[] bucketUnit = null; private static boolean enabled = false; private Timer timer = null; public static void post(long starttime){ PollingWorker temp = self; if(temp != null && enabled) { temp.register(new TestSample(starttime)); } } public static void createInistance(Properties props){ self = new PollingWorker(props); } private PollingWorker(Properties ctxprops){ if(ctxprops==null || ctxprops.getProperty("org.onap.ccsdk.dblib.pm") == null){ enabled = false; } else { if("true".equalsIgnoreCase((String)ctxprops.getProperty("org.onap.ccsdk.dblib.pm"))){ enabled = true; } else { enabled = false; } } interval = Long.parseLong(( ctxprops == null || ctxprops.getProperty("org.onap.ccsdk.dblib.pm.interval") == null) ? "60" : (String)ctxprops.getProperty("org.onap.ccsdk.dblib.pm.interval")); // '0' bucket is to count exceptions String sampling[] = ((ctxprops == null || ctxprops.getProperty("org.onap.ccsdk.dblib.pm.sampling")==null) ? "0,2,5,10,20,50,100" : (String)ctxprops.getProperty("org.onap.ccsdk.dblib.pm.sampling")).split(","); if(enabled){ bucketUnit = new int[sampling.length]; for(int i=0, max = bucketUnit.length; i x.starttime) return -1; if(endtime > x.endtime) return -1; return 0; } return 1; } } }