Home
Find the answer to your question
Enable call metrics logging in Java SDK
Summary
You can use the JAVA SDK MetricsLogger class to report the amount of time spent by an API call in each phase of execution. The sample application below illustrates how MatricsLogger is used.
Detailed Description
The sample applicaiton generates API call metrics report in milliseconds.
eBay Java SDK is based on JAX-WS RI which creates proxy instance at runtim, as shown in the bottom of this KB, the performance for the first call is slow ( marked as PreJAXB in the report) but the subsequent calls are much quicker than the initial one.
import com.ebay.sdk.*;
import com.ebay.sdk.call.VerifyAddFixedPriceItemCall; import com.ebay.sdk.logging.*; import com.ebay.soap.eBLBaseComponents.*; /** * * @author zhuyang */ public class SimplePerformanceTest { private ApiContext apiContext = new ApiContext(); private ApiLogging apiLogging = new ApiLogging(); private CallMetrics matrics; private String TOKEN=""; private String APISERVERURL = "https://api.ebay.com/wsapi"; public SimplePerformanceTest() { matrics = new CallMetrics(); ApiCredential cred = new ApiCredential(); apiContext.setApiCredential(cred); // Set api call credential apiContext.getApiCredential().seteBayToken(TOKEN); // Enable api logging apiContext.setApiLogging(apiLogging); apiContext.setSite(SiteCodeType.UK); apiContext.setApiServerUrl(APISERVERURL); } public static void main(String[] args) { // Enable MatricsLogging MetricsLogger.enableMetricsLogging(); SimplePerformanceTest results = new SimplePerformanceTest(); try { for (int i = 0; i < 10; i++) { FeesType fee = addFixedItem(results.apiContext); //collect matric data MetricsLogger.collectMetrics(results.matrics); if (fee == null) { return; } } } catch (Exception e) { //e.printStackTrace(); } finally { // print out matrics report to console results.matrics.generateReport(System.out); } } private static FeesType addFixedItem(ApiContext apiContext throws Exception { FeesType fee = null; VerifyAddFixedPriceItemCall request = new VerifyAddFixedPriceItemCall( apiContext); request.setSite(SiteCodeType.UK); ItemType item = new ItemType(); item.setConditionID(1000); item.setTitle("Testing item. Do not bid"); item.setDescription("Testing item. Do not bid"); item.setSite(SiteCodeType.UK); item.setConditionID(1000); item.setPostalCode("SE6 1AL"); item.setListingDuration("Days_7"); BuyerPaymentMethodCodeType[] arrPaymentMethods = new BuyerPaymentMethodCodeType[]{ BuyerPaymentMethodCodeType.PAY_PAL }; item.setPayPalEmailAddress("test@test.com"); item.setPaymentMethods(arrPaymentMethods); item.setStartPrice(getAmount(11.0)); item.setCountry(CountryCodeType.GB); item.setCurrency(CurrencyCodeType.GBP); CategoryType category = new CategoryType(); category.setCategoryID("57991"); item.setPrimaryCategory(category); item.setQuantity(5); item.setShippingDetails(getShippingDetails()); item.setDispatchTimeMax(2); item.setReturnPolicy(getReturnPolicy()); request.setItem(item); fee = request.verifyAddFixedPriceItem(); return fee; } private static ReturnPolicyType getReturnPolicy() { ReturnPolicyType rp = new ReturnPolicyType(); rp.setReturnsAcceptedOption("ReturnsAccepted"); rp.setRefundOption("MoneyBack"); rp.setReturnsWithinOption("Days_30"); rp.setDescription("Text description of return policy details"); rp.setShippingCostPaidByOption("Buyer"); return rp; } private static ShippingDetailsType getShippingDetails() { ShippingDetailsType sd = new ShippingDetailsType(); ShippingServiceOptionsType st1 = new ShippingServiceOptionsType(); st1.setShippingService("UK_SellersStandardRate"); st1.setShippingServiceCost(getAmount(1)); st1.setShippingServiceAdditionalCost(getAmount(1)); sd.setShippingServiceOptions(new ShippingServiceOptionsType[]{st1}); return sd; } private static AmountType getAmount(double amount) { AmountType a = new AmountType(); a.setValue(amount); return a; } } |
Here is a sample report ( in ms)
== VerifyAddFixedPriceItem ==
|
Version Info
The code example above was based on the versions specified below:
Java SDK Version | javasdk v673 Full release |