KDE 4.9 PyKDE API Reference

- KDE's Python API

# ServerCore Class Reference

`from PyKDE4.soprano import *`

Inherits: QObject,Soprano.Error.ErrorCache
Namespace: Soprano.Server

## Detailed Description

\class ServerCore servercore.h Soprano/Server/ServerCore

Central %Soprano server class.

The %ServerCore provides a %Soprano server which maintains a set of named Model instances that can be accessed by clients over a tcp connection through Server.BackendPlugin.

Creating a server is very simple: Either derive from ServerCore or create an instance and then call start() to make the server listen for incoming connections.

     Soprano.Server.ServerCore core;
     core.start();

Optionally ServerCore can be configured using normal BackendSetting settings through setBackendSettings().

Be aware the ServerCode supports multiple ways of communication. start() opens a TCP socket to accept new connections, registerAsDBusObject() registers a DBus interface on the DBus session bus. Both ways of communication can be used simultaneously.

ServerCore will spawn a new thread for each incoming TCP or local socket connection. In addition the D-Bus interface is running in its own thread. The maximum number of threads that are spawned can be set via setMaximumConnectionCount(). By default there is no restriction on the maximum thread count to keep backwards compatibility.

Author:
  Sebastian Trueg <trueg@kde.org>

## Attributes
int | DEFAULT_PORT
## Methods
| __init__ (self, QObject parent=0)
QStringList | allModels (self)
Soprano.Backend | backend (self)
[Soprano.BackendSetting] | backendSettings (self)
Soprano.Model | createModel (self, [Soprano.BackendSetting] settings)
bool | listen (self, int port=Soprano.Server.ServerCore.DEFAULT_PORT)
int | maximumConnectionCount (self)
Soprano.Model | model (self, QString name)
| registerAsDBusObject (self, QString objectPath=QString())
| removeModel (self, QString name)
int | serverPort (self)
| setBackend (self, Soprano.Backend backend)
| setBackendSettings (self, [Soprano.BackendSetting] settings)
| setMaximumConnectionCount (self, int max)
bool | start (self, QString socketPath=QString())

## Method Documentation

__init__ | ( | self, |
|  | QObject | parent=0
| ) |  |  |

QStringList allModels | ( |  | self ) |

Retrieve all models that have been loaded.

Returns:
  A list of Model names.

Soprano.Backend backend | ( |  | self ) |

The Backend used by the Server to create Model instances.

[Soprano.BackendSetting] backendSettings | ( |  | self ) |

Retrieve the backend settings configured via setBackendSettings().

Returns:
  A list of BackendSetting objects.

Soprano.Model createModel | ( | self, |
|  | [Soprano.BackendSetting] | settings
| ) |  |  |

Create a new Model. The default implementation uses the configured Backend with the configured settings to create a new Model. This method can be reimplemented to create specialized Model, for example in combination with some FilterModel.

Parameters:

  | settings | The settings to use (a reimplementation may choose to ignore the settings.)

Returns:
  A newly create Model.

bool listen | ( | self, |
|  | int | port=Soprano.Server.ServerCore.DEFAULT_PORT
| ) |  |  |

Start the Server. Calling this method will make the Server listen on the specified port for incoming client connections.

Parameters:

  | port | The port to listen on for client connections.

Use Client.TcpClient to connect.

Warning:
  Via the TCP connection signals are not supported. Thus, the models created by it will not emit signals such as Model.statementAdded. Also no permission handling or any kind of security is implemented at the moment. Thus, if a server is running and is listening on a port, it is open to connections from any client on any computer in the network.

Returns:
  true if the server was successfully started, false otherwise.

int maximumConnectionCount | ( |  | self ) |

The maximum number of incoming connections that are served.

Returns:
  The maxium number of connections the server will handle or 0 if there is no restriction.

\sa setMaximumConnectionCount.

Since:
  2.4

Soprano.Model model | ( | self, |
|  | QString | name
| ) |  |  |

Get or create Model with the specific name. The default implementation will use createModel() to create a new Model if none with the specified name exists and protect it against deadlocks with a Util.AsyncModel.

Parameters:

  | name | The name of the requested Model.

registerAsDBusObject | ( | self, |
|  | QString | objectPath=QString()
| ) |  |  |

Register the ServerCore as a DBus object. The process needs to be registered as a DBus service before (QDBusConnection.registerService()).

Parameters:

  | objectPath | The DBus object path to register the server as. If empty the default path will be used (/org/soprano/Server).

Use Client.DBusClient to connect.

In case Soprano is compiled without D-Bus support this method does nothing.

D-Bus clients will be served in a separate thread.

removeModel | ( | self, |
|  | QString | name
| ) |  |  |

Remove a model and delete all data in it. Use with care.

Be aware that the Model instance will also be deleted.

Should be reimplemented if model() is reimplemented.

Parameters:

  | name | The name of the requested Model.

Warning:
  This is not the same as deleting the Model instance. It will also delete all the data on the harddisk.

int serverPort | ( |  | self ) |

Returns:
  The port this server is listening on or 0 if listen has not been called successfully.

Since:
  2.1

setBackend | ( | self, |
|  | Soprano.Backend | backend
| ) |  |  |

Set the Backend used in the Server to create Models.

setBackendSettings | ( | self, |
|  | [Soprano.BackendSetting] | settings
| ) |  |  |

Set the settings that are to be used by createModel() to create new Model instances. Be aware that Soprano.BackendOptionStorageDir will be changed to include a subdir which is the Model's name.

Parameters:

  | settings | The settings to use for new Models.

setMaximumConnectionCount | ( | self, |
|  | int | max
| ) |  |  |

Set the maximum number of TCP and local socket connections. If the max is reached new incoming connections are refused.

This makes sense to restrict the number of threads the server spawns.

A typical usage would be to server a max number of clients via a local socket connection and let the rest share the one D-Bus interface.

Parameters:

  | max | The maximum number of connections. Using a value of 0 means no restriction.

Since:
  2.4

bool start | ( | self, |
|  | QString | socketPath=QString()
| ) |  |  |

Start the core on a local socket. On Windows this is a named pipe and on Unix this this is a local domain socket.

Use Client.LocalSocketClient to connect.

Warning:
  Via the local socket connection signals are not supported.

Returns:
  true if the local socket could be successfully opened. false on error. See ErrorCache.lastError() for details.

## Attribute Documentation

int DEFAULT_PORT