use of com.google.common.util.concurrent.ThreadFactoryBuilder in project eureka by Netflix.
the class TimedSupervisorTaskTest method setUp.
@Before
public void setUp() {
scheduler = Executors.newScheduledThreadPool(4, new ThreadFactoryBuilder().setNameFormat("DiscoveryClient-%d").setDaemon(true).build());
helperExecutor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10));
executor = new ThreadPoolExecutor(// corePoolSize
1, // maxPoolSize
3, // keepAliveTime
0, TimeUnit.SECONDS, // use direct handoff
new SynchronousQueue<Runnable>());
testTaskStartCounter = new AtomicLong(0);
testTaskSuccessfulCounter = new AtomicLong(0);
testTaskInterruptedCounter = new AtomicLong(0);
maxConcurrentTestTasks = new AtomicLong(0);
testTaskCounter = new AtomicLong(0);
}
use of com.google.common.util.concurrent.ThreadFactoryBuilder in project ribbon by Netflix.
the class MockHttpServer method before.
public void before(final Description description) throws Exception {
this.service = Executors.newFixedThreadPool(threadCount, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("TestHttpServer-%d").build());
InetSocketAddress inetSocketAddress = new InetSocketAddress("localhost", 0);
if (hasSsl) {
byte[] sampleTruststore1 = Base64.decode(TEST_TS1);
byte[] sampleKeystore1 = Base64.decode(TEST_KS1);
keystore = File.createTempFile("SecureAcceptAllGetTest", ".keystore");
truststore = File.createTempFile("SecureAcceptAllGetTest", ".truststore");
FileOutputStream keystoreFileOut = new FileOutputStream(keystore);
try {
keystoreFileOut.write(sampleKeystore1);
} finally {
keystoreFileOut.close();
}
FileOutputStream truststoreFileOut = new FileOutputStream(truststore);
try {
truststoreFileOut.write(sampleTruststore1);
} finally {
truststoreFileOut.close();
}
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(new FileInputStream(keystore), PASSWORD.toCharArray());
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(ks, PASSWORD.toCharArray());
KeyStore ts = KeyStore.getInstance("JKS");
ts.load(new FileInputStream(truststore), PASSWORD.toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(ts);
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
HttpsServer secureServer = HttpsServer.create(inetSocketAddress, 0);
secureServer.setHttpsConfigurator(new HttpsConfigurator(sc) {
public void configure(HttpsParameters params) {
SSLContext c = getSSLContext();
SSLParameters sslparams = c.getDefaultSSLParameters();
params.setSSLParameters(sslparams);
}
});
server = secureServer;
} else {
server = HttpServer.create(inetSocketAddress, 0);
}
server.setExecutor(service);
for (Entry<String, HttpHandler> handler : handlers.entrySet()) {
server.createContext(handler.getKey(), handler.getValue());
}
server.start();
localHttpServerPort = server.getAddress().getPort();
System.out.println(description.getClassName() + " TestServer is started: " + getServerUrl());
}
use of com.google.common.util.concurrent.ThreadFactoryBuilder in project reflections by ronmamo.
the class ConfigurationBuilder method useParallelExecutor.
/** sets the executor service used for scanning to ThreadPoolExecutor with core size as the given availableProcessors parameter.
* the executor service spawns daemon threads by default.
* <p>default is ThreadPoolExecutor with a single core */
public ConfigurationBuilder useParallelExecutor(final int availableProcessors) {
ThreadFactory factory = new ThreadFactoryBuilder().setDaemon(true).setNameFormat("org.reflections-scanner-%d").build();
setExecutorService(Executors.newFixedThreadPool(availableProcessors, factory));
return this;
}
use of com.google.common.util.concurrent.ThreadFactoryBuilder in project helios by spotify.
the class FastForwardReporterTest method setUp.
@Before
public void setUp() throws Exception {
final ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true).build();
this.executor = Executors.newSingleThreadScheduledExecutor(threadFactory);
this.reporter = new FastForwardReporter(ffwd, metricRegistry, executor, "helios.test", // these interval values do not matter for this test:
30, TimeUnit.SECONDS, Collections::emptyMap);
}
use of com.google.common.util.concurrent.ThreadFactoryBuilder in project helios by spotify.
the class FastForwardReporter method create.
/**
* Overload of {@link #create(MetricRegistry, Optional, String, int)} which allows for setting
* additional attributes in each reported metric.
*
* <p>The additional attributes are modeled as a Supplier to allow for attributes that might
* change values at runtime.
*/
public static FastForwardReporter create(MetricRegistry registry, Optional<HostAndPort> address, String metricKey, int intervalSeconds, Supplier<Map<String, String>> additionalAttributes) throws SocketException, UnknownHostException {
final FastForward ff;
if (address.isPresent()) {
ff = FastForward.setup(address.get().getHostText(), address.get().getPort());
} else {
ff = FastForward.setup();
}
final ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true).setNameFormat("fast-forward-reporter-%d").build();
final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(threadFactory);
return new FastForwardReporter(ff, registry, executorService, metricKey, intervalSeconds, TimeUnit.SECONDS, additionalAttributes);
}
Aggregations