+

Search Tips   |   Advanced Search

 

Example: Using the correlation service interface

 

Consult this information when utilizing the ARM API with the correlation service as part of a servlet instrumentation.

 

Example

The arm40 binaries should be installed in accordance with the installation instructions supplied by the implementation provider. Once this is done, restart the server. This causes trace records to be generated in the SystemOut.log file indicating the instantiation of the appropriate ARM implementation.

The following example illustrates one of the typical workflows of using the ARM API in conjunction with the correlation service as part of a servlet instrumentation:

public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

PmiRmArmTx artrax =
// The factory detects the currently active ARM implementation (specified by user through 
// admin console) and instantiates an appropriate ARM wrapper object

    PmiRmArmTxFactory.createPmiRmArmTx();
ArmTransaction at = newArmTx(); if (null == at)
            out.println("Got a null ArmTransaction");
ArmCorrelator arc = newArmCorr(); at.start(arc); try {
  artrax.setArmTransaction(at);
  PmiRmArmStack.pushTransaction(artrax);
} catch (Exception e) {
  System.out.println("Caught 1 exception" + e);
}

PmiRmArmTx atxwrp = PmiRmArmStack.peekTransaction();
 if (atxwrp == null)
  out.println("Armtransaction is null");

//getArmType try {
  out.println("ARMTYPE is"+ PmiRmArmTx.getARMType());
} catch (Exception e) {
  out.println(e);
}
//getting correlator bytes try {
  if (null == atxwrp.getCorrelatorBytes())
    out.println("Got a null Correlator");
} catch (Exception e) {
  out.println(e);
}

//blocked/unblocked long blkid = 0; try {
  out.println(blkid = atxwrp.blocked());
} catch (Exception e) {
  out.println(e);
}
 try {
  out.println(atxwrp.unblocked(blkid));
} catch (Exception e) {
  out.println(e);
} try {
  atxwrp = PmiRmArmStack.popTransaction();
  ArmTransaction art = (ArmTransaction) atxwrp.getArmTransaction();
  art.stop(ArmConstants.STATUS_GOOD);
} catch (Exception e) {
  out.println(e);
}

}


 private ArmTransaction newArmTx() {

  ArmTransactionFactory txFactory = null; try {
  String sWasName = "WebSphere";
  String appName = "t23xpimage/t23xpimage/server1";
  String sCellName = appName.substring(0, appName.indexOf("/"));
  String sNodeInstance =
      appName.substring(appName.indexOf("/") + 1, appName.length());
  sNodeInstance = sNodeInstance.replace('/', '.');
  txFactory =  (ArmTransactionFactory)                   
  newObjectInstance("org.opengroup.arm40.sdk.ArmTransactionFactoryImpl");
  ArmApplication app = null; // 149297
  ArmApplicationDefinition appDef = null; //LIDB3207
  appDef =        txFactory.newArmApplicationDefinition(sWasName, null, null);
  app = txFactory.newArmApplication(appDef, sCellName, sNodeInstance, null);

  String[] idnames = { "request_type" };
  String[] idvalues = { "URI" };
  String[] ctxnames = { "URI" };
  ArmIdentityPropertiesTransaction props =
      txFactory.newArmIdentityPropertiesTransaction(
          idnames,
          idvalues,
          ctxnames,
          null);
  ArmTransactionDefinition atd =
        txFactory.newArmTransactionDefinition(
          appDef,
          "URI",
          props,
          (ArmID) null);
  ArmTransaction at = txFactory.newArmTransaction(app, atd);
  return at;
} catch (Exception e) {
  System.out.println(e);
  return null;
}

}
 private ArmCorrelator newArmCorr() {

  ArmTransactionFactory txFactory = null; try {
  String sWasName = "WebSphere";
  String appName = "t23xpimage/t23xpimage/server1";
  txFactory =
  (ArmTransactionFactory) newObjectInstance("org.opengroup.arm40.sdk.ArmTransactionFactoryImpl");

  ArmCorrelator arc =txFactory.newArmCorrelator(
          PmiRmArmStack.peekTransaction().getCorrelatorBytes());
  return arc;
} catch (Exception e) {
  System.out.println(e);
  return null;
}

}

 

Example

There are several potential scenarios for using the PmiRmArmStack. This example shows a scenario where code accesses an existing PmiRmArmTx on the stack, extracts the correlator, and calls blocked and unblocked. This is a typical scenario when sending a correlator along an unsupported protocol. In this scenario, the Arm transaction is already on the stack.

1      PmiRmArmTx artrax =
2        PmiRmArmStack.peekTransaction();
3      if( artrax != null )
4                          {
5                                      try
6                                      {
7            byte[] cbytes = artrax.getCorrelatorBytes();
8                                          stuffBytesIntoOutboundMessage( msg, cbytes);
9                                           long blockedId = 0;
10                                          try
11                                          {
12                                             blockedId = artrax.blocked();
13                                           }
14                                           catch( NoSuchMethodException nsme )
15                                           {
16                                               // must not be running ARM4 or eWLM
17                                           }
18                                             sendMsg( msg );
19                                          try
20                                          {
21                                             artrax.blocked( blockedId );
22                                           }
23                                           catch( NoSuchMethodException nsme )
24                                           {
25                                               // must not be running ARM4 or eWLM
26                                           }
27                      
28                                       }
29                                       catch( Exception e )
30                                       {
31                                          report a problem;
32                                       }
33      }
 



 

Related concepts


Request metric extension

 

Related tasks


Monitor application flow

 

Reference topic