com.sap.tc.cmi.util

Class CMIThreadContextUtils

java.lang.Object
  extended by com.sap.tc.cmi.util.CMIThreadContextUtils

public final class CMIThreadContextUtils
extends Object

Provides a primitive data storage (context) that allows different CMI consumers running in the same thread to exchange data without knowing/referencing each other. For the time being, only CMI defines the type and semantic of the data that can be stored.

Regarding this class, CMI consumers can act in two different roles:

Role: Context User

A context user stores data in an existing context or retrieves data from it. Typical context users must not try to create contexts on their own. With the current API of this class, they even don't have to check whether a context exists. This is done by the provided helper methods.

See the Types of Data sub topic for a description of the supported data.

Role: Context Creator

A context creator defines the maximum lifetime of the data stored in the thread local storage. By calling the openContext() method, the context comes into life and data can be stored in and retrieved from that context. With a call to the closeContext(String) method, the lifetime of the context ends and all data contained therein is dereferenced. After that time, no data can be stored in or retrieved from the context.

Currently, only a single context per thread is supported (contexts can't be nested). In case of multiple calls to openContext, the last one wins.

Context creators should always use try..finally to guarantee proper cleanup of a created context:
   String myRegistrationId =  CMIThreadContextUtils.openContext();
   try 
   {
     ...
   } 
   finally 
   {
     CMIThreadContextUtils.closeContext(myRegistrationId);
   }
 
Note: For the time being, Web Dynpro is the only context creator. In later versions of the CMI API, the methods openContext/closeContext might be moved to a separate class which will be available through a restricted public part only (ACL). DON'T USE openContext OR closeContext WITHOUT CONTACTING THE AUTHOR OF THIS CLASS.

Types of Data

Currently, the only type of data managed by this context are backend execution times. They are measured to calculate the amount of time within a single request/response, that the local J2EE engine was idle and waiting for an external resource. On a frontend, these times might be displayed as backend times, in contrast to the J2EE times.

All measured times are meant to be informational only, so there is no exact definition what can/must be measured or how it should be measured.

Type Classification Type Classification:

This class is part of the Common Model Interface, so applications may reference it or call any method of this type, but they must not subclass it.


Method Summary
static void addBackendExecutionTime(String groupId, long durationMillis)
          Adds the given backend execution time (in milliseconds) to the given group.
static boolean closeContext(String callerId)
          Deprecated. For Web Dynpro use only, will be moved to a separate class in a separate public part during development of NW NY.
static Map getGroupedBackendExecutionTimes()
          Returns an unmodifiable map with the currently known model execution times.
static long getTotalBackendExecutionTime()
          Returns the sum of all recorded backend execution times in all groups.
static String openContext()
          Deprecated. For Web Dynpro use only, will be moved to a separate class in a separate public part during development of NW NY.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

openContext

public static String openContext()
Deprecated. For Web Dynpro use only, will be moved to a separate class in a separate public part during development of NW NY.

Opens a new context for the current thread, if no one exists already. Otherwise, the existing context is cleared. In either case, an ID is returned that identifies the caller. The created context can only be closed with that id.

This method is to be used by context creators only.


closeContext

public static boolean closeContext(String callerId)
Deprecated. For Web Dynpro use only, will be moved to a separate class in a separate public part during development of NW NY.

Closes a currently open context, if the given id is the id returned by the context defining call. Otherwise does nothing.

This method is to be used by context creators only.

Parameters:
callerId - callerId as returned by corresponding call to openContext

addBackendExecutionTime

public static void addBackendExecutionTime(String groupId,
                                           long durationMillis)
Adds the given backend execution time (in milliseconds) to the given group. Groups can be freely defined, but callers should be aware that

The proposed granularity for groups is that each model technology (model type) uses a single group to sum the backend execution times of all its models.

Parameters:
groupId - String id of the group
durationMillis - measured backend execution time in milliseconds

getGroupedBackendExecutionTimes

public static Map getGroupedBackendExecutionTimes()
Returns an unmodifiable map with the currently known model execution times. The keys of this map will be Strings (those that have been used in calls to addBackendExecutionTime since the current context has been opened) and the values will be Longs that represent the cumulated time values provided in these calls. All returned times are in milliseconds.


getTotalBackendExecutionTime

public static long getTotalBackendExecutionTime()
Returns the sum of all recorded backend execution times in all groups.

Returns:
total time over all groups, measured in milliseconds
Access Rights

This class can be accessed from:


SC DC Public Part ACH
[sap.com] FRAMEWORK [sap.com] tc/cm/ejb/api api BC-JAS-EJB
[sap.com] FRAMEWORK [sap.com] tc/cmi default BC-WD-JAV-RUN


Copyright 2014 SAP AG Complete Copyright Notice