~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/scheduler.h

  • Committer: Brian Aker
  • Date: 2009-05-23 17:13:03 UTC
  • mfrom: (1034.1.8 merge)
  • Revision ID: brian@gaz-20090523171303-d28xhutqic0xe2b4
Merge Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
1
/*
 
2
 -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
3
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
 
4
 
4
5
 *  Definitions required for Configuration Variables plugin
5
 
 *
 
6
 
6
7
 *  Copyright (C) 2008 Sun Microsystems
7
8
 *
8
9
 *  This program is free software; you can redistribute it and/or modify
19
20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
21
 */
21
22
 
22
 
#ifndef DRIZZLED_PLUGIN_SCHEDULER_H
23
 
#define DRIZZLED_PLUGIN_SCHEDULER_H
24
 
 
25
 
#include "drizzled/session.h"
26
 
#include "drizzled/plugin/plugin.h"
 
23
#ifndef DRIZZLED_PLUGIN_SCHEDULING_H
 
24
#define DRIZZLED_PLUGIN_SCHEDULING_H
27
25
 
28
26
#include <string>
29
27
#include <vector>
30
28
 
31
 
namespace drizzled
32
 
{
33
 
 
34
 
class Session;
35
 
 
36
 
namespace plugin
37
 
{
38
 
 
39
 
/**
40
 
 * This class should be used by scheduler plugins to implement custom session
41
 
 * schedulers.
42
 
 */
43
 
class Scheduler : public Plugin
44
 
{
45
 
  /* Disable default constructors */
46
 
  Scheduler();
47
 
  Scheduler(const Scheduler &);
48
 
  Scheduler& operator=(const Scheduler &);
 
29
class Scheduler
 
30
{
 
31
private:
 
32
  uint32_t max_threads;
49
33
public:
50
 
  explicit Scheduler(std::string name_arg)
51
 
    : Plugin(name_arg, "Scheduler")
52
 
  {}
 
34
 
 
35
  Scheduler(uint32_t threads)
 
36
    : max_threads(threads) {}
 
37
 
53
38
  virtual ~Scheduler() {}
54
39
 
55
 
  /**
56
 
   * Add a session to the scheduler. When the scheduler is ready to run the
57
 
   * session, it should call session->run().
58
 
   */
59
 
  virtual bool addSession(Session::shared_ptr &session)= 0;
60
 
 
61
 
  /**
62
 
   * Notify the scheduler that it should be killed gracefully.
63
 
   */
64
 
  virtual void killSession(Session *) {}
65
 
 
66
 
  /**
67
 
   * This is called when a scheduler should kill the session immedaitely.
68
 
   */
69
 
  virtual void killSessionNow(Session::shared_ptr&) {}
70
 
 
71
 
  static bool addPlugin(plugin::Scheduler *sced);
72
 
  static void removePlugin(plugin::Scheduler *sced);
73
 
  static bool setPlugin(const std::string& name);
74
 
  static Scheduler *getScheduler();
75
 
};
76
 
 
77
 
} /* namespace plugin */
78
 
} /* namespace drizzled */
79
 
 
80
 
#endif /* DRIZZLED_PLUGIN_SCHEDULER_H */
 
40
  uint32_t get_max_threads()
 
41
  {
 
42
    return max_threads;
 
43
  }
 
44
 
 
45
  virtual uint32_t count(void)= 0;
 
46
  virtual bool add_connection(Session *session)= 0;
 
47
 
 
48
  virtual bool end_thread(Session *, bool) {return false;}
 
49
  virtual bool init_new_connection_thread(void)
 
50
  {
 
51
    if (my_thread_init())
 
52
      return true;
 
53
    return false;
 
54
  }
 
55
 
 
56
  virtual void post_kill_notification(Session *) {}
 
57
};
 
58
 
 
59
class SchedulerFactory
 
60
{
 
61
  std::string name;
 
62
  std::vector<std::string> aliases;
 
63
protected:
 
64
  Scheduler *scheduler;
 
65
public:
 
66
  SchedulerFactory(std::string name_arg): name(name_arg), scheduler(NULL) {}
 
67
  SchedulerFactory(const char *name_arg): name(name_arg), scheduler(NULL) {}
 
68
  virtual ~SchedulerFactory() {}
 
69
  virtual Scheduler *operator()(void)= 0;
 
70
  std::string getName() {return name;}
 
71
  const std::vector<std::string>& getAliases() {return aliases;}
 
72
  void addAlias(std::string alias)
 
73
  {
 
74
    aliases.push_back(alias);
 
75
  }
 
76
 
 
77
};
 
78
 
 
79
#endif /* DRIZZLED_PLUGIN_SCHEDULING_H */