Skip to content

Commit 85e2647

Browse files
authored
Merge pull request #104 from shokakucarrier/1.x
remove o11yphant from weft, adjusted isBlank with alternative code
2 parents c8ed10b + b6ff893 commit 85e2647

4 files changed

Lines changed: 14 additions & 212 deletions

File tree

pom.xml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
<projectEmail>https://github.com/Commonjava/weft</projectEmail>
4545
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4646
<plugin.jacoco.skip>false</plugin.jacoco.skip>
47-
<o11yphantVersion>1.9.2</o11yphantVersion>
4847
<weldVersion>3.1.9.Final</weldVersion>
4948
<annotationVersion>1.3.2</annotationVersion>
5049
</properties>
@@ -58,11 +57,6 @@
5857
<type>pom</type>
5958
<scope>import</scope>
6059
</dependency>
61-
<dependency>
62-
<groupId>org.commonjava.util</groupId>
63-
<artifactId>o11yphant-metrics-api</artifactId>
64-
<version>${o11yphantVersion}</version>
65-
</dependency>
6660
<dependency>
6761
<groupId>javax.annotation</groupId>
6862
<artifactId>javax.annotation-api</artifactId>
@@ -72,12 +66,6 @@
7266
</dependencyManagement>
7367

7468
<dependencies>
75-
<!-- metrics support-->
76-
<dependency>
77-
<groupId>org.commonjava.util</groupId>
78-
<artifactId>o11yphant-metrics-api</artifactId>
79-
</dependency>
80-
8169
<dependency>
8270
<groupId>javax.inject</groupId>
8371
<artifactId>javax.inject</artifactId>

src/main/java/org/commonjava/cdi/util/weft/PoolWeftExecutorService.java

Lines changed: 10 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
package org.commonjava.cdi.util.weft;
1717

1818
import org.commonjava.cdi.util.weft.exception.PoolOverloadException;
19-
import org.commonjava.o11yphant.metrics.api.MetricRegistry;
20-
import org.commonjava.o11yphant.metrics.api.Timer;
2119
import org.slf4j.Logger;
2220
import org.slf4j.LoggerFactory;
2321

@@ -40,18 +38,12 @@
4038
import java.util.function.Function;
4139
import java.util.stream.Collectors;
4240

43-
import static org.commonjava.o11yphant.metrics.util.NameUtils.name;
44-
4541
/**
4642
* Created by jdcasey on 1/3/17.
4743
*/
4844
public class PoolWeftExecutorService
4945
implements WeftExecutorService, ScheduledExecutorService
5046
{
51-
private static final String TIMER = "timer";
52-
53-
private static final String METER = "meter";
54-
5547
private static final int DEFAULT_THREAD_COUNT = 2;
5648

5749
private static final float DEFAULT_LOAD_FACTOR = 10f;
@@ -68,41 +60,33 @@ public class PoolWeftExecutorService
6860

6961
private final boolean loadSensitive;
7062

71-
private final MetricRegistry metricRegistry;
72-
73-
private final String metricPrefix;
74-
7563
private Set<ThreadContextualizer> contextualizers;
7664

7765
private final AtomicLong load = new AtomicLong( 0L );
7866

7967

8068
public PoolWeftExecutorService( String name, ThreadPoolExecutor delegate )
8169
{
82-
this( name, delegate, DEFAULT_THREAD_COUNT, DEFAULT_LOAD_FACTOR, DEFAULT_LOAD_SENSITIVE, null, null,
70+
this( name, delegate, DEFAULT_THREAD_COUNT, DEFAULT_LOAD_FACTOR, DEFAULT_LOAD_SENSITIVE,
8371
Collections.emptySet() );
8472
}
8573

8674
public PoolWeftExecutorService( final String name, ThreadPoolExecutor delegate, final Integer threadCount,
87-
final Float maxLoadFactor, boolean loadSensitive,
88-
final MetricRegistry metricRegistry, final String metricPrefix )
75+
final Float maxLoadFactor, boolean loadSensitive )
8976
{
90-
this( name, delegate, threadCount, maxLoadFactor, loadSensitive, metricRegistry, metricPrefix,
77+
this( name, delegate, threadCount, maxLoadFactor, loadSensitive,
9178
Collections.emptySet() );
9279
}
9380

9481
public PoolWeftExecutorService( final String name, ThreadPoolExecutor delegate, final Integer threadCount,
9582
final Float maxLoadFactor, boolean loadSensitive,
96-
final MetricRegistry metricRegistry, final String metricPrefix,
9783
Iterable<ThreadContextualizer> contextualizers )
9884
{
9985
this.name = name;
10086
this.delegate = delegate;
10187
this.threadCount = threadCount;
10288
this.maxLoadFactor = maxLoadFactor;
10389
this.loadSensitive = loadSensitive;
104-
this.metricRegistry = metricRegistry;
105-
this.metricPrefix = metricPrefix;
10690
this.contextualizers = new HashSet<>();
10791
contextualizers.forEach( c -> this.contextualizers.add( c ) );
10892
}
@@ -175,7 +159,7 @@ private void verifyLoad()
175159
throw new PoolOverloadException( getName(), getLoadFactor(), getCurrentLoad(), maxLoadFactor, getThreadCount() );
176160
}
177161
}
178-
162+
179163
@Override
180164
public <T> Future<T> submit( Callable<T> callable )
181165
{
@@ -313,52 +297,6 @@ private <T> ScheduledFuture<T> asScheduled( Function<ScheduledExecutorService, S
313297
}
314298
}
315299

