Skip to content
Yair Ogen edited this page Mar 20, 2014 · 2 revisions

Introduction

FlowContext is an object that is used to identify a flow (business transaction) in the system during any request flow.

FlowContext is stored on Thread Local and is printing as a prefix to each log message.

The user could use a GUI product to filter log messages from a flow.

The main goal of the FlowContext object is to help users concatenate/filter data in the same flow from various log files.

This feature is especially practical for a distributed system, where each component writes to a separate log file.

FlowContext stores a uuid or a custom parameter which is an identifier data of the flow given by the entry point of the system that starts the flow.

Flow Context Implementation

The internal implementation is a unique String. The structure of the String is not exposed as it may vary between versions. Keep in mind that a String is your interface and that should suffice.

How To Use FlowContext In Code

Entry Point to the System and Flow Context Propagation to Remote Servers

​1. When you handle a request (when you start a flow), the application developer is responsible for creating a new instance of FlowContext by calling one of the simple functions:

FlowContextFactory.createFlowContext(); //Will generate a uuid.
FlowContextFactory.createFlowContext(String customParameter); //Will store the customParameter as an identifier of the flow.

​2. When using our communication stack we pass the flowcontext from client to the server automatically.

In order to get a String representation of the Flow Context, the serializeNativeFlowContext() function will have to be called by the application. for example:

doSomething(other_arguments..., serializeNativeFlowContext());

Remote Servers Invocation Flowcontext support

When the String representation of the FlowContext arrives to the remote server (as part of the protocol or any other way), the application will be responsible for manually calling the deserializeNativeFlowContext function in order to propagate it to the remote server.

For example:

public void doAction(other_arguments..., String flowContextString){
    FlowContextFactory.deserializeNativeFlowContext(flowContextString);
}

Note: In our Http server support we enable such de-serialization out of the box.

FlowContext API Summary

The FlowContext API is grouped in a single Class called FlowContextFactory.

The current functions may be needed by the application:

​1. createFlowContext

public static FlowContext createFlowContext(); //Creates FlowContext and generate uuid to identify the flow.
 
public static FlowContext createFlowContext(final String customParameter); //Creates FlowContext and use customParameter as identifier of the flow.

Creates new specific FlowContext object for this request, on the JVM.

After calling this function, the FlowContext will be added transparently to any log of the request.

​2. getFlowContext

public static FlowContext getFlowContext(); 

Return the current FlowContext; if FlowContext has not yet been created, it will return null.

May be used by the application to manually get information from the FlowContext.

​3. serializeNativeFlowContext

public static String serializeNativeFlowContext();

Return a String representing the current FlowContext (in the threadLocal); if FlowContext has not yet been created, it will return empty string.

​4. deserializeNativeFlowContext

public static FlowContext deserializeNativeFlowContext(final String flowContextString);

Creates new FlowContext from the String representation of our FlowContext on the current process.

​5. clearFlowContext

public static void clearFlowContext();