org.addsimplicity.anicetus
Class TelemetryContext

java.lang.Object
  extended by org.addsimplicity.anicetus.TelemetryContext
All Implemented Interfaces:
org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean

public class TelemetryContext
extends java.lang.Object
implements org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean

The TelemetryContext establishes the execution container for all telemetry. The execution context is defined by the system, process, and potentially the thread of execution for the session. A session is a logical concept that represents a unit of activity performed by the application. A session provides a container for other telemetry artifacts. Transactions are one of the artifacts that are also containers for other artifacts. The TelemetryContext provides a convenience method for creating other artifacts that will be parented to the current container (either session or transaction). The TelemetryContext is responsible for sending telemetry to the bus. By default, a session is sent anytime it ends. Applications may also send beacon telemetry (i.e. state and events) directly to the telemetry bus using the context convenience method. The lifecycle of the session is controlled by startSession and endSession. These methods are automatically called from the Spring container if Spring is used to manage the lifecycle of the context.

Author:
Dan Pritchett (driveawedge@yahoo.com)

Constructor Summary
TelemetryContext()
           
 
Method Summary
 void afterPropertiesSet()
          Called after the Spring framework sets all properties.
 TelemetryTransaction beginTransaction(java.lang.String resourceId)
          The beginTransaction method starts a new transaction as a child of the current session or transaction.
protected  TelemetrySession createSession()
           
 void destroy()
          The destroy method is called by the Spring framework when the context is being disposed.
 void endSession()
          The current session is ended.
 void endTransaction()
          The current transaction is closed.
 DeliveryAdapter getDeliveryAdapter()
          Return the currently set delivery adapter.
 java.lang.String getOperationName()
          Return the operation name.
 int getProcessIdentifier()
          Return the processor identifier.
 java.lang.String getReportingNode()
          Return the reporting node.
 TelemetrySession getSession()
          Return the current active session.
 TelemetryEvent newEvent(java.lang.String type)
          Create an event, child of the current context (session or transaction).
 TelemetryState newState()
          Create a state, child of the current context (session or transaction).
 ExecInfo peekTransaction()
          Return the current execution context (session or transaction).
 ExecInfo popTransaction()
          Pop the current transaction off the top of the stack.
 void pushTransaction(ExecInfo transaction)
          Push a transaction to the top of the execution context.
 void sendBeacon(GlobalInfo beacon)
          Send a telemetry beacon that is independent of the current execution context.
 void setDeliveryAdapter(DeliveryAdapter deliveryAdapter)
          Set the delivery adpater that will be used to publish events on the telemetry bus.
 void setOperationName(java.lang.String operationName)
          Set the operation name for this context.
 void setProcessIdentifier(int processIdentifier)
          Set the process identifier for this context.
 void setReportingNode(java.lang.String reportingNode)
          Set the node identifier for this context.
 void startSession()
          Start a new session.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TelemetryContext

public TelemetryContext()
Method Detail

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.Exception
Called after the Spring framework sets all properties. This method will start the session.

Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
java.lang.Exception
See Also:
InitializingBean.afterPropertiesSet()

beginTransaction

public TelemetryTransaction beginTransaction(java.lang.String resourceId)
The beginTransaction method starts a new transaction as a child of the current session or transaction.

Parameters:
resourceId - The application defined resource identifier.
Returns:
an initialized transaction.

destroy

public void destroy()
             throws java.lang.Exception
The destroy method is called by the Spring framework when the context is being disposed. An open session will be closed and published before the bean is disposed.

Specified by:
destroy in interface org.springframework.beans.factory.DisposableBean
Throws:
java.lang.Exception
See Also:
DisposableBean.destroy()

endSession

public void endSession()
The current session is ended. Any open transactions are closed with their completion status set to unknown. The session is published on the telemetry bus.


endTransaction

public void endTransaction()
The current transaction is closed. The completion status will be set to unknown if it has not already been set.


getDeliveryAdapter

public DeliveryAdapter getDeliveryAdapter()
Return the currently set delivery adapter.

Returns:
the current delivery adapter.

getOperationName

public java.lang.String getOperationName()
Return the operation name. The operation name is set on the session when it is created.

Returns:
the operation name.

getProcessIdentifier

public int getProcessIdentifier()
Return the processor identifier. The process identifier is extracted from the system property anicetus.processid. The process identifier is used in conjunction with the thread identifier to construct the session execution context.

Returns:
the processor identifier.

getReportingNode

public java.lang.String getReportingNode()
Return the reporting node. The reporting node is set to the host name of the default interface on the system where the application is run. The reporting node is set on the session.

Returns:
the reporting node.

getSession

public TelemetrySession getSession()
Return the current active session.

Returns:
the current active session.

newEvent

public TelemetryEvent newEvent(java.lang.String type)
Create an event, child of the current context (session or transaction).

Parameters:
type - The application defined type of the event.
Returns:
the newly created event.

newState

public TelemetryState newState()
Create a state, child of the current context (session or transaction).

Returns:
the newly created state.

peekTransaction

public ExecInfo peekTransaction()
Return the current execution context (session or transaction).

Returns:
the session or transaction context in effect.

popTransaction

public ExecInfo popTransaction()
Pop the current transaction off the top of the stack. The session will not be popped from the stack.

Returns:
the current transaction or null if no transactions are left.

pushTransaction

public void pushTransaction(ExecInfo transaction)
Push a transaction to the top of the execution context. The standard reporting information will be added to the transaction.

Parameters:
transaction - The transaction to push.

sendBeacon

public void sendBeacon(GlobalInfo beacon)
Send a telemetry beacon that is independent of the current execution context. The beacon will be sent immediately. The basic information about the current application environment will be set.

Parameters:
beacon - The beacon to be sent.

setDeliveryAdapter

public void setDeliveryAdapter(DeliveryAdapter deliveryAdapter)
Set the delivery adpater that will be used to publish events on the telemetry bus.

Parameters:
deliveryAdapter - The delivery adapter instance.

setOperationName

public void setOperationName(java.lang.String operationName)
Set the operation name for this context. This will be set on sessions when they are created.

Parameters:
operationName -

setProcessIdentifier

public void setProcessIdentifier(int processIdentifier)
Set the process identifier for this context. The process identifier should be the operating system identifier for the JVM process.

Parameters:
processIdentifier - The JVM process identifier.

setReportingNode

public void setReportingNode(java.lang.String reportingNode)
Set the node identifier for this context. This is typically the host name or IP address.

Parameters:
reportingNode - The node network identifier.

startSession

public void startSession()
Start a new session. The session is filled with the current execution environment information.


createSession

protected TelemetrySession createSession()


Copyright © 2009 Add Simplicity. All Rights Reserved.