Development/Tutorials/Metadata/Nepomuk/NepomukServer: Difference between revisions

From KDE TechBase
No edit summary
No edit summary
 
(8 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{TutorialBrowser|
{{TutorialBrowser|
series=Nepomuk|
series=[[../|Nepomuk]]|
name=Nepomuk Server|
name=Nepomuk Server|
pre=|
pre=|
Line 8: Line 10:


==The Nepomuk Server==
==The Nepomuk Server==
[[Image:Nepomuk-Architecture.png|center|thumbnail|500px|Nepomuk Architecture]]


The Nepomuk Server is a daemon which hosts all Nepomuk service including the main Nepomuk data repository. In normal operation it is started through KDE's autostart feature when logging into KDE. Starting it manually is as simple as typing "nepomukserver". This will start the daemon and all services.
The Nepomuk Server is a daemon which hosts all Nepomuk service including the main Nepomuk data repository. In normal operation it is started through KDE's autostart feature when logging into KDE. Starting it manually is as simple as typing "nepomukserver". This will start the daemon and all services.


The main repository is an RDF database using [http://soprano.sf.net Soprano] including a [http://api.kde.org/kdesupport-api/kdesupport-apidocs/soprano/html/namespaceSoprano_1_1Index.html Soprano full text index]. The interface of the repository is exported via DBus (The DBus interface is defined by [http://api.kde.org/kdesupport-api/kdesupport-apidocs/soprano/html/soprano_server_dbus.html Soprano]). When using the Soprano DBus interface from within a KDE application there is no need to bother with QDBus. Soprano provides the [http://api.kde.org/kdesupport-api/kdesupport-apidocs/soprano/html/classSoprano_1_1Client_1_1DBusModel.html Soprano::Client::DBusModel] class which wraps all DBus communication into a nice [http://api.kde.org/kdesupport-api/kdesupport-apidocs/soprano/html/classSoprano_1_1Model.html Soprano::Model] interface.
Services are started as separate processes via the service wrapper application "nepomukservicestub". This design descision has been taken to enhance the stability of the Nepomuk system. Services are implemented by subclassing Nepomuk::Service and exporting it like any other KDE plugin. [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk/html/classNepomuk_1_1Service.html The Nepomuk::Service class documentation] explains this in detail.
 
With kdebase a set of default services are installed. Most notably the storage service which hosts the RDF database used to store all Nepomuk-related data. [[Development/Tutorials/Metadata/Nepomuk/NepomukServices|Nepomuk Services]] explains the services in detail.
 
===Using the Server===
 
The Nepomuk server is registered as a DBus service at ''org.kde.NepomukServer'' and provides three DBus interfaces: The service manager, the legacy storage bridge, and the standard configuration interface.
 
====Service Manager====
 
The '''Service Manager DBus Interface''' named ''org.kde.nepomuk.ServiceManager'' and exported at ''servicemanager'' provides methods to start and stop [[../NepomukServices|Nepomuk Services]], to list available or running services, and to request some basic information about services:
 
<syntaxhighlight lang="text">QStringList availableServices()</syntaxhighlight>
 
Lists the names of all available services, running and non-running.
 
<syntaxhighlight lang="text">bool isServiceAutostarted(QString service)</syntaxhighlight>
Checks if a service is started automatically.
 
<syntaxhighlight lang="text">bool isServiceInitialized(QString name)</syntaxhighlight>
Checks if a services is running and initialized (running services might still be initializing).
 
<syntaxhighlight lang="text">QStringList runningServices()</syntaxhighlight>
Lists the names of all running services.
 
<syntaxhighlight lang="text">void serviceInitialized(QString name)</syntaxhighlight>
Signal which is emitted once a service finished initialization and is ready for usage.
 
<syntaxhighlight lang="text">void setServiceAutostarted(QString service, bool autostart)</syntaxhighlight>
Change the autostart behaviour of a service.
 
<syntaxhighlight lang="text">bool startService(QString name)</syntaxhighlight>
Start a service. This will also start all dependencies.
 
<syntaxhighlight lang="text">bool stopService(QString name)</syntaxhighlight>
Stop a service. This will also stop all services depending on the stopped one.
 
 
====Legacy Storage====
The '''Legacy Storage interface''' exported at ''org.soprano.Server'' is a simple wrapper around the storage service and not meant to be used in new applications.
 


There are two ways to access this wrapper model:
====Configuration====
The '''Nepomuk Service Configuration interface''' named ''org.kde.NepomukServer'' and exported at ''nepomukserver'' provides methods to configure the server. These methods are for example used by the Nepomuk KCM:


1. Use [http://api.kde.org/kdesupport-api/kdesupport-apidocs/soprano/html/classSoprano_1_1Client_1_1DBusClient.html Soprano::Client::DBusClient] to create a connection to the Nepomuk Server:
<syntaxhighlight lang="text">QString defaultRepository()</syntaxhighlight>
Returns the name of the default repository (the Soprano server API used in the storage service provides API to create multiple repositories. Nepomu only uses one: ''main'').


<code cppqt>
<syntaxhighlight lang="text">void enableNepomuk(bool enabled)</syntaxhighlight>
Soprano::Client::DBusClient* client = new Soprano::Client::DBusClient( "org.kde.NepomukStorage" );
The method to enable or disable the whole Nepomuk system. Setting ''enable'' to ''false'' will stop all services.
Soprano::Model* model = client->createModel( "main" );
</code>


The Nepomuk Server registers as DBus service ''org.kde.NepomukStorage'' and the name of the main data repository is ''main''.
<syntaxhighlight lang="text">void enableStrigi(bool enabled)</syntaxhighlight>
Enable or disable Strigi file indexing.


2. Use the Nepomuk library, i.e. [http://api.kde.org/4.x-api/kdelibs-apidocs/nepomuk/html/classNepomuk_1_1ResourceManager.html ResourceManager] to access the main model:
<syntaxhighlight lang="text">bool isNepomukEnabled()</syntaxhighlight>
Check if Nepomuk is enabled.


<code cppqt>
<syntaxhighlight lang="text">bool isStrigiEnabled()</syntaxhighlight>
Soprano::Model* model = Nepomuk::ResourceManager::instance()->mainModel();
Check if Strigi is enabled.
</code>


The advantage of the first version is that there is no need to link to libnepomuk. On the other hand the main model as provided by libnepomuk connects via a local socket if available which is faster. Also, it provides an automatic re-connect feature.
<syntaxhighlight lang="text">void quit()</syntaxhighlight>
Quit the Nepomuk server and all services. ''Caution: this method is only intended for debugging purposes.''


So all in all the easy way is also the recommended one: use libnepomuk and the ResourceManager to access the data.
<syntaxhighlight lang="text">void reconfigure()</syntaxhighlight>
Re-read the configuration. Normally there is no need to call this method.

Latest revision as of 10:49, 15 July 2012


Nepomuk Server
Tutorial Series   Nepomuk
Previous  
What's Next   Advanced Queries
Further Reading   Introduction to RDF and Ontologies, Handling Resources with Nepomuk, Nepomuk Services

The Nepomuk Server

Nepomuk Architecture

The Nepomuk Server is a daemon which hosts all Nepomuk service including the main Nepomuk data repository. In normal operation it is started through KDE's autostart feature when logging into KDE. Starting it manually is as simple as typing "nepomukserver". This will start the daemon and all services.

Services are started as separate processes via the service wrapper application "nepomukservicestub". This design descision has been taken to enhance the stability of the Nepomuk system. Services are implemented by subclassing Nepomuk::Service and exporting it like any other KDE plugin. The Nepomuk::Service class documentation explains this in detail.

With kdebase a set of default services are installed. Most notably the storage service which hosts the RDF database used to store all Nepomuk-related data. Nepomuk Services explains the services in detail.

Using the Server

The Nepomuk server is registered as a DBus service at org.kde.NepomukServer and provides three DBus interfaces: The service manager, the legacy storage bridge, and the standard configuration interface.

Service Manager

The Service Manager DBus Interface named org.kde.nepomuk.ServiceManager and exported at servicemanager provides methods to start and stop Nepomuk Services, to list available or running services, and to request some basic information about services:

QStringList availableServices()

Lists the names of all available services, running and non-running.

bool isServiceAutostarted(QString service)

Checks if a service is started automatically.

bool isServiceInitialized(QString name)

Checks if a services is running and initialized (running services might still be initializing).

QStringList runningServices()

Lists the names of all running services.

void serviceInitialized(QString name)

Signal which is emitted once a service finished initialization and is ready for usage.

void setServiceAutostarted(QString service, bool autostart)

Change the autostart behaviour of a service.

bool startService(QString name)

Start a service. This will also start all dependencies.

bool stopService(QString name)

Stop a service. This will also stop all services depending on the stopped one.


Legacy Storage

The Legacy Storage interface exported at org.soprano.Server is a simple wrapper around the storage service and not meant to be used in new applications.


Configuration

The Nepomuk Service Configuration interface named org.kde.NepomukServer and exported at nepomukserver provides methods to configure the server. These methods are for example used by the Nepomuk KCM:

QString defaultRepository()

Returns the name of the default repository (the Soprano server API used in the storage service provides API to create multiple repositories. Nepomu only uses one: main).

void enableNepomuk(bool enabled)

The method to enable or disable the whole Nepomuk system. Setting enable to false will stop all services.

void enableStrigi(bool enabled)

Enable or disable Strigi file indexing.

bool isNepomukEnabled()

Check if Nepomuk is enabled.

bool isStrigiEnabled()

Check if Strigi is enabled.

void quit()

Quit the Nepomuk server and all services. Caution: this method is only intended for debugging purposes.

void reconfigure()

Re-read the configuration. Normally there is no need to call this method.