ji2p 0.0.3-jruby-java-universal-java-9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/bundle +15 -0
- data/bin/ctxirb +119 -0
- data/bin/simple_http_server +20 -0
- data/bin/simple_outproxy +96 -0
- data/lib/actor_system/actor.rb +10 -0
- data/lib/actor_system/concurrent/processor.rb +21 -0
- data/lib/actor_system/concurrent/worker.rb +13 -0
- data/lib/actor_system/core/minimal.rb +84 -0
- data/lib/actor_system/core/observable_implementation.rb +58 -0
- data/lib/actor_system/core/props.rb +45 -0
- data/lib/actor_system/dispatcher.rb +12 -0
- data/lib/actor_system/mailbox.rb +7 -0
- data/lib/actor_system/message.rb +60 -0
- data/lib/core_ext.rb +41 -0
- data/lib/gen_server.rb +57 -0
- data/lib/ji2p.rb +37 -0
- data/lib/ji2p/bundler.rb +165 -0
- data/lib/ji2p/cluster.rb +6 -0
- data/lib/ji2p/cluster/etcd.rb +5 -0
- data/lib/ji2p/cluster/etcd/version3.rb +6 -0
- data/lib/ji2p/cluster/kubernetes.rb +5 -0
- data/lib/ji2p/cluster/kubernetes/kube_api.rb +6 -0
- data/lib/ji2p/concurrent.rb +24 -0
- data/lib/ji2p/concurrent_executor.rb +56 -0
- data/lib/ji2p/config.rb +15 -0
- data/lib/ji2p/control.rb +15 -0
- data/lib/ji2p/control/client_manager.rb +14 -0
- data/lib/ji2p/control/dest.rb +34 -0
- data/lib/ji2p/control/keypair.rb +176 -0
- data/lib/ji2p/control/server.rb +80 -0
- data/lib/ji2p/control/socket_manager.rb +77 -0
- data/lib/ji2p/control/tunnel_manager.rb +62 -0
- data/lib/ji2p/environment.rb +35 -0
- data/lib/ji2p/package/gem_installer.rb +91 -0
- data/lib/ji2p/package/gemfile.rb +234 -0
- data/lib/ji2p/package/jar_dependencies.rb +23 -0
- data/lib/ji2p/package/proxy_support.rb +50 -0
- data/lib/ji2p/rspec.rb +16 -0
- data/lib/ji2p/server.rb +10 -0
- data/lib/ji2p/server/api.rb +14 -0
- data/lib/ji2p/server/database.rb +66 -0
- data/lib/ji2p/server/http.rb +69 -0
- data/lib/ji2p/server/http_server.rb +37 -0
- data/lib/ji2p/server/initializer.rb +4 -0
- data/lib/ji2p/server/launcher.rb +40 -0
- data/lib/ji2p/server/models.rb +9 -0
- data/lib/ji2p/server/models/base_record.rb +7 -0
- data/lib/ji2p/server/models/keypair.rb +32 -0
- data/lib/ji2p/server/models/tunnel.rb +4 -0
- data/lib/ji2p/startup.rb +12 -0
- data/lib/ji2p/startup/bootstrap.rb +60 -0
- data/lib/ji2p/startup/client_application.rb +20 -0
- data/lib/ji2p/startup/router_manager.rb +21 -0
- data/lib/ji2p/startup/sinatra_app.rb +61 -0
- data/lib/ji2p/startup/worker.rb +63 -0
- data/lib/ji2p/utils/blocking_queue.rb +32 -0
- data/lib/ji2p/utils/byte_value.rb +61 -0
- data/lib/ji2p/version.rb +3 -0
- data/lib/ji2p_jars.rb +16 -0
- data/lib/maybe.rb +148 -0
- data/lib/net/i2p/client/mstreaming/0.9.43/mstreaming-0.9.43.jar +0 -0
- data/lib/net/i2p/client/streaming/0.9.43/streaming-0.9.43.jar +0 -0
- data/lib/net/i2p/i2p/0.9.43/i2p-0.9.43.jar +0 -0
- data/lib/net/i2p/router/0.9.43/router-0.9.43.jar +0 -0
- metadata +392 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
require_relative 'observable_implementation.rb'
|
2
|
+
|
3
|
+
module ActorSystem
|
4
|
+
module Core
|
5
|
+
class Prop
|
6
|
+
include ObservableImplementation
|
7
|
+
|
8
|
+
def initialize name, value
|
9
|
+
@name = name
|
10
|
+
@value = value
|
11
|
+
end
|
12
|
+
|
13
|
+
def value= value
|
14
|
+
@value = value
|
15
|
+
notify_observers(value)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
class BasicObserverHash
|
19
|
+
def initialize values={}
|
20
|
+
@internal_hash = values
|
21
|
+
end
|
22
|
+
|
23
|
+
def [](key)
|
24
|
+
@internal_hash[key]
|
25
|
+
end
|
26
|
+
|
27
|
+
def []=(key, value)
|
28
|
+
if @internal_hash[key].nil?
|
29
|
+
p = Prop.new key,value
|
30
|
+
p.add_observer self
|
31
|
+
@internal_hash[key] = p
|
32
|
+
else
|
33
|
+
@internal_hash[key].value = value
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def observer_update value
|
38
|
+
puts "Received update = #{value}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Props < BasicObserverHash
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module ActorSystem
|
2
|
+
module Message
|
3
|
+
def self.included cls
|
4
|
+
cls.class_exec do
|
5
|
+
extend Matcher
|
6
|
+
|
7
|
+
include MessageName
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.extended receiver
|
12
|
+
receiver.instance_exec do
|
13
|
+
extend Matcher
|
14
|
+
extend MessageName
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.=== object
|
19
|
+
if object.is_a? Symbol
|
20
|
+
true
|
21
|
+
else
|
22
|
+
super
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module Matcher
|
27
|
+
def === other
|
28
|
+
other_message_name = Name.get other
|
29
|
+
|
30
|
+
message_name == other_message_name
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module MessageName
|
35
|
+
def self.included cls
|
36
|
+
cls.class_exec do
|
37
|
+
extend ClassMethod
|
38
|
+
|
39
|
+
include InstanceMethod
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.extended receiver
|
44
|
+
receiver.extend ClassMethod
|
45
|
+
end
|
46
|
+
|
47
|
+
module InstanceMethod
|
48
|
+
def message_name
|
49
|
+
self.class.message_name
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
module ClassMethod
|
54
|
+
def message_name
|
55
|
+
Name.get name
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/core_ext.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
class Hash
|
3
|
+
def to_properties
|
4
|
+
# Java::JavaUtil::Properties
|
5
|
+
props = java_import('java.util.Properties').first.new
|
6
|
+
self.each do |k,v|
|
7
|
+
props[k.to_s] = v.to_s
|
8
|
+
end
|
9
|
+
props
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.from_properties props,convert_symbols=false
|
13
|
+
return unless props.is_a? java_import('java.util.Properties').first
|
14
|
+
hash = new
|
15
|
+
props.each do |k,v|
|
16
|
+
k = k.to_sym if convert_symbols
|
17
|
+
hash[k] = v
|
18
|
+
end
|
19
|
+
hash
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Object
|
24
|
+
def try(*a, &b)
|
25
|
+
if a.empty? && block_given?
|
26
|
+
yield self
|
27
|
+
else
|
28
|
+
public_send(*a, &b) if respond_to?(a.first)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class NilClass
|
34
|
+
def try(*args)
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def method_missing(method, *args)
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
end
|
data/lib/gen_server.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require "ostruct"
|
2
|
+
require "securerandom"
|
3
|
+
|
4
|
+
module GenServer
|
5
|
+
class << self
|
6
|
+
def call(pid, method, *args)
|
7
|
+
entry = fetch_entry(pid)
|
8
|
+
value, state = entry.module.send(method, entry.state, *args)
|
9
|
+
entry.state = state
|
10
|
+
update_entry(pid, entry)
|
11
|
+
value
|
12
|
+
end
|
13
|
+
|
14
|
+
def cast(pid, method, *args)
|
15
|
+
entry = fetch_entry(pid)
|
16
|
+
entry.state = entry.module.send(method, entry.state, *args)
|
17
|
+
update_entry(pid, entry)
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def start_link(mod, *args)
|
22
|
+
state = mod.init(*args)
|
23
|
+
add_entry(mod, state)
|
24
|
+
end
|
25
|
+
|
26
|
+
def terminate(pid)
|
27
|
+
remove_entry(pid)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def add_entry(mod, state)
|
33
|
+
SecureRandom.uuid.tap do |uuid|
|
34
|
+
entries[uuid] = OpenStruct.new(
|
35
|
+
:module => mod,
|
36
|
+
:state => state
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def entries
|
42
|
+
@entries ||= {}
|
43
|
+
end
|
44
|
+
|
45
|
+
def fetch_entry(pid)
|
46
|
+
entries[pid]
|
47
|
+
end
|
48
|
+
|
49
|
+
def remove_entry(pid)
|
50
|
+
entries.delete(pid)
|
51
|
+
end
|
52
|
+
|
53
|
+
def update_entry(pid, entry)
|
54
|
+
entries[pid] = entry
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/ji2p.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#require 'active_support'
|
2
|
+
#require 'active_support/core_ext'
|
3
|
+
#require 'active_support/dependencies'
|
4
|
+
require 'logger'
|
5
|
+
require 'java'
|
6
|
+
$CLASSPATH << "file:///#{File.expand_path(File.join(__dir__, '..', 'config'))}/"
|
7
|
+
|
8
|
+
require 'ji2p/environment.rb'
|
9
|
+
|
10
|
+
module Ji2p
|
11
|
+
require_relative 'ji2p/version.rb'
|
12
|
+
autoload :Cluster, File.expand_path('ji2p/cluster.rb', __dir__)
|
13
|
+
autoload :Control, File.expand_path('ji2p/control.rb', __dir__)
|
14
|
+
autoload :Server, File.expand_path('ji2p/server.rb', __dir__)
|
15
|
+
autoload :Startup, File.expand_path('ji2p/startup.rb', __dir__)
|
16
|
+
#ActiveSupport::Dependencies.autoload_paths << __dir__
|
17
|
+
#Dir.glob('**/').each do |dir|
|
18
|
+
# ActiveSupport::Dependencies.autoload_paths << File.expand_path(dir, __dir__)
|
19
|
+
#end
|
20
|
+
|
21
|
+
# https://github.com/jruby/jruby/wiki/RedBridge
|
22
|
+
java_import 'java.lang.System'
|
23
|
+
System.setProperty("org.jruby.embed.localcontext.scope", "singleton") # concurrent, threadsafe, etc.
|
24
|
+
|
25
|
+
def self.logger
|
26
|
+
@logger ||= Logger.new(STDOUT)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.disable_crypto_restriction
|
30
|
+
# java.lang.Class.for_name('javax.crypto.JceSecurity').get_declared_field('isRestricted').tap{|f| f.accessible = true; f.set nil, false}
|
31
|
+
security_class = java.lang.Class.for_name('javax.crypto.JceSecurity')
|
32
|
+
restricted_field = security_class.get_declared_field('isRestricted')
|
33
|
+
restricted_field.accessible = true
|
34
|
+
restricted_field.set nil, false
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/lib/ji2p/bundler.rb
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Ji2p
|
4
|
+
module Bundler
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def setup!(options = {})
|
8
|
+
options = {:without => [:development]}.merge(options)
|
9
|
+
options[:without] = Array(options[:without])
|
10
|
+
|
11
|
+
::Gem.clear_paths
|
12
|
+
ENV['GEM_HOME'] = ENV['GEM_PATH'] = Environment.ji2p_gem_home
|
13
|
+
::Gem.paths = ENV
|
14
|
+
|
15
|
+
# set BUNDLE_GEMFILE ENV before requiring bundler to avoid bundler recurse and load unrelated Gemfile(s)
|
16
|
+
ENV["BUNDLE_GEMFILE"] = Environment::GEMFILE_PATH
|
17
|
+
|
18
|
+
require 'bundler'
|
19
|
+
|
20
|
+
::Bundler.settings.set_local(:path, Environment::BUNDLE_DIR)
|
21
|
+
::Bundler.settings.set_local(:without, options[:without])
|
22
|
+
# in the context of Bundler.setup it looks like this is useless here because Gemfile path can only be specified using
|
23
|
+
# the ENV, see https://github.com/bundler/bundler/blob/v1.8.3/lib/bundler/shared_helpers.rb#L103
|
24
|
+
::Bundler.settings.set_local(:gemfile, Environment::GEMFILE_PATH)
|
25
|
+
|
26
|
+
::Bundler.reset!
|
27
|
+
::Bundler.setup
|
28
|
+
end
|
29
|
+
|
30
|
+
# execute bundle install and capture any $stdout output. any raised exception in the process will be trapped
|
31
|
+
# and returned. logs errors to $stdout.
|
32
|
+
# @param [Hash] options invoke options with default values, :max_tries => 10, :clean => false, :install => false, :update => false
|
33
|
+
# @option options [Boolean] :max_tries The number of times bundler is going to try the installation before failing (default: 10)
|
34
|
+
# @option options [Boolean] :clean It cleans the unused gems (default: false)
|
35
|
+
# @option options [Boolean] :install Run the installation of a set of gems defined in a Gemfile (default: false)
|
36
|
+
# @option options [Boolean, String, Array] :update Update the current environment, must be either false or a String or an Array of String (default: false)
|
37
|
+
# @option options [Boolean] :local Do not attempt to fetch gems remotely and use the gem cache instead (default: false)
|
38
|
+
# @option options [Boolean] :package Locks and then caches all dependencies to be reused later on (default: false)
|
39
|
+
# @option options [Boolean] :all It packages dependencies defined with :git or :path (default: false)
|
40
|
+
# @option options [Array] :without Exclude gems that are part of the specified named group (default: [:development])
|
41
|
+
# @return [String, Exception] the installation captured output and any raised exception or nil if none
|
42
|
+
def invoke!(options = {})
|
43
|
+
options = {:max_tries => 10, :clean => false, :install => false, :update => false, :local => false,
|
44
|
+
:jobs => 12, :all => false, :package => false, :without => [:development]}.merge(options)
|
45
|
+
options[:without] = Array(options[:without])
|
46
|
+
options[:update] = Array(options[:update]) if options[:update]
|
47
|
+
|
48
|
+
::Gem.clear_paths
|
49
|
+
ENV['GEM_HOME'] = ENV['GEM_PATH'] = Ji2p::Environment.ji2p_gem_home
|
50
|
+
::Gem.paths = ENV
|
51
|
+
# set BUNDLE_GEMFILE ENV before requiring bundler to avoid bundler recurse and load unrelated Gemfile(s).
|
52
|
+
# in the context of calling Bundler::CLI this is not really required since Bundler::CLI will look at
|
53
|
+
# Bundler.settings[:gemfile] unlike Bundler.setup. For the sake of consistency and defensive/future proofing, let's keep it here.
|
54
|
+
ENV["BUNDLE_GEMFILE"] = Ji2p::Environment::GEMFILE_PATH
|
55
|
+
|
56
|
+
require 'bundler'
|
57
|
+
require 'bundler/cli'
|
58
|
+
|
59
|
+
# force Rubygems sources to our Gemfile sources
|
60
|
+
::Gem.sources = ::Gem::SourceList.from(options[:rubygems_source]) if options[:rubygems_source]
|
61
|
+
|
62
|
+
::Bundler.settings.set_local(:path, Ji2p::Environment::BUNDLE_DIR)
|
63
|
+
::Bundler.settings.set_local(:gemfile, Ji2p::Environment::GEMFILE_PATH)
|
64
|
+
::Bundler.settings.set_local(:without, options[:without])
|
65
|
+
::Bundler.settings.set_local(:force, options[:force])
|
66
|
+
|
67
|
+
if !debug?
|
68
|
+
# Will deal with transient network errors
|
69
|
+
execute_bundler_with_retry(options)
|
70
|
+
else
|
71
|
+
options[:verbose] = true
|
72
|
+
execute_bundler(options)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def execute_bundler_with_retry(options)
|
77
|
+
try = 0
|
78
|
+
# capture_stdout also traps any raised exception and pass them back as the function return [output, exception]
|
79
|
+
output, exception = capture_stdout do
|
80
|
+
loop do
|
81
|
+
begin
|
82
|
+
execute_bundler(options)
|
83
|
+
break
|
84
|
+
rescue ::Bundler::VersionConflict => e
|
85
|
+
$stderr.puts("Plugin version conflict, aborting")
|
86
|
+
raise(e)
|
87
|
+
rescue ::Bundler::GemNotFound => e
|
88
|
+
$stderr.puts("Plugin not found, aborting")
|
89
|
+
raise(e)
|
90
|
+
rescue => e
|
91
|
+
if try >= options[:max_tries]
|
92
|
+
$stderr.puts("Too many retries, aborting, caused by #{e.class}")
|
93
|
+
$stderr.puts(e.message) if ENV["DEBUG"]
|
94
|
+
raise(e)
|
95
|
+
end
|
96
|
+
|
97
|
+
try += 1
|
98
|
+
$stderr.puts("Error #{e.class}, retrying #{try}/#{options[:max_tries]}")
|
99
|
+
$stderr.puts(e.message)
|
100
|
+
sleep(0.5)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
raise exception if exception
|
105
|
+
|
106
|
+
return output
|
107
|
+
end
|
108
|
+
|
109
|
+
def execute_bundler(options)
|
110
|
+
::Bundler.reset!
|
111
|
+
::Bundler::CLI.start(bundler_arguments(options))
|
112
|
+
end
|
113
|
+
|
114
|
+
def debug?
|
115
|
+
ENV["DEBUG"]
|
116
|
+
end
|
117
|
+
|
118
|
+
# build Bundler::CLI.start arguments array from the given options hash
|
119
|
+
# @param option [Hash] the invoke! options hash
|
120
|
+
# @return [Array<String>] Bundler::CLI.start string arguments array
|
121
|
+
def bundler_arguments(options = {})
|
122
|
+
arguments = []
|
123
|
+
|
124
|
+
if options[:install]
|
125
|
+
arguments << "install"
|
126
|
+
arguments << "--clean" if options[:clean]
|
127
|
+
if options[:local]
|
128
|
+
arguments << "--local"
|
129
|
+
arguments << "--no-prune" # From bundler docs: Don't remove stale gems from the cache.
|
130
|
+
end
|
131
|
+
elsif options[:update]
|
132
|
+
arguments << "update"
|
133
|
+
arguments << options[:update]
|
134
|
+
arguments << "--local" if options[:local]
|
135
|
+
elsif options[:clean]
|
136
|
+
arguments << "clean"
|
137
|
+
elsif options[:package]
|
138
|
+
arguments << "package"
|
139
|
+
arguments << "--all" if options[:all]
|
140
|
+
end
|
141
|
+
|
142
|
+
arguments << "--verbose" if options[:verbose]
|
143
|
+
|
144
|
+
arguments.flatten
|
145
|
+
end
|
146
|
+
|
147
|
+
# capture any $stdout from the passed block. also trap any exception in that block, in which case the trapped exception will be returned
|
148
|
+
# @param [Proc] the code block to execute
|
149
|
+
# @return [String, Exception] the captured $stdout string and any trapped exception or nil if none
|
150
|
+
def capture_stdout(&block)
|
151
|
+
old_stdout = $stdout
|
152
|
+
$stdout = StringIO.new("", "w")
|
153
|
+
begin
|
154
|
+
block.call
|
155
|
+
rescue => e
|
156
|
+
return [$stdout.string, e]
|
157
|
+
end
|
158
|
+
|
159
|
+
[$stdout.string, nil]
|
160
|
+
ensure
|
161
|
+
$stdout = old_stdout
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
end
|
data/lib/ji2p/cluster.rb
ADDED