CTBCAFServiceAlmMgmt

From TBwiki
Revision as of 12:27, 30 May 2011 by Abrassard (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The class CTBCAFServiceAlmMgmt is used by an application that wants to be launched automatically by the Toolpack system.

An application that initializes this class has to provide a callback to interface ITBCAFServiceAlmMgmtClient. This interface provides 3 functions that the application must implement:

  • OnMgmtReady: Tells the application that it's properly being detected by Toolpack OAM.
  • OnMgmtShutdown: Tells the application that it must shutdown itself. If the application takes too long (default timeout 20 seconds) it will get killed by Toolpack OAM.
  • OnMgmtHeartBeat: This function is called periodically by Toolpack OAM to test that the application is still alive. The application, within this function, should perform a sanity check on it's various internal modules. If this function call does not return, Toolpack OAM will kill the application after a timeout (default 20 seconds).


Adding an application to the Toolpack Web Portal list of applications

Once an application has create an object of class CTBCAFServiceAlmMgmt, and properly implemented the interface ITBCAFServiceAlmMgmtClient, it's ready to be automatically launched and shutdown by Toolpack OAM.

To add an application to be launched by Toolpack OAM, follow this procedure: Add custom application to Toolpack

Example usage

class MyApplication : public ITBCAFServiceAlmMgmtClient
{
	// your class definition

	// Functions inherited from ITBCAFServiceAlmMgmtClient
	virtual TBX_VOID OnMgmtReady();
	virtual TBX_VOID OnMgmtShutdown( TBX_BOOL in_fGracefulShutdown = TBX_FALSE );
	virtual TBX_RESULT OnMgmtHeartBeat();
};

TBX_RESULT MyApplication::Init()
{
	TBX_RESULT			Result = TBX_RESULT_OK;

	// Answer to management message
	Result = CTBCAFServiceAlmMgmt::Init(TBX_FALSE);
	if( TBX_RESULT_SUCCESS( Result ) )
	{
		// Register ourself to launch service
		CTBCAFServiceAlmMgmt::GetInstance()->Register(this);
	}

	return Result;
}

TBX_RESULT MyApplication::UnInit()
{
	TBX_RESULT			Result = TBX_RESULT_OK;

	/* Unregister from ALM client */
	Result = CTBCAFServiceAlmMgmt::Uninit();

	return Result;
}

TBX_VOID MyApplication::OnMgmtReady()
{
	// Do whatever you want when successfully connected to Toolpack OAM
	LogTrace
	(
		TBCAF_TRACE_LEVEL_ALWAYS,
		"OnMgmtReady: Now connected to Toolpack OAM ALM"
	);
}

TBX_VOID MyApplication::OnMgmtShutdown( TBX_BOOL in_fGracefulShutdown )
{
	// Indicate to current application that it must shutdown itself
	mfQuit = TBX_TRUE;

	if( in_fGracefulShutdown )
	{
		// No hurry. We can start actively refusing new incoming calls,
		// but leave active calls terminate gracefully as users hangup, for example.
		// Or we can just quit immediately if we don't care implementing a "graceful" shutdown!
	}
	else
	{
		// Hurry a bit more, no time to wait for calls to terminate gracefully,
		// we'll get killed in 20 seconds if we don't quit!
	}
}

TBX_RESULT CTBS2GWSimpleCall::OnMgmtHeartBeat()
{
 	TBX_RESULT			Result = TBX_RESULT_OK;

	// Poll the CAF framework to detect problems with it
	Result = TBCAF::GlobalPoll();

	// Poll any modules of current application to see if they are in good health.
	// A good idea is to at least enter each module, as if there is an infinite loop
	// or dead-lock within one of them, for example, we'll block on the module's mutex
	// and not return from OnMgmtHeartBeat(), causing Toolpack OAM to kill ourself after
	// 20 seconds (which is probably what we want if we have a dead-lock somewhere!)

	return Result;
}
Personal tools