Runtime tools : Core components : CHA : Reference : Programming examples
  
Programming examples
Following are the primary function usage examples:
To create a context: context is created by a factory class ContextFactory.java:
Context rootCtx = ContextFactory.getRoot();
KeyedCollection keyColl = new KeyedCollection("sessionData");

Context bCtxt = ContextFactory.createContext("sessionCtx", true);
Context cCtx = ContextFactory.createContext("sessionCtx", "session", keyColl);
Context dCtx = ContextFactory.createContext("sessionCtx", "session", rootCtx,
true);
Context eCtx = ContextFactory.createContext("sessionCtx", "session", rootCtx, keyColl);
Context fCtx = ContextFactory.createContext("sessionCtx", "session", rootCtx, keyColl, true);
Another API is added to ContextFactory.java:
Context aCtxt = ContextFactory.createContext("sessionCtx");
To chain a context to another context:
Context rootCtx = ContextFactory.getRoot();
Context session1Ctx = ContextFactory.createContext("sessionCtx",true);
Context session2Ctx = ContextFactory.createContext("sessionCtx",false);
session1Ctx.chainTo(rootCtx);
session2Ctx.chainTo(rootCtx);
To fetch the value of a context:
Context rootCtx = ContextFactory.getRoot();
Context sessionCtx = ContextFactory.createContext("sessionCtx", true);
String str= (String)sessionCtx.getValueAt("SessionId");
KeyedCollection kColl = sessionCtx.getKeyedCollection();
System.out.println(str);
System.out.println(kColl);
To set the value of a context:
Context rootCtx = ContextFactory.getRoot();
Context sessionCtx = ContextFactory.createContext ("sessionCtx", true);
sessionCtx.setValueAt("SessionId", "Bank A");
KeyedCollection kColl = new KeyedCollection("SessionData");
To commit the context:
Context rootCtx = ContextFacotry.getRoot();
Context sessionCtx = ContexfFactory.createContext("sessionCtx", "session", rootCtx, true);
sessionCtx.commit();
To unchain a context from another context:
Context rootCtx = ContextFactory.getRoot();
Context sessionCtx = ContextFactory.createContext("sessionCtx", true);
sessionCtx.chainTo(rootCtx);
sessionCtx.unchain();
To remove a context:
Context rootCtx = ContextFactory.getRoot();
Context sessionCtx = ContextFactory.createContext("sessionCtx", true);
sessionCtx.chainTo(rootCtx);
sessionCtx.unchain();
sessionCtx.prune();
Go up to
Reference