# 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

- Scheduler (a0)

  returns ctor
  Not implemented

  Argument | Type | Default
  --- | --- | ---
  a0 | KIO.Scheduler |

- Scheduler ( )

  returns ctor
  Not implemented

- Scheduler ( )

  returns dtor
  Not implemented

- assignJobToSlave (slave, job)

  returns bool
  static

  Argument | Type | Default
  --- | --- | ---
  slave | KIO.Slave |
  job | KIO.SimpleJob |

- cancelJob (job)

  returns Nothing
  static

  Argument | Type | Default
  --- | --- | ---
  job | KIO.SimpleJob |

  Stop the execution of a job.

  job - the job to cancel

- checkSlaveOnHold (b)

  returns Nothing
  static

  Argument | Type | Default
  --- | --- | ---
  b | bool |

  When true, the next job will check whether KLauncher has a slave on hold that is suitable for the job.

  b - true when KLauncher has a job on hold

- connect (signal, receiver, member)

  returns bool
  static

  Argument | Type | Default
  --- | --- | ---
  signal | char |
  receiver | QObject |
  member | char |

  Function to connect signals emitted by the scheduler.

  See also slaveConnected()

  See also slaveError()

- connect (sender, signal, receiver, member)

  returns bool
  static

  Argument | Type | Default
  --- | --- | ---
  sender | QObject |
  signal | char |
  receiver | QObject |
  member | char |

- connect (sender, signal, member)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  sender | QObject |
  signal | char |
  member | char |

- disconnect (sender, signal, receiver, member)

  returns bool
  static

  Argument | Type | Default
  --- | --- | ---
  sender | QObject |
  signal | char |
  receiver | QObject |
  member | char |

- disconnectSlave (slave)

  returns bool
  static

  Argument | Type | Default
  --- | --- | ---
  slave | KIO.Slave |

- doJob (job)

  returns Nothing
  static

  Argument | Type | Default
  --- | --- | ---
  job | KIO.SimpleJob |

  Register job with the scheduler. The default is to create a new slave for the job if no slave is available. This can be changed by calling scheduleJob.

  job - the job to register

- emitReparseSlaveConfiguration ( )

  returns Nothing
  static

- getConnectedSlave (url, config)

  returns KIO.Slave
  static

  Argument | Type | Default
  --- | --- | ---
  url | KUrl |
  config | KIO.MetaData | KIO.MetaData()

  Requests a slave for use in connection-oriented mode.

  url - This defines the username,password,host & port to connect with.

  config - Configuration data for the slave.

  Returns A pointer to a connected slave or 0 if an error occurred.

  See also assignJobToSlave()

  See also disconnectSlave()

- jobFinished (job, slave)

  returns Nothing
  static

  Argument | Type | Default
  --- | --- | ---
  job | KIO.SimpleJob |
  slave | KIO.Slave |

  Called when a job is done.

  job - the finished job

  slave - the slave that executed the job

- publishSlaveOnHold ( )

  returns Nothing
  static

  Send the slave that was put on hold back to KLauncher. This allows another process to take over the slave and resume the job that was started.

- putSlaveOnHold (job, url)

  returns Nothing
  static

  Argument | Type | Default
  --- | --- | ---
  job | KIO.SimpleJob |
  url | KUrl |

  Puts a slave on notice. A next job may reuse this slave if it requests the same URL.

  A job can be put on hold after it has emit'ed its mimetype. Based on the mimetype, the program can give control to another component in the same process which can then resume the job by simply asking for the same URL again.

  job - the job that should be stopped

  url - the URL that is handled by the url

- registerWindow (wid)

  returns Nothing
  static

  Argument | Type | Default
  --- | --- | ---
  wid | QWidget |

  Register the mainwindow wid with the KIO subsystem Do not call this, it is called automatically from void KIO.Job.setWindow(QWidget*).

  wid - the window to register

- removeSlaveOnHold ( )

  returns Nothing
  static

  Removes any slave that might have been put on hold. If a slave was put on hold it will be killed.

- reparseSlaveConfiguration (a0)

  returns Nothing
  SIGNAL ("reparseSlaveConfiguration (const QString&)")

  Argument | Type | Default
  --- | --- | ---
  a0 | QString |

- scheduleJob (job)

  returns Nothing
  static

  Argument | Type | Default
  --- | --- | ---
  job | KIO.SimpleJob |

  Calling ths function makes that job gets scheduled for later execution, if multiple jobs are registered it might wait for other jobs to finish.

  job - the job to schedule

- slaveConnected (slave)

  returns Nothing
  SIGNAL ("slaveConnected (Slave*)")

  Argument | Type | Default
  --- | --- | ---
  slave | KIO.Slave |

- slaveError (slave, error, errorMsg)

  returns Nothing
  SIGNAL ("slaveError (Slave*, int, const QString&)")

  Argument | Type | Default
  --- | --- | ---
  slave | KIO.Slave |
  error | int |
  errorMsg | QString |

- unregisterWindow (wid)

  returns Nothing
  static

  Argument | Type | Default
  --- | --- | ---
  wid | QObject |

  Internal Unregisters the window registered by registerWindow().