FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Using Profiler class, from the utils package, instead of System.currentTimeMillis() by wilderrodrigues · Pull Request #525 · apache/cloudstack · GitHub

Repository navigation

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.apache.commons.httpclient.params.HttpClientParams;
import org.apache.log4j.Logger;

import com.cloud.utils.Profiler;

public class ClusterServiceServletImpl implements ClusterService {
private static final long serialVersionUID = 4574025200012566153L;
private static final Logger s_logger = Logger.getLogger(ClusterServiceServletImpl.class);
Expand All @@ -38,18 +40,18 @@ public class ClusterServiceServletImpl implements ClusterService {
public ClusterServiceServletImpl() {
}

public ClusterServiceServletImpl(String serviceUrl) {
public ClusterServiceServletImpl(final String serviceUrl) {
s_logger.info("Setup cluster service servlet. service url: " + serviceUrl + ", request timeout: " + ClusterServiceAdapter.ClusterMessageTimeOut.value() +
" seconds");
" seconds");

_serviceUrl = serviceUrl;
}

@Override
public String execute(ClusterServicePdu pdu) throws RemoteException {
public String execute(final ClusterServicePdu pdu) throws RemoteException {

HttpClient client = getHttpClient();
PostMethod method = new PostMethod(_serviceUrl);
final HttpClient client = getHttpClient();
final PostMethod method = new PostMethod(_serviceUrl);

method.addParameter("method", Integer.toString(RemoteMethodConstants.METHOD_DELIVER_PDU));
method.addParameter("sourcePeer", pdu.getSourcePeer());
Expand All @@ -65,44 +67,47 @@ public String execute(ClusterServicePdu pdu) throws RemoteException {
}

@Override
public boolean ping(String callingPeer) throws RemoteException {
public boolean ping(final String callingPeer) throws RemoteException {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Ping at " + _serviceUrl);
}

HttpClient client = getHttpClient();
PostMethod method = new PostMethod(_serviceUrl);
final HttpClient client = getHttpClient();
final PostMethod method = new PostMethod(_serviceUrl);

method.addParameter("method", Integer.toString(RemoteMethodConstants.METHOD_PING));
method.addParameter("callingPeer", callingPeer);

String returnVal = executePostMethod(client, method);
final String returnVal = executePostMethod(client, method);
if ("true".equalsIgnoreCase(returnVal)) {
return true;
}
return false;
}

private String executePostMethod(HttpClient client, PostMethod method) {
private String executePostMethod(final HttpClient client, final PostMethod method) {
int response = 0;
String result = null;
try {
long startTick = System.currentTimeMillis();
final Profiler profiler = new Profiler();
profiler.start();
response = client.executeMethod(method);
if (response == HttpStatus.SC_OK) {
result = method.getResponseBodyAsString();
profiler.stop();
if (s_logger.isDebugEnabled()) {
s_logger.debug("POST " + _serviceUrl + " response :" + result + ", responding time: " + (System.currentTimeMillis() - startTick) + " ms");
s_logger.debug("POST " + _serviceUrl + " response :" + result + ", responding time: " + profiler.getDurationInMillis() + " ms");
}
} else {
profiler.stop();
s_logger.error("Invalid response code : " + response + ", from : " + _serviceUrl + ", method : " + method.getParameter("method") + " responding time: " +
(System.currentTimeMillis() - startTick));
profiler.getDurationInMillis());
}
} catch (HttpException e) {
} catch (final HttpException e) {
s_logger.error("HttpException from : " + _serviceUrl + ", method : " + method.getParameter("method"));
} catch (IOException e) {
} catch (final IOException e) {
s_logger.error("IOException from : " + _serviceUrl + ", method : " + method.getParameter("method"));
} catch (Throwable e) {
} catch (final Throwable e) {
s_logger.error("Exception from : " + _serviceUrl + ", method : " + method.getParameter("method") + ", exception :", e);
} finally {
method.releaseConnection();
Expand All @@ -114,14 +119,14 @@ private String executePostMethod(HttpClient client, PostMethod method) {
private HttpClient getHttpClient() {

if (s_client == null) {
MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
final MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
mgr.getParams().setDefaultMaxConnectionsPerHost(4);

// TODO make it configurable
mgr.getParams().setMaxTotalConnections(1000);

s_client = new HttpClient(mgr);
HttpClientParams clientParams = new HttpClientParams();
final HttpClientParams clientParams = new HttpClientParams();
clientParams.setSoTimeout(ClusterServiceAdapter.ClusterMessageTimeOut.value() * 1000);

s_client.setParams(clientParams);
Expand All @@ -130,14 +135,14 @@ private HttpClient getHttpClient() {
}

// for test purpose only
public static void main(String[] args) {
public static void main(final String[] args) {
/*
ClusterServiceServletImpl service = new ClusterServiceServletImpl("http://localhost:9090/clusterservice", 300);
try {
String result = service.execute("test", 1, "{ p1:v1, p2:v2 }", true);
System.out.println(result);
} catch (RemoteException e) {
}
*/
*/
}
}

Back | FazBrowse Home | New Git URL