class Scheduler


Module kio
Namespace KIO
Class Scheduler
Inherits QObject
The KIO.Scheduler manages io-slaves for the application. It also queues jobs and assigns the job to a slave when one becomes available.

There are 3 possible ways for a job to get a slave:

1. Direct

This is the default. When you create a job the KIO.Scheduler will be notified and will find either an existing slave that is idle or it will create a new slave for the job.

Example:

TransferJob *job = KIO.get(KUrl("http://www.kde.org"));

2. Scheduled

If you create a lot of jobs, you might want not want to have a slave for each job. If you schedule a job, a maximum number of slaves will be created. When more jobs arrive, they will be queued. When a slave is finished with a job, it will be assigned a job from the queue.

Example:

TransferJob *job = KIO.get(KUrl("http://www.kde.org"));
KIO.Scheduler.scheduleJob(job);

3. Connection Oriented

For some operations it is important that multiple jobs use the same connection. This can only be ensured if all these jobs use the same slave.

You can ask the scheduler to open a slave for connection oriented operations. You can then use the scheduler to assign jobs to this slave. The jobs will be queued and the slave will handle these jobs one after the other.

Example:

Slave *slave = KIO.Scheduler.getConnectedSlave(
KUrl("pop3://bastian:password@mail.kde.org"));
TransferJob *job1 = KIO.get(
KUrl("pop3://bastian:password@mail.kde.org/msg1"));
KIO.Scheduler.assignJobToSlave(slave, job1);
TransferJob *job2 = KIO.get(
KUrl("pop3://bastian:password@mail.kde.org/msg2"));
KIO.Scheduler.assignJobToSlave(slave, job2);
TransferJob *job3 = KIO.get(
KUrl("pop3://bastian:password@mail.kde.org/msg3"));
KIO.Scheduler.assignJobToSlave(slave, job3);

// ... Wait for jobs to finish...

KIO.Scheduler.disconnectSlave(slave);

Note that you need to explicitly disconnect the slave when the connection goes down, so your error handler should contain:

if (error == KIO.ERR_CONNECTION_BROKEN)
KIO.Scheduler.disconnectSlave(slave);

See also KIO.Slave

See also KIO.Job



methods