316-
private <T> Callable<T> timeCallable( Callable<T> callable )
317-
{
318-
return (Callable<T>) ()->{
319-
if( metricRegistry != null )
320-
{
321-
metricRegistry.meter( name( metricPrefix, "call", METER ) ).mark();
322-
Timer.Context context = metricRegistry.timer( name( metricPrefix, "call", TIMER ) ).time();
323-
try
324-
{
325-
return callable.call();
326-
}
327-
finally
328-
{
329-
context.stop();
330-
}
331-
}
332-
else
333-
{
334-
return callable.call();
335-
}
336-
};
337-
}
338-
339-
private Runnable timeRunnable( Runnable runnable )
340-
{
341-
return ()->{
342-
if( metricRegistry != null )
343-
{
344-
metricRegistry.meter( name( metricPrefix, "run", METER ) ).mark();
345-
Timer.Context context = metricRegistry.timer( name( metricPrefix, "run", TIMER ) ).time();
346-
try
347-
{
348-
runnable.run();
349-
}
350-
finally
351-
{
352-
context.stop();
353-
}
354-
}
355-
else
356-
{
357-
runnable.run();
358-
}
359-
};
360-
}
361-
362300
private <T> Collection<Callable<T>> wrapAll( Collection<? extends Callable<T>> collection )
363301
{
364302
ThreadContext ctx = ThreadContext.getContext( false );
@@ -369,7 +307,7 @@ private <T> Collection<Callable<T>> wrapAll( Collection<? extends Callable<T>> c
369307
setContext( extractedContext );
370308
Logger logger = LoggerFactory.getLogger( getClass() );
371309
logger.debug( "Using ThreadContext: {} (saving: {}) in {}", ctx, old, Thread.currentThread().getName() );
372-
return timeCallable((Callable<T>) () -> {
310+
return (Callable<T>) () -> {
373311
try
374312
{
375313
return callable.call();
@@ -381,7 +319,7 @@ private <T> Collection<Callable<T>> wrapAll( Collection<? extends Callable<T>> c
381319
clearBridgedContext();
382320
load.decrementAndGet();
383321
}
384-
});
322+
};
385323
} ).collect( Collectors.toList() );
386324
}
387325

@@ -390,7 +328,7 @@ private Runnable wrapRunnable( Runnable runnable )
390328
ThreadContext ctx = ThreadContext.getContext( false );
391329
Map<String, Object> extractedContext = extractContext();
392330
load.incrementAndGet();
393-
return timeRunnable(()->{
331+
return ()->{
394332
ThreadContext old = ThreadContext.setContext( ctx );
395333
setContext( extractedContext );
396334
Logger logger = LoggerFactory.getLogger( getClass() );
@@ -407,15 +345,15 @@ private Runnable wrapRunnable( Runnable runnable )
407345
clearBridgedContext();
408346
load.decrementAndGet();
409347
}
410-
});
348+
};
411349
}
412350

413351
private <T> Callable<T> wrapCallable( Callable<T> callable )
414352
{
415353
ThreadContext ctx = ThreadContext.getContext( false );
416354
Map<String, Object> extractedContext = extractContext();
417355
load.incrementAndGet();
418-
return timeCallable((Callable<T>) ()->{
356+
return (Callable<T>) ()->{
419357
ThreadContext old = ThreadContext.setContext( ctx );
420358
setContext( extractedContext );
421359
Logger logger = LoggerFactory.getLogger( getClass() );
@@ -431,7 +369,7 @@ private <T> Callable<T> wrapCallable( Callable<T> callable )
431369
clearBridgedContext();
432370
load.decrementAndGet();
433371
}
434-
});
372+
};
435373
}
436374

437375
private void clearBridgedContext()

