knjappserver 0.0.17 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,9 +3,8 @@ source "http://rubygems.org"
3
3
  # Example:
4
4
  # gem "activesupport", ">= 2.3.5"
5
5
 
6
- gem "knjrbfw", ">= 0.0.8"
6
+ gem "knjrbfw"
7
7
  gem "erubis"
8
- gem "knjdbrevision", ">= 0.0.2"
9
8
  gem "mail"
10
9
 
11
10
  # Add dependencies to develop your gem here.
data/Gemfile.lock CHANGED
@@ -11,8 +11,6 @@ GEM
11
11
  rake
12
12
  json (1.6.1)
13
13
  json (1.6.1-java)
14
- knjdbrevision (0.0.3)
15
- knjrbfw (>= 0.0.3)
16
14
  knjrbfw (0.0.8)
17
15
  mail (2.3.0)
18
16
  i18n (>= 0.4.0)
@@ -45,8 +43,7 @@ DEPENDENCIES
45
43
  erubis
46
44
  jeweler (~> 1.6.3)
47
45
  json
48
- knjdbrevision (>= 0.0.2)
49
- knjrbfw (>= 0.0.8)
46
+ knjrbfw
50
47
  mail
51
48
  rcov
52
49
  rspec (~> 2.3.0)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.17
1
+ 0.0.18
data/knjappserver.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{knjappserver}
8
- s.version = "0.0.17"
8
+ s.version = "0.0.18"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kasper Johansen"]
12
- s.date = %q{2012-02-21}
12
+ s.date = %q{2012-02-25}
13
13
  s.description = %q{Which supports a lot of undocumented stuff.}
14
14
  s.email = %q{k@spernj.org}
15
15
  s.executables = ["check_running.rb", "knjappserver_start.rb"]
@@ -98,9 +98,8 @@ Gem::Specification.new do |s|
98
98
  s.specification_version = 3
99
99
 
100
100
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
101
- s.add_runtime_dependency(%q<knjrbfw>, [">= 0.0.8"])
101
+ s.add_runtime_dependency(%q<knjrbfw>, [">= 0"])
102
102
  s.add_runtime_dependency(%q<erubis>, [">= 0"])
103
- s.add_runtime_dependency(%q<knjdbrevision>, [">= 0.0.2"])
104
103
  s.add_runtime_dependency(%q<mail>, [">= 0"])
105
104
  s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
106
105
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -109,9 +108,8 @@ Gem::Specification.new do |s|
109
108
  s.add_development_dependency(%q<sqlite3>, [">= 0"])
110
109
  s.add_development_dependency(%q<json>, [">= 0"])
111
110
  else
112
- s.add_dependency(%q<knjrbfw>, [">= 0.0.8"])
111
+ s.add_dependency(%q<knjrbfw>, [">= 0"])
113
112
  s.add_dependency(%q<erubis>, [">= 0"])
114
- s.add_dependency(%q<knjdbrevision>, [">= 0.0.2"])
115
113
  s.add_dependency(%q<mail>, [">= 0"])
116
114
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
117
115
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -121,9 +119,8 @@ Gem::Specification.new do |s|
121
119
  s.add_dependency(%q<json>, [">= 0"])
122
120
  end
123
121
  else
124
- s.add_dependency(%q<knjrbfw>, [">= 0.0.8"])
122
+ s.add_dependency(%q<knjrbfw>, [">= 0"])
125
123
  s.add_dependency(%q<erubis>, [">= 0"])
126
- s.add_dependency(%q<knjdbrevision>, [">= 0.0.2"])
127
124
  s.add_dependency(%q<mail>, [">= 0"])
128
125
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
129
126
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -1,4 +1,5 @@
1
1
  require "uri"
2
+ require "knj/web"
2
3
 
3
4
  #If we are running on JRuby or Rubinius this will seriously speed things up if we are behind a proxy.
4
5
  if RUBY_PLATFORM == "java" or RUBY_ENGINE == "rbx"
@@ -15,7 +15,8 @@ class Knjappserver
15
15
  :default_page => "index.rhtml",
16
16
  :default_filetype => "text/html",
17
17
  :max_requests_working => 20,
18
- :size_send => 1024
18
+ :size_send => 1024,
19
+ :cleaner_timeout => 300
19
20
  }.merge(config)
20
21
 
21
22
  @config[:smtp_args] = {"smtp_host" => "localhost", "smtp_port" => 25} if !@config[:smtp_args]
