public class ParallelClient
extends java.lang.Object
ParallelTaskBuilder
after a prepareGet functions. The Parallel
Task builder is to build a parallel task.
This is more a wrapper class and does not hold object specific resources. You
may create a single or multiple instances.
Only call releaseExternalResources()
before your app
shutdown and when you no longer need to use it. Will mark as closed after it is closed
isClosed
Will auto reinitialize if is closed.
<dependency>
<groupId>io.parallec</groupId>
<artifactId>parallec-core</artifactId>
<version>0.9.0</version>
</dependency>
Here is a complete runnable code.
import io.parallec.core.*;
import java.util.Map;
ParallelClient pc= new ParallelClient();
pc.prepareHttpGet("/validateInternals.html")
.setConcurrency(1000)
.setTargetHostsFromString("www.parallec.io www.jeffpei.com www.restcommander.com")
.execute(new ParallecResponseHandler() {
public void onCompleted(ResponseOnSingleTask res,
Map<String, Object> responseContext) {
String cpu = new FilterRegex(".*<td>CPU-Usage-Percent</td>\\s*<td>(.*?)</td>.*")
.filter(res.getResponseContent());
System.out.println("cpu:" + cpu + " host: " + res.getHost() );
}
});
pc.releaseExternalResources();
Modifier and Type | Field and Description |
---|---|
HttpClientStore |
httpClientStore
The http client store.
|
static java.util.concurrent.atomic.AtomicBoolean |
isClosed
The is closed is marked when all resources are released/not initialized.
|
private static org.slf4j.Logger |
logger
The logger.
|
ParallelTaskManager |
taskManager
The task manager.
|
TcpUdpSshPingResourceStore |
tcpSshPingResourceStore
The tcp client store.
|
Constructor and Description |
---|
ParallelClient()
Instantiates a new parallel client.
|
Modifier and Type | Method and Description |
---|---|
void |
cleanInprogressJobMap()
Clean inprogress job map.
|
void |
cleanWaitTaskQueue()
Clean wait task queue.
|
HttpClientStore |
getHttpClientStore()
Gets the http client store.
|
int |
getRunningJobCount()
Gets the running job count.
|
void |
initialize()
Initialize.
|
java.lang.String |
logHealth()
Log memory health.
|
ParallelTaskBuilder |
prepareHttpDelete(java.lang.String url)
Prepare a parallel HTTP DELETE Task.
|
ParallelTaskBuilder |
prepareHttpGet(java.lang.String url)
Prepare a parallel HTTP GET Task.
|
ParallelTaskBuilder |
prepareHttpHead(java.lang.String url)
Prepare a parallel HTTP HEAD Task.
|
ParallelTaskBuilder |
prepareHttpOptions(java.lang.String url)
Prepare a parallel HTTP OPTION Task.
|
ParallelTaskBuilder |
prepareHttpPost(java.lang.String url)
Prepare a parallel HTTP POST Task.
|
ParallelTaskBuilder |
prepareHttpPut(java.lang.String url)
Prepare a parallel HTTP PUT Task.
|
ParallelTaskBuilder |
preparePing()
Prepare a parallel PING Task.
|
ParallelTaskBuilder |
prepareSsh()
Prepare a parallel SSH Task.
|
ParallelTaskBuilder |
prepareTcp(java.lang.String command)
Prepare a parallel TCP Task.
|
ParallelTaskBuilder |
prepareUdp(java.lang.String command)
Prepare a parallel UDP Task.
|
void |
reinitHttpClients()
Reinit http clients.
|
void |
reinitIfClosed()
Auto re-initialize external resourced
if resources have been already released.
|
void |
releaseExternalResources()
Releases the external resources that this object depends on.
|
void |
setCustomClientFast(com.ning.http.client.AsyncHttpClient client)
Sets the custom fast client in the httpClientStore.
|
void |
setCustomClientSlow(com.ning.http.client.AsyncHttpClient client)
Sets the custom fast client in the httpClientStore.
|
void |
setHttpClientTypeCurrentDefault(HttpClientType type)
Sets the default client type that the httpClientStore.
|
private static org.slf4j.Logger logger
public ParallelTaskManager taskManager
public HttpClientStore httpClientStore
public TcpUdpSshPingResourceStore tcpSshPingResourceStore
public static java.util.concurrent.atomic.AtomicBoolean isClosed
public ParallelClient()
public void initialize()
public void releaseExternalResources()
public void reinitIfClosed()
public ParallelTaskBuilder prepareSsh()
public ParallelTaskBuilder preparePing()
public ParallelTaskBuilder prepareTcp(java.lang.String command)
command
- the commandpublic ParallelTaskBuilder prepareUdp(java.lang.String command)
command
- the commandpublic ParallelTaskBuilder prepareHttpGet(java.lang.String url)
url
- the UrlPostfix: e.g. in http://localhost:8080/index.html.,the url is "/index.html"public ParallelTaskBuilder prepareHttpPost(java.lang.String url)
url
- the UrlPostfix: e.g. in http://localhost:8080/index.html.,the url is "/index.html"public ParallelTaskBuilder prepareHttpDelete(java.lang.String url)
url
- the UrlPostfix: e.g. in http://localhost:8080/index.html.,the url is "/index.html"public ParallelTaskBuilder prepareHttpPut(java.lang.String url)
url
- the UrlPostfix: e.g. in http://localhost:8080/index.html.,the url is "/index.html"public ParallelTaskBuilder prepareHttpHead(java.lang.String url)
url
- the UrlPostfix: e.g. in http://localhost:8080/index.html.,the url is "/index.html"public ParallelTaskBuilder prepareHttpOptions(java.lang.String url)
url
- the UrlPostfix: e.g. in http://localhost:8080/index.html.,the url is "/index.html"public void setCustomClientFast(com.ning.http.client.AsyncHttpClient client)
client
- the new custom client fastpublic void setCustomClientSlow(com.ning.http.client.AsyncHttpClient client)
client
- the new custom client slowpublic void setHttpClientTypeCurrentDefault(HttpClientType type)
type
- the new http client type current defaultpublic void reinitHttpClients()
public void cleanInprogressJobMap()
public void cleanWaitTaskQueue()
public HttpClientStore getHttpClientStore()
public java.lang.String logHealth()
MonitorProvider
} class (singleton) provider JVM memory, thread information.
You may directly call MonitorProvider.getInstance() to access JVM memory / thread objectspublic int getRunningJobCount()