Kanzi Connect  3.9.8
Kanzi Connect C++ API
kanzi::connect::ExternalServiceAdapter Class Reference

Adapter class between Java implemented services and AbstractService instance. More...

#include <externalserviceadapter.hpp>

Inheritance diagram for kanzi::connect::ExternalServiceAdapter:
kanzi::connect::AbstractService

Public Member Functions

 ExternalServiceAdapter (const string &identfier)
 Constructor. More...
 
virtual void receive (shared_ptr< ExternalServiceSession > session, const MessagePackage &message)
 Invoked to receive incoming message. More...
 
virtual void transmitToAll (const MessagePackage &message)
 Transmits a provided message to wire and delivers it to all sessions available. More...
 
virtual bool transmitToSession (shared_ptr< ExternalServiceSession > session, const MessagePackage &message)
 Transmits a provided message to specific session. More...
 
virtual ~ExternalServiceAdapter () override
 Destructor. More...
 
virtual GenericInvokergetGenericInvoker () override
 
virtual AbstractSessionSharedPtr onAcquireSession (int clientId, int sessionId, MessageDispatcher *dispatcher, const string &instanceName) override
 Session factorization method interface. More...
 
virtual ContentProviderCollectionSharedPtr getContentProvider () override
 Returns content provider for this service. More...
 
virtual string getIdentifier () const override
 
virtual void onReleaseSession (AbstractSessionSharedPtr session) override
 Virtual method that inheriting classes can implement. More...
 
bool addSubscriptionExt (const string &identifier, shared_ptr< ExternalServiceSession > session)
 
vector< string > removeSubscriptionsExt (shared_ptr< ExternalServiceSession > session, const string &identifier="")
 
bool hasSubscriptionsExt (const string &identifier)
 
vector< shared_ptr< ExternalServiceSession > > findSubscribersExt (const string &identifier)
 
- Public Member Functions inherited from kanzi::connect::AbstractService
 AbstractService ()
 Constructor. More...
 
AbstractSessionSharedPtr acquireSession (int clientId, int sessionId, MessageDispatcher *dispatcher, const string &instanceName)
 Session factorization method. More...
 
virtual InvokableOperationResult addCustomType (const string &xml)
 Add a custom type to the service. More...
 
virtual InvokableOperationResult addCustomTypeDecoded (const string &decodedXml)
 Add a custom type to the service. More...
 
virtual int addEvent (const string &identifier, const string &description)
 
virtual int addMethod (const string &identifier, const string &description)
 
virtual int addProperty (const string &identifier, const string &description)
 
virtual InvokableOperationResult addRoute (const string &xml)
 Add new P2P route(s) for the service. More...
 
virtual InvokableOperationResult addRouteDecoded (const string &decodedXml)
 Add new P2P route(s) for the service. More...
 
RuntimeDataSchemaChangeSubscriptionToken addRuntimeDataSchemaChangeSubscription (RuntimeDataSchemaChangeCallback function)
 Adds a callback to invoke when runtime data schema changes. More...
 
StateChangedSubscriptionToken addStateChangeSubscription (StateCallbackFunction function)
 Adds a state change callback subscription. More...
 
bool addSubscription (const string &identifier, AbstractSessionSharedPtr session)
 Add subscription to the given session for this service. More...
 
virtual void cancelTimer (int64_t timerId)
 Cancels ongoing timer. More...
 
int countSessions () const
 Amount of allocated sessions. More...
 
size_t countSessions ()
 Return the amount of sessions towards this service amount of sessions. More...
 
virtual InvokableOperationResult createRuntimedata (const string &parentIdentifier, const string &xml)
 Create a new runtime data element for the service runtime data. More...
 
EnumMap::const_iterator enumerationValuesBegin ()
 
EnumMap::const_iterator enumerationValuesEnd ()
 
vector< AbstractSessionSharedPtrfindSubscribers (const string &identifier)
 Find all subscribers for the given identifier. More...
 
const SessionContainergetAllSessions () const
 Returns all currently active sessions. More...
 
SessionContainer getAllSessionsOfClient (int clientId)
 Returns all sessions for a given client. More...
 
string getAttribute (const string &key)
 Gets value of a service attribute. More...
 
KanziStringVectorSharedPtr getAttributes ()
 Lists all service attributes. More...
 
RuntimeDataObjectSharedPtr getConfigurationProperties ()
 Retrieves configuration properties as a runtime data object to allow more convenient access to data. More...
 
ContentClientSharedPtr getContentClient () const
 Access to content system. More...
 
const vector< unique_ptr< CustomType > > & getCustomTypes () const
 Get the custom types defined for this service. More...
 
KanziStringVectorSharedPtr getDisabledInvokables ()
 
ConnectDomainSharedPtr getDomain () const
 Retrieves the connect domain. More...
 