@@ -270,6 +271,11 @@ class Knjappserver
270
271
  :name => :request_begin,
271
272
  :connections_max => 1
272
273
  )
274
+
275
+ #This event is used if the user himself wants stuff to be cleaned up when the appserver is cleaning up stuff.
276
+ @events.add_event(
277
+ :name => :on_clean
278
+ )
273
279
  end
274
280
 
275
281
  #Set up the 'vars'-variable that can be used to set custom global variables for web-requests.
@@ -91,32 +91,51 @@ class Knjappserver
91
91
  end
92
92
 
93
93
  #This flushes (writes) all session-data to the server and deletes old unused sessions from the database.
94
- self.timeout(:time => 300) do
94
+ self.timeout(:time => @config[:cleaner_timeout]) do
95
+ self.clean
96
+ end
97
+ end
98
+
99
+ #This method can be used to clean the appserver. Dont call this from a HTTP-request.
100
+ def clean
101
+ self.paused_exec do
95
102
  STDOUT.print "Cleaning sessions on appserver.\n" if @config[:debug]
96
103
 
97
- self.paused_exec do
98
- session_not_ids = []
99
- time_check = Time.now.to_i - 300
100
- newsessions = {}
101
- @sessions.each do |session_hash, session_data|
102
- session_data[:dbobj].flush
103
-
104
- if session_data[:time_lastused].to_i > time_check
105
- newsessions[session_hash] = session_data
106
- session_not_ids << session_data[:dbobj].id
107
- end
108
- end
109
-
110
- @sessions = newsessions
104
+ #Clean up various inactive sessions.
105
+ session_not_ids = []
106
+ time_check = Time.now.to_i - 300
107
+ newsessions = {}
108
+ @sessions.each do |session_hash, session_data|
109
+ session_data[:dbobj].flush
111
110
 
112
- STDOUT.print "Delete sessions...\n" if @config[:debug]
113
- @ob.list(:Session, {"id_not" => session_not_ids, "date_lastused_below" => (Time.now - 5356800)}) do |session|
114
- idhash = session[:idhash]
115
- STDOUT.print "Deleting session: '#{session.id}'.\n" if @config[:debug]
116
- @ob.delete(session)
117
- @sessions.delete(idhash)
111
+ if session_data[:time_lastused].to_i > time_check
112
+ newsessions[session_hash] = session_data
113
+ session_not_ids << session_data[:dbobj].id
118
114
  end
119
115
  end
116
+
117
+ @sessions = newsessions
118
+
119
+ STDOUT.print "Delete sessions...\n" if @config[:debug]
120
+ @ob.list(:Session, {"id_not" => session_not_ids, "date_lastused_below" => (Time.now - 5356800)}) do |session|
121
+ idhash = session[:idhash]
122
+ STDOUT.print "Deleting session: '#{session.id}'.\n" if @config[:debug]
123
+ @ob.delete(session)
124
+ @sessions.delete(idhash)
125
+ end
126
+
127
+
128
+ #Clean database weak references from the tables-module.
129
+ @db.clean
130
+
131
+ #Clean the object-handler.
132
+ @ob.clean_all
133
+
134
+ #Run garbage-collector.
135
+ GC.start
136
+
137
+ #Call various user-connected methods.
138
+ @events.call(:on_clean) if @events
120
139
  end
121
140
  end
122
141
  end
@@ -1,7 +1,7 @@
1
1
  class Knjappserver
2
2
  def initialize_threadding
3
3
  @config[:threadding] = {} if !@config.has_key?(:threadding)
4
- @config[:threadding][:max_running] = 1 if !@config[:threadding].has_key?(:max_running)
4
+ @config[:threadding][:max_running] = 8 if !@config[:threadding].has_key?(:max_running)
5
5
 
6
6
  @threadpool = Knj::Threadpool.new(:threads => @config[:threadding][:max_running], :sleep => 0.1)
7
7
  @threadpool.events.connect(:on_error) do |event, error|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knjappserver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.18
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,23 +9,23 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-21 00:00:00.000000000 +01:00
12
+ date: 2012-02-25 00:00:00.000000000 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: knjrbfw
17
- requirement: &16146280 !ruby/object:Gem::Requirement
17
+ requirement: &27853120 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
21
21
  - !ruby/object:Gem::Version
