From 5003b67bf38e913ec358132d225f2416934b84ad Mon Sep 17 00:00:00 2001 From: emeroad Date: Fri, 17 Jun 2022 19:13:09 +0900 Subject: [PATCH] [#8939] Delete Counter class for jdk7 --- .../pinpoint/profiler/util/Java8Counter.java | 40 ------------ .../profiler/util/Java8CounterFactory.java | 32 --------- .../response/ReuseResponseTimeCollector.java | 26 ++++---- .../pinpoint/profiler/util/Counter.java | 28 -------- .../profiler/util/CounterFactory.java | 65 ------------------- .../pinpoint/profiler/util/Java6Counter.java | 40 ------------ 6 files changed, 11 insertions(+), 220 deletions(-) delete mode 100644 profiler-optional/profiler-optional-jdk8/src/main/java/com/navercorp/pinpoint/profiler/util/Java8Counter.java delete mode 100644 profiler-optional/profiler-optional-jdk8/src/main/java/com/navercorp/pinpoint/profiler/util/Java8CounterFactory.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/util/Counter.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/util/CounterFactory.java delete mode 100644 profiler/src/main/java/com/navercorp/pinpoint/profiler/util/Java6Counter.java diff --git a/profiler-optional/profiler-optional-jdk8/src/main/java/com/navercorp/pinpoint/profiler/util/Java8Counter.java b/profiler-optional/profiler-optional-jdk8/src/main/java/com/navercorp/pinpoint/profiler/util/Java8Counter.java deleted file mode 100644 index 725fce4d5b78..000000000000 --- a/profiler-optional/profiler-optional-jdk8/src/main/java/com/navercorp/pinpoint/profiler/util/Java8Counter.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2018 NAVER Corp. - * - * 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. - */ - -package com.navercorp.pinpoint.profiler.util; - -import java.util.concurrent.atomic.LongAdder; - -/** - * @author Woonduk Kang(emeroad) - */ -public class Java8Counter implements Counter { - private final LongAdder longAdder = new LongAdder(); - @Override - public void increment() { - longAdder.increment(); - } - - @Override - public void add(long x) { - longAdder.add(x); - } - - @Override - public long longValue() { - return longAdder.longValue(); - } -} diff --git a/profiler-optional/profiler-optional-jdk8/src/main/java/com/navercorp/pinpoint/profiler/util/Java8CounterFactory.java b/profiler-optional/profiler-optional-jdk8/src/main/java/com/navercorp/pinpoint/profiler/util/Java8CounterFactory.java deleted file mode 100644 index 5f407773d7bb..000000000000 --- a/profiler-optional/profiler-optional-jdk8/src/main/java/com/navercorp/pinpoint/profiler/util/Java8CounterFactory.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2018 NAVER Corp. - * - * 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. - */ - -package com.navercorp.pinpoint.profiler.util; - - -/** - * @author Woonduk Kang(emeroad) - */ -public class Java8CounterFactory implements CounterFactory.ObjectFactory { - - public Java8CounterFactory() { - } - - @Override - public Counter newInstance() { - return new Java8Counter(); - } -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/response/ReuseResponseTimeCollector.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/response/ReuseResponseTimeCollector.java index 91a136214ba7..5ba1ecaa655b 100644 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/response/ReuseResponseTimeCollector.java +++ b/profiler/src/main/java/com/navercorp/pinpoint/profiler/monitor/metric/response/ReuseResponseTimeCollector.java @@ -17,10 +17,9 @@ package com.navercorp.pinpoint.profiler.monitor.metric.response; import com.google.inject.Inject; -import com.navercorp.pinpoint.profiler.util.Counter; -import com.navercorp.pinpoint.profiler.util.CounterFactory; import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.LongAdder; /** * @author Taejin Koo @@ -46,8 +45,7 @@ public ResponseTimeValue resetAndGetValue() { final long totalValue = reset.getTotalValue(); final long maxValue = reset.getMaxValue(); final long transactionCount = reset.getTransactionCount(); - ResponseTimeValue result = new ResponseTimeValue0(totalValue, maxValue, transactionCount); - return result; + return new ResponseTimeValue0(totalValue, maxValue, transactionCount); } private ResponseTimeCollector reset() { @@ -58,13 +56,13 @@ private ResponseTimeCollector reset() { } private static class ResponseTimeCollector { - private final Counter totalValue; - private final Counter transactionCount; + private final LongAdder totalValue; + private final LongAdder transactionCount; private final AtomicLong maxValue = new AtomicLong(0); private ResponseTimeCollector() { - this.totalValue = CounterFactory.newCounter(); - this.transactionCount = CounterFactory.newCounter(); + this.totalValue = new LongAdder(); + this.transactionCount = new LongAdder(); } void add(long value) { @@ -136,14 +134,12 @@ public long getTransactionCount() { @Override public String toString() { - final StringBuilder sb = new StringBuilder("ResponseTimeValue0{"); - sb.append("totalResponseTime=").append(totalResponseTime); - sb.append(", transactionCount=").append(transactionCount); - sb.append(", maxResponseTime=").append(maxResponseTime); - sb.append('}'); - return sb.toString(); + return "ResponseTimeValue0{" + + "totalResponseTime=" + totalResponseTime + + ", maxResponseTime=" + maxResponseTime + + ", transactionCount=" + transactionCount + + '}'; } - } } diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/util/Counter.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/util/Counter.java deleted file mode 100644 index 8ff827218388..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/util/Counter.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2018 NAVER Corp. - * - * 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. - */ - -package com.navercorp.pinpoint.profiler.util; - -/** - * @author Woonduk Kang(emeroad) - */ -public interface Counter { - void increment(); - - void add(long x); - - long longValue(); -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/util/CounterFactory.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/util/CounterFactory.java deleted file mode 100644 index 4f57ef1f0855..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/util/CounterFactory.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2018 NAVER Corp. - * - * 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. - */ - -package com.navercorp.pinpoint.profiler.util; - -import com.navercorp.pinpoint.bootstrap.logging.PLogger; -import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory; -import com.navercorp.pinpoint.common.util.JvmUtils; -import com.navercorp.pinpoint.common.util.JvmVersion; - -import java.lang.reflect.Constructor; - -/** - * @author Woonduk Kang(emeroad) - */ -public class CounterFactory { - - private static final PLogger logger = PLoggerFactory.getLogger(CounterFactory.class.getName()); - - private static final ObjectFactory counterFactory = buildFactory(); - - private static ObjectFactory buildFactory() { - JvmVersion version = JvmUtils.getVersion(); - if (version.onOrAfter(JvmVersion.JAVA_8)) { - String counterName = "com.navercorp.pinpoint.profiler.util.Java8CounterFactory"; - try { - Class> counterClazz = (Class>) Class.forName(counterName, false, CounterFactory.class.getClassLoader()); - Constructor> constructor = counterClazz.getDeclaredConstructor(); - return constructor.newInstance(); - } catch (Exception e) { - logger.warn("{} not found", counterName , e); - } - } - return new Java6CounterFactory(); - } - - public static Counter newCounter() { - return counterFactory.newInstance(); - } - - interface ObjectFactory { - T newInstance(); - } - - private static class Java6CounterFactory implements ObjectFactory { - @Override - public Counter newInstance() { - return new Java6Counter(); - } - } - -} diff --git a/profiler/src/main/java/com/navercorp/pinpoint/profiler/util/Java6Counter.java b/profiler/src/main/java/com/navercorp/pinpoint/profiler/util/Java6Counter.java deleted file mode 100644 index 3f205f625569..000000000000 --- a/profiler/src/main/java/com/navercorp/pinpoint/profiler/util/Java6Counter.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2018 NAVER Corp. - * - * 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. - */ - -package com.navercorp.pinpoint.profiler.util; - -import com.navercorp.pinpoint.profiler.util.jdk.LongAdder; - -/** - * @author Woonduk Kang(emeroad) - */ -public class Java6Counter implements Counter { - private final LongAdder longAdder = new LongAdder(); - @Override - public void increment() { - longAdder.increment(); - } - - @Override - public void add(long x) { - longAdder.add(x); - } - - @Override - public long longValue() { - return longAdder.longValue(); - } -}