optional< int > getEnumValue (const string &name, const string &enumerator)
 Find out value for enumeration string. More...
 
ServiceExtensionContainergetExtensions ()
 
string getExtensionsSchemas ()
 
string getFullyQualifiedConfigurationPropertyName (const string &name)
 Constructs a fully qualified configuration property name, usually the fully qualified name is something like "Connect.Service.MyService.ConfigurationProperties.MyPropertyName". More...
 
InterfaceDomainBasegetInterfaceDomain () const
 Access to interface domain. More...
 
virtual RuntimeDataObjectSharedPtr getModifiedConfigurationProperties ()
 Retrieves modified configuration properties as runtime data object. More...
 
virtual string getName ()
 Returns the override name. More...
 
WorkQueueInterfacegetProxyWorkQueue ()
 Returns a proxied work queue instance that can be used by composited classes to to assign work to this service. More...
 
AbstractSessionSharedPtr getRunningSession ()
 
virtual string getSchema ()
 Returns service schema in XML format. More...
 
virtual const ServiceDescriptiongetServiceDescription () const
 Access the static service description info. More...
 
virtual p2p::RoutingRulesSharedPtr getServiceRoutingInformation ()
 Return service routing information. More...
 
virtual const ServiceStategetServiceState () const
 Gets service state information. More...
 
AbstractSessionSharedPtr getSession (int clientId, int sessionId)
 Returns session by client & session id. More...
 
int getStopInterval () const
 Retrieve service stop interval. More...
 
WorkQueueInterfacegetWorkQueue () const
 Access to signal that allows to invoke work(). More...
 
bool hasEnumValues (const string &name)
 Checks if enum has been defined on this service. More...
 
bool hasSubscriptions (const string &identifier)
 Check if the given identifier has any subscriptions. More...
 
virtual void initialize (InterfaceDomainBase *domain, ContentClientSharedPtr contentClient, WorkQueueInterface *workQueue)
 Initialize this service. More...
 
bool manualPersistenceOverride () const
 Defines whether manual persistence override is active, i.e. More...
 
bool processMessage (const MessagePackage &message, AbstractSessionSharedPtr session, shared_ptr< GenericRPCReplyMessage > &ret)
 Offer received message directly to service to implement a short path for scripts and built-in methods. Intended for internal use. More...
 
void releaseAllSessions ()
 Unconditionally releases all sessions. use carefully. More...
 
void releaseSession (AbstractSessionSharedPtr session)
 Releases previously allocated session. More...
 
virtual InvokableOperationResult removeCustomType (const string &typeName)
 Remove a custom type from a service. More...
 
virtual int removeEvent (const string &identifier)
 
virtual int removeMethod (const string &identifier)
 
virtual int removeProperty (const string &identifier)
 
virtual InvokableOperationResult removeRoute (const string &subjectName)
 Remove a route from a service. More...
 
virtual InvokableOperationResult removeRuntimedataElement (const string &elementIdentifier)
 Remove runtime data element from the service runtime data. More...
 
void removeRuntimeDataSchemaChangeSubscription (RuntimeDataSchemaChangeSubscriptionToken token)
 Remove schema change subscription. More...
 
void removeStateChangeSubscription (StateChangedSubscriptionToken token)
 Remove state change subscription. More...
 
vector< string > removeSubscriptions (AbstractSessionSharedPtr session, const string &identifier="")
 Remove subscription to the given session for this service. More...
 
AbstractService::ServiceControlResult resetService (ServiceArgumentsSharedPtr arguments)
 Tries to reset service. More...
 
ServiceRuntimeDataruntimeData ()
 Retrieve service runtime data. More...
 
void setAttribute (const string &key, const string &value)
 Add service attributes as key value pairs. More...
 
void setDomain (ConnectDomainSharedPtr domain)
 Set the connect domain. More...
 
void setFileClient (VirtualFileClient *client)
 Set the client instance to access VirtualFileService. More...
 
virtual void setName (const string &name)
 Defines a override name used to identify the service. More...
 
void setPersistence (AbstractService::ServiceDescription::Persistence persistence)
 Sets the service persistence. More...
 
virtual void setRunningSession (AbstractSessionSharedPtr session)
 Stores the currently running session. More...
 
virtual InvokableOperationResult setRuntimedataValue (const string &elementIdentifier, const string &value)
 Set runtime data value for the given element in the service runtime data. More...
 
bool setServiceRuntimeDataSchema (const string &xml)
 Set service runtime data schema. More...
 
void setServiceState (AbstractService::ServiceState state)
 sets service state information. More...
 
void setServiceVersion (AbstractService::ServiceDescription::Version version, AbstractService::ServiceDescription::Version minCompatibleVersion=AbstractService::ServiceDescription::Version())
 Configures the service version information. More...
 