src/main/java/org/commonjava/cdi/util/weft/WeftPoolBoy.java

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@
1616
package org.commonjava.cdi.util.weft;
1717

1818
import org.commonjava.cdi.util.weft.config.WeftConfig;
19-
import org.commonjava.o11yphant.metrics.api.Gauge;
20-
import org.commonjava.o11yphant.metrics.api.MetricRegistry;
2119
import org.slf4j.Logger;
2220
import org.slf4j.LoggerFactory;
2321

24-
import javax.annotation.PostConstruct;
2522
import javax.annotation.PreDestroy;
2623
import javax.enterprise.context.ApplicationScoped;
2724
import javax.enterprise.inject.Instance;
@@ -36,11 +33,9 @@
3633
import java.util.concurrent.ThreadPoolExecutor;
3734
import java.util.concurrent.TimeUnit;
3835

39-
import static org.apache.commons.lang3.StringUtils.isBlank;
4036
import static org.commonjava.cdi.util.weft.config.DefaultWeftConfig.DEFAULT_MAX_LOAD_FACTOR;
4137
import static org.commonjava.cdi.util.weft.config.DefaultWeftConfig.DEFAULT_PRIORITY;
4238
import static org.commonjava.cdi.util.weft.config.DefaultWeftConfig.DEFAULT_THREADS;
43-
import static org.commonjava.o11yphant.metrics.util.NameUtils.name;
4439

4540
@ApplicationScoped
4641
public class WeftPoolBoy
@@ -54,29 +49,14 @@ public class WeftPoolBoy
5449
@Inject
5550
private WeftConfig config;
5651

57-
@Inject
58-
private Instance<MetricRegistry> metricRegistryInstance;
59-
60-
private MetricRegistry metricRegistry;
61-
6252
@Inject
6353
private Instance<ThreadContextualizer> contextualizers;
6454

6555
protected WeftPoolBoy(){}
6656

67-
public WeftPoolBoy( WeftConfig config, MetricRegistry registry )
57+
public WeftPoolBoy( WeftConfig config )
6858
{
6959
this.config = config;
70-
this.metricRegistry = registry;
71-
}
72-
73-
@PostConstruct
74-
public void init()
75-
{
76-
if ( !metricRegistryInstance.isUnsatisfied() )
77-
{
78-
this.metricRegistry = metricRegistryInstance.get();
79-
}
8060
}
8161

8262
public WeftExecutorService getPool( final String key )
@@ -140,7 +120,7 @@ public synchronized WeftExecutorService getPool( final ExecutorConfig ec, final
140120
{
141121
int threadCount = ec.threads();
142122
String name = ec.named();
143-
if ( isBlank( name ) )
123+
if ( name == null || name.trim().isEmpty() )
144124
{
145125
name = DUMMY_NAME;
146126
}
@@ -215,34 +195,18 @@ else if ( threadCount > 0 )
215195
svc = (ThreadPoolExecutor) Executors.newCachedThreadPool( fac );
216196
}
217197

218-
String metricPrefix = name( config.getNodePrefix(), "weft.ThreadPoolExecutor", name );
219-
220-
service = new PoolWeftExecutorService( name, svc, threadCount, maxLoadFactor, loadSensitive, metricRegistry,
221-
metricPrefix, contextualizers );
198+
service = new PoolWeftExecutorService( name, svc, threadCount, maxLoadFactor, loadSensitive,
199+
contextualizers );
222200

223201
// TODO: Wrapper ThreadPoolExecutor that wraps Runnables to store/copy MDC when it gets created/started.
224202

225203
addPool( service );
226-
registerMetrics( metricPrefix, service );
227204
}
228205

229206
return service;
230207
}
231208

232209

233-
private void registerMetrics( String prefix, WeftExecutorService pool )
234-
{
235-
if ( metricRegistry != null )
236-
{
237-
metricRegistry.register( name( prefix, "corePoolSize" ), (Gauge<Integer>) () -> pool.getCorePoolSize() );
238-
metricRegistry.register( name( prefix, "activeThreads" ), (Gauge<Integer>) () -> pool.getActiveCount() );
239-
metricRegistry.register( name( prefix, "loadFactor" ), (Gauge<Double>) () -> pool.getLoadFactor() );
240-
metricRegistry.register( name( prefix, "currentLoad" ), (Gauge<Long>) () -> pool.getCurrentLoad() );
241-
242-
metricRegistry.registerHealthCheck( name( prefix, pool.getName() ), new WeftPoolHealthCheck( pool ) );
243-
}
244-
}
245-
246210
public Map<String, WeftExecutorService> getPools()
247211
{
248212
Map<String, WeftExecutorService> result = new HashMap<>( pools );

0 commit comments

Comments
 (0)