rdf-threadsafe 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +14 -0
- data/VERSION +1 -0
- data/lib/rdf/threadsafe/module.rb +23 -0
- data/lib/rdf/threadsafe/util/cache.rb +15 -0
- data/lib/rdf/threadsafe.rb +146 -0
- metadata +88 -0
data/README
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
RDF/Threadsafe: An attempt to make RDF.rb work safely in JRuby Threads
|
2
|
+
==============================
|
3
|
+
|
4
|
+
RDF.rb makes extensive use of autoload, in fact it advertises that very fact. This is great for almost everything you would want to use RDF.rb for, unless you happen to want to use it in a multithreaded JRuby environment (see: <http://jira.codehaus.org/browse/JRUBY-3194>). RDF/Threadsafe is an attempt to undo autoload's mischief (at the expense of requiring all of RDF.rb to be loaded).
|
5
|
+
|
6
|
+
Note, this should *only* matter for JRuby (and, possibly, Rubinius) and will be necessary until JRuby can get along with autoload (which, unfortunately, might be a while, if ever). Ruby 1.9 now works with autoload.
|
7
|
+
|
8
|
+
Changes from RDF.rb:
|
9
|
+
|
10
|
+
* Overrides Method#autoload, which calls require for any autoload in the RDF module namespace (and defaults to regular autoload to anything outside).
|
11
|
+
* Because of a problem with RDF::Util::Cache and frozen objects (namely the RDF Vocabulary object), there is a modified version of #define_finalizer! that adds exception handling.
|
12
|
+
* All of the class methods in rdf.rb had to be included in threadsafe.rb because they are needed when the other files are required, but autoload fires before the methods are interpreted. Because of this, RDF/Threadsafe will need to be pegged to specific versions of RDF.rb
|
13
|
+
|
14
|
+
This should work for everything that falls under the RDF Module namespace (assuming there are no dependency errors based on the autoload order).
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.3.1
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Module
|
2
|
+
##
|
3
|
+
# Take Module#autoload, unbind it and rebind it as #regular_autoload
|
4
|
+
#
|
5
|
+
define_method(:regular_autoload, self.instance_method(:autoload).unbind)
|
6
|
+
|
7
|
+
##
|
8
|
+
# For any autoload call from a caller in the RDF module namespace, use require instead.
|
9
|
+
# All other callers use the normal autoload
|
10
|
+
#
|
11
|
+
def rdf_autoload(sym, path)
|
12
|
+
if self.name =~ /^RDF(\:\:|$)/
|
13
|
+
require path
|
14
|
+
else
|
15
|
+
regular_autoload(sym, path)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
##
|
20
|
+
# Alias rdf_autoload to autoload
|
21
|
+
#
|
22
|
+
alias_method :autoload, :rdf_autoload
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module RDF; module Util
|
2
|
+
class Cache
|
3
|
+
##
|
4
|
+
# @param [Object] value
|
5
|
+
# @return [void]
|
6
|
+
def define_finalizer!(value)
|
7
|
+
# We need to catch when we try to pass a frozen object (namely the RDF vocabulary)
|
8
|
+
begin
|
9
|
+
ObjectSpace.define_finalizer(value, finalizer)
|
10
|
+
rescue TypeError
|
11
|
+
return
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end; end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/threadsafe/module'
|
2
|
+
module RDF
|
3
|
+
##
|
4
|
+
# Alias for `RDF::Resource.new`.
|
5
|
+
#
|
6
|
+
# @return [RDF::Resource]
|
7
|
+
def self.Resource(*args, &block)
|
8
|
+
Resource.new(*args, &block)
|
9
|
+
end
|
10
|
+
|
11
|
+
##
|
12
|
+
# Alias for `RDF::Node.new`.
|
13
|
+
#
|
14
|
+
# @return [RDF::Node]
|
15
|
+
def self.Node(*args, &block)
|
16
|
+
Node.new(*args, &block)
|
17
|
+
end
|
18
|
+
|
19
|
+
##
|
20
|
+
# Alias for `RDF::URI.new`.
|
21
|
+
#
|
22
|
+
# @overload URI(uri)
|
23
|
+
# @param [URI, String, #to_s] uri
|
24
|
+
#
|
25
|
+
# @overload URI(options = {})
|
26
|
+
# @param [Hash{Symbol => Object} options
|
27
|
+
#
|
28
|
+
# @return [RDF::URI]
|
29
|
+
def self.URI(*args, &block)
|
30
|
+
case uri = args.first
|
31
|
+
when RDF::URI then uri
|
32
|
+
else case
|
33
|
+
when uri.respond_to?(:to_uri) then uri.to_uri
|
34
|
+
else URI.new(*args, &block)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
##
|
40
|
+
# Alias for `RDF::Literal.new`.
|
41
|
+
#
|
42
|
+
# @return [RDF::Literal]
|
43
|
+
def self.Literal(*args, &block)
|
44
|
+
case literal = args.first
|
45
|
+
when RDF::Literal then literal
|
46
|
+
else Literal.new(*args, &block)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# Alias for `RDF::Graph.new`.
|
52
|
+
#
|
53
|
+
# @return [RDF::Graph]
|
54
|
+
def self.Graph(*args, &block)
|
55
|
+
Graph.new(*args, &block)
|
56
|
+
end
|
57
|
+
|
58
|
+
##
|
59
|
+
# Alias for `RDF::Statement.new`.
|
60
|
+
#
|
61
|
+
# @return [RDF::Statement]
|
62
|
+
def self.Statement(*args, &block)
|
63
|
+
Statement.new(*args, &block)
|
64
|
+
end
|
65
|
+
|
66
|
+
##
|
67
|
+
# Alias for `RDF::Vocabulary.create`.
|
68
|
+
#
|
69
|
+
# @param [String] uri
|
70
|
+
# @return [Class]
|
71
|
+
def self.Vocabulary(uri)
|
72
|
+
Vocabulary.create(uri)
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
# @return [URI]
|
77
|
+
def self.type
|
78
|
+
self[:type]
|
79
|
+
end
|
80
|
+
|
81
|
+
##
|
82
|
+
# @return [#to_s] property
|
83
|
+
# @return [URI]
|
84
|
+
def self.[](property)
|
85
|
+
RDF::URI.intern([to_uri.to_s, property.to_s].join)
|
86
|
+
end
|
87
|
+
|
88
|
+
##
|
89
|
+
# @param [Symbol] property
|
90
|
+
# @return [URI]
|
91
|
+
# @raise [NoMethodError]
|
92
|
+
def self.method_missing(property, *args, &block)
|
93
|
+
if args.empty?
|
94
|
+
self[property]
|
95
|
+
else
|
96
|
+
super
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
##
|
101
|
+
# @return [URI]
|
102
|
+
def self.to_rdf
|
103
|
+
to_uri
|
104
|
+
end
|
105
|
+
|
106
|
+
##
|
107
|
+
# @return [URI]
|
108
|
+
def self.to_uri
|
109
|
+
RDF::URI.intern("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
|
110
|
+
end
|
111
|
+
|
112
|
+
class << self
|
113
|
+
# For compatibility with `RDF::Vocabulary.__name__`:
|
114
|
+
alias_method :__name__, :name
|
115
|
+
end
|
116
|
+
|
117
|
+
# Load order matters, this needs to be tweaked if JRuby throws NameErrors.
|
118
|
+
|
119
|
+
require 'rdf/util'
|
120
|
+
require 'rdf/util/cache'
|
121
|
+
require 'rdf/mixin/readable'
|
122
|
+
require 'rdf/mixin/writable'
|
123
|
+
require 'rdf/mixin/countable'
|
124
|
+
require 'rdf/mixin/enumerable'
|
125
|
+
require 'rdf/mixin/queryable'
|
126
|
+
require 'rdf/mixin/mutable'
|
127
|
+
require 'rdf/mixin/durable'
|
128
|
+
require 'rdf/vocab.rb'
|
129
|
+
|
130
|
+
require 'rdf/model/value'
|
131
|
+
require 'rdf/model/term'
|
132
|
+
require 'rdf/vocab/xsd'
|
133
|
+
require 'rdf/vocab/foaf'
|
134
|
+
require 'rdf/model/resource'
|
135
|
+
require 'rdf/model/uri'
|
136
|
+
require 'rdf/model/literal/boolean'
|
137
|
+
require 'rdf/model/literal/numeric'
|
138
|
+
require 'rdf/model/literal/decimal'
|
139
|
+
require 'rdf/model/statement'
|
140
|
+
require 'rdf/repository'
|
141
|
+
require 'rdf/query'
|
142
|
+
require 'rdf/query/pattern'
|
143
|
+
end
|
144
|
+
|
145
|
+
require 'rdf'
|
146
|
+
require File.dirname(__FILE__) + '/threadsafe/util/cache'
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rdf-threadsafe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 17
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Ross Singer
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-02-08 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rdf
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - "="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 17
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 3
|
33
|
+
- 1
|
34
|
+
version: 0.3.1
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: A hack to RDF.rb to override its autoloading feature to allow it to work in JRuby threads.
|
38
|
+
email: rossfsinger@gmail.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
files:
|
46
|
+
- README
|
47
|
+
- VERSION
|
48
|
+
- lib/rdf/threadsafe/module.rb
|
49
|
+
- lib/rdf/threadsafe/util/cache.rb
|
50
|
+
- lib/rdf/threadsafe.rb
|
51
|
+
has_rdoc: false
|
52
|
+
homepage: http://github.com/rsinger/rdf-threadsafe
|
53
|
+
licenses:
|
54
|
+
- Public Domain
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 53
|
66
|
+
segments:
|
67
|
+
- 1
|
68
|
+
- 8
|
69
|
+
- 1
|
70
|
+
version: 1.8.1
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
requirements: []
|
81
|
+
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.3.7
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: A hack to RDF.rb to override its autoloading feature to allow it to work in JRuby threads.
|
87
|
+
test_files: []
|
88
|
+
|