void setSettingFactory (const persistence::SettingFactory *factory)
 Set the setting factory instance to allow using persistence service. More...
 
void setStopInterval (int seconds)
 Configures the stop interval. More...
 
virtual int64_t setTimer (int64_t milliseconds, ConnectWorkItem::Executor callback)
 Installs a timer to be called after a specified timeout in milliseconds. More...
 
virtual int64_t setTimer (int64_t milliseconds, ConnectWorkItem::Executor callback, ConnectWorkItem::ExecutionContext executionContext)
 Installs a timer to be called after a specified timeout in milliseconds. More...
 
bool simulateEvent (const string &messageName, const MessagePackage &message)
 Post a message to all running sessions as event. Intended for internal use. More...
 
AbstractService::ServiceControlResult startService (ServiceControlSource serviceControlSource, ServiceArgumentsSharedPtr arguments)
 Tries to start the service. More...
 
AbstractService::ServiceControlResult stopService (ServiceControlSource serviceControlSource)
 Tries to stop the service. More...
 
virtual void uninitialize ()
 Uninitialize this service. More...
 
virtual void work (ConnectWorkItemSharedPtr workItem)
 Asks service to perform work. More...
 
virtual ~AbstractService ()
 Destructor. More...
 

Protected Member Functions

virtual void onSubscriptionsEnded (const vector< string > &identifiers)
 Notifies that these streams no longer have any subscribers left (but they used to have) This is notified when a session is released without it first explicitly unsubscribing. More...
 
- Protected Member Functions inherited from kanzi::connect::AbstractService
void addEnumValue (const string &name, const string &enumerator, int value)
 Store value for enumeration string. More...
 
VirtualFileClientgetFileClient () const
 Get instance to access the VirtualFileService. More...
 
ScriptContextSharedPtr getScriptContext ()
 Get shared script context. More...
 
const persistence::SettingFactory * getSettingFactory () const
 Get the setting factory instance. More...
 
void notifyRuntimeSchemaChange ()
 Notify all observers that service schema has changed. More...
 
virtual void notifyWork ()
 Allows the derived class to invoke work(). More...
 
virtual void notifyWork (ConnectWorkItemSharedPtr workItem)
 Called notify that this service would have a work item to be processed later on. More...
 
void notifyWork (const ConnectWorkItem::Executor executor)
 Call to notify that provided executor should be run the kanzi connect main thread context. More...
 
virtual void notifyWork (ConnectWorkItemSharedPtr workItem, const ConnectWorkItem::Executor executor)
 Called to notify this service has work to do and for that work use the attached executor. More...
 
virtual AbstractService::ServiceControlResult onResetServiceRequest (ServiceArgumentsSharedPtr arguments)
 Inherited classes should implements this method that is invoked when service is requested to reset itself. More...
 
virtual AbstractService::ServiceControlResult onStartServiceRequest (ServiceArgumentsSharedPtr arguments)
 Inherited classes should implement this method that is invoked when service is to be started. More...
 
virtual AbstractService::ServiceControlResult onStopServiceRequest ()
 Inherited classes should implement this method that is invoked when service is to be stopped. More...
 
bool prepareScriptContext ()
 Prepare script plugin for use. More...
 
virtual string provideServiceRoutingInformationOverride ()
 Service should override this in order to provide a custom routing information structure. More...
 
virtual string provideServiceRuntimeDataOverride ()
 Service should override this in order to provide a runtime data structure. More...
 
void registerEnumValue (AbstractServiceSharedPtr service, const string &name, const string &enumerator, int value)
 Store value for enumeration string for a service. More...
 
void setConfigurationPropertyPrefix (const string &prefix)
 Configures the configuration property name prefix used to build fully qualified configuration property names. More...
 
bool writeConfigurationPropertyInternal (const string &stream)
 Writes a configuration property value. More...
 

Additional Inherited Members

- Public Types inherited from kanzi::connect::AbstractService
typedef map< string, EnumValuesEnumMap
 
typedef map< string, int > EnumValues
 
enum  InvokableOperationResult {
  Success = 0, AlreadyExists = -1, ValidationFailed = -2, NotFound = -3,
  NotReady = -4
}
 
typedef function< void(AbstractService *)> RuntimeDataSchemaChangeCallback
 Callback prototype to be invoked when runtime data schema changes. More...
 
typedef shared_ptr< void > RuntimeDataSchemaChangeSubscriptionToken
 Handle given as return value to runtime data schema change callback registration. More...
 
enum  ServiceControlResult { ServiceControlSuccess, ServiceControlFailed, ServiceControlNotSupported }
 
typedef enum kanzi::connect::AbstractService::ServiceControlResult ServiceControlResult
 