22
- version: 0.0.8
22
+ version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *16146280
25
+ version_requirements: *27853120
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: erubis
28
- requirement: &16145700 !ruby/object:Gem::Requirement
28
+ requirement: &27852420 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,21 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *16145700
37
- - !ruby/object:Gem::Dependency
38
- name: knjdbrevision
39
- requirement: &16145200 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ! '>='
43
- - !ruby/object:Gem::Version
44
- version: 0.0.2
45
- type: :runtime
46
- prerelease: false
47
- version_requirements: *16145200
36
+ version_requirements: *27852420
48
37
  - !ruby/object:Gem::Dependency
49
38
  name: mail
50
- requirement: &16144680 !ruby/object:Gem::Requirement
39
+ requirement: &27837000 !ruby/object:Gem::Requirement
51
40
  none: false
52
41
  requirements:
53
42
  - - ! '>='
@@ -55,10 +44,10 @@ dependencies:
55
44
  version: '0'
56
45
  type: :runtime
57
46
  prerelease: false
58
- version_requirements: *16144680
47
+ version_requirements: *27837000
59
48
  - !ruby/object:Gem::Dependency
60
49
  name: rspec
61
- requirement: &16144020 !ruby/object:Gem::Requirement
50
+ requirement: &27836360 !ruby/object:Gem::Requirement
62
51
  none: false
63
52
  requirements:
64
53
  - - ~>
@@ -66,10 +55,10 @@ dependencies:
66
55
  version: 2.3.0
67
56
  type: :development
68
57
  prerelease: false
69
- version_requirements: *16144020
58
+ version_requirements: *27836360
70
59
  - !ruby/object:Gem::Dependency
71
60
  name: bundler
72
- requirement: &16143360 !ruby/object:Gem::Requirement
61
+ requirement: &27835720 !ruby/object:Gem::Requirement
73
62
  none: false
74
63
  requirements:
75
64
  - - ~>
@@ -77,10 +66,10 @@ dependencies:
77
66
  version: 1.0.0
78
67
  type: :development
79
68
  prerelease: false
80
- version_requirements: *16143360
69
+ version_requirements: *27835720
81
70
  - !ruby/object:Gem::Dependency
82
71
  name: jeweler
83
- requirement: &16141740 !ruby/object:Gem::Requirement
72
+ requirement: &27835120 !ruby/object:Gem::Requirement
84
73
  none: false
85
74
  requirements:
86
75
  - - ~>
@@ -88,10 +77,10 @@ dependencies:
88
77
  version: 1.6.3
89
78
  type: :development
90
79
  prerelease: false
91
- version_requirements: *16141740
80
+ version_requirements: *27835120
92
81
  - !ruby/object:Gem::Dependency
93
82
  name: rcov
94
- requirement: &16090320 !ruby/object:Gem::Requirement
83
+ requirement: &27834480 !ruby/object:Gem::Requirement
95
84
  none: false
96
85
  requirements:
97
86
  - - ! '>='
@@ -99,10 +88,10 @@ dependencies:
99
88
  version: '0'
100
89
  type: :development
101
90
  prerelease: false
102
- version_requirements: *16090320
91
+ version_requirements: *27834480
103
92
  - !ruby/object:Gem::Dependency
104
93
  name: sqlite3
105
- requirement: &16089600 !ruby/object:Gem::Requirement
94
+ requirement: &27833880 !ruby/object:Gem::Requirement
106
95
  none: false
107
96
  requirements:
108
97
  - - ! '>='
@@ -110,10 +99,10 @@ dependencies:
110
99
  version: '0'
111
100
  type: :development
112
101
  prerelease: false
113
- version_requirements: *16089600
102
+ version_requirements: *27833880
114
103
  - !ruby/object:Gem::Dependency
115
104
  name: json
116
- requirement: &16088860 !ruby/object:Gem::Requirement
105
+ requirement: &27833320 !ruby/object:Gem::Requirement
117
106
  none: false
118
107
  requirements:
119
108
  - - ! '>='
@@ -121,7 +110,7 @@ dependencies:
121
110
  version: '0'
122
111
  type: :development
123
112
  prerelease: false
124
- version_requirements: *16088860
113
+ version_requirements: *27833320
125
114
  description: Which supports a lot of undocumented stuff.
126
115
  email: k@spernj.org
127
116
  executables:
@@ -217,7 +206,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
217
206
  version: '0'
218
207
  segments:
219
208
  - 0
220
- hash: -3001161973856161206
209
+ hash: -3895621098014444760
221
210
  required_rubygems_version: !ruby/object:Gem::Requirement
222
211
  none: false
223
212
  requirements: