Exemple 1 d'API d'agent
Le code suivant génère une transaction à partir du code client et récupère l'arborescence de transactions générée :
private static void testAddTransaction() throws Exception
{
String request = "http://localhost:8080/examples/servlets/servlet/HelloWorldExample";
TransactionsClient tc = AgentClient.getInstance().getTransactionClient();
tc.installSocketTracker(false);
long start = System.currentTimeMillis();
String response = testMakeRequest(request);
long end = System.currentTimeMillis();
tc.uninstallSocketTracker(false);
String frameId = tc.addClientTransaction("test", new Object[] { request }, response, end - start);
TransactionFrame frame = tc.getTransactionTree(frameId);
System.out.println(frame.isComplete() ? "Yes!" : "No!");
}
Dans cet exemple de code, la fonction d'utilitaire suivante est utilisée, sans lien avec l'agent, mais répertoriée à des fins d'exhaustivité :
/** Supposons que Tomcat est en cours d'exécution sur l'hôte local :8080 */
private static String testMakeRequest(String url) throws IOException
{
StringBuffer response = new StringBuffer();
HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
con.setRequestMethod("GET");
con.setDoOutput(true);
con.setUseCaches(false);
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
for (String line = br.readLine(); line != null; line = br.readLine()) response.append(line);
br.close();
return response.toString();
}
Exemple 2 d'API d'agent
Le code suivant enregistre un rappel de VSE de journalisation :
AgentClient.getInstance().addListener(new IAgentEventListener()
{
public void onAgentOffline(final IAgentInfo info) {}
public void onAgentOnline(final IAgentInfo info)
{
AgentClient.getInstance().getVSEClient().registerVSECallback(info, new IVSECallback()
{
public void onFrameRecord(VSEFrame frame) { System.out.println("Recorded: " + frame); }
public VSEFrame onFramePlayback(VSEFrame frame) { System.out.println("Played back: " + frame); return frame; }
public int hashCode() { return 0; }
public boolean equals(Object o) { return o instanceof IVSECallback; }
});
try { AgentClient.getInstance().getVSEClient().startVSERecording(info); } catch (JMSInvocationException e) {}
});
|
Copyright © 2014 CA Technologies.
Tous droits réservés.
|
|