enum  ServiceControlSource { ServiceControlSourceManual, ServiceControlSourceLogic }
 
typedef enum kanzi::connect::AbstractService::ServiceControlSource ServiceControlSource
 
typedef vector< AbstractSessionSharedPtrSessionContainer
 Container type for all connected sessions. More...
 
typedef function< void(AbstractService *)> StateCallbackFunction
 Function prototype to be invoked when state changes. More...
 
typedef shared_ptr< void > StateChangedSubscriptionToken
 Handle given as return value to state callback registration. More...
 

Detailed Description

Adapter class between Java implemented services and AbstractService instance.

Constructor & Destructor Documentation

◆ ExternalServiceAdapter()

kanzi::connect::ExternalServiceAdapter::ExternalServiceAdapter ( const string &  identfier)

Constructor.

Parameters
identfierthe name of the service this adapter represents.

◆ ~ExternalServiceAdapter()

virtual kanzi::connect::ExternalServiceAdapter::~ExternalServiceAdapter ( )
inlineoverridevirtual

Destructor.

Member Function Documentation

◆ addSubscriptionExt()

bool kanzi::connect::ExternalServiceAdapter::addSubscriptionExt ( const string &  identifier,
shared_ptr< ExternalServiceSession session 
)
See also
kanzi::connect::connect::AbstractService

◆ findSubscribersExt()

vector<shared_ptr<ExternalServiceSession> > kanzi::connect::ExternalServiceAdapter::findSubscribersExt ( const string &  identifier)

◆ getContentProvider()

virtual ContentProviderCollectionSharedPtr kanzi::connect::ExternalServiceAdapter::getContentProvider ( )
inlineoverridevirtual

Returns content provider for this service.

Returns
Collection of content providers, created by this service.

Reimplemented from kanzi::connect::AbstractService.

◆ getGenericInvoker()

virtual GenericInvoker* kanzi::connect::ExternalServiceAdapter::getGenericInvoker ( )
overridevirtual
See also
kanzi::connect::connect::AbstractService

Reimplemented from kanzi::connect::AbstractService.

◆ getIdentifier()

virtual string kanzi::connect::ExternalServiceAdapter::getIdentifier ( ) const
overridevirtual

◆ hasSubscriptionsExt()

bool kanzi::connect::ExternalServiceAdapter::hasSubscriptionsExt ( const string &  identifier)

◆ onAcquireSession()

virtual AbstractSessionSharedPtr kanzi::connect::ExternalServiceAdapter::onAcquireSession ( int  clientId,
int  sessionId,
MessageDispatcher dispatcher,
const string &  instanceName 
)
overridevirtual

Session factorization method interface.

To be overrided by concrete services

Parameters
clientIdclient identifier number
sessionIdsession identifier number
dispatchermessage dispatching functionality for the session.
instanceNamename for the service/session instance
Returns
newly allocated session. ownership is transfered.

Implements kanzi::connect::AbstractService.

◆ onReleaseSession()

virtual void kanzi::connect::ExternalServiceAdapter::onReleaseSession ( AbstractSessionSharedPtr  session)
overridevirtual

Virtual method that inheriting classes can implement.

Can be used to receive notifications when sessions are destroyed.

Parameters
sessionidentifies the session to be released. ownership not transfered.

Reimplemented from kanzi::connect::AbstractService.

◆ onSubscriptionsEnded()

virtual void kanzi::connect::ExternalServiceAdapter::onSubscriptionsEnded ( const vector< string > &  identifiers)
protectedvirtual

Notifies that these streams no longer have any subscribers left (but they used to have) This is notified when a session is released without it first explicitly unsubscribing.

Parameters
identifiersContains the stream identifiers that have lost their subscribers

◆ receive()

virtual void kanzi::connect::ExternalServiceAdapter::receive ( shared_ptr< ExternalServiceSession session,
const MessagePackage message 
)
virtual

Invoked to receive incoming message.

This is handled in external code (Java etc)

Parameters
messagethe message to be processed.

◆ removeSubscriptionsExt()

vector<string> kanzi::connect::ExternalServiceAdapter::removeSubscriptionsExt ( shared_ptr< ExternalServiceSession session,
const string &  identifier = "" 
)

◆ transmitToAll()

virtual void kanzi::connect::ExternalServiceAdapter::transmitToAll ( const MessagePackage message)
virtual

Transmits a provided message to wire and delivers it to all sessions available.

Parameters
messagethe message to be sent.

◆ transmitToSession()

virtual bool kanzi::connect::ExternalServiceAdapter::transmitToSession ( shared_ptr< ExternalServiceSession session,
const MessagePackage message 
)
virtual

Transmits a provided message to specific session.

Parameters
sessionthe session where to send to message. Session presence is verified before making the call.
messagethe message to be sent.

The documentation for this class was generated from the following file: