tibems 0.0.2-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dd6d3099d869e484d150441df309c585b7dcd6e8
4
+ data.tar.gz: b5fd1c0569158c8b4ae0ddb5671d56b2c4cdc61d
5
+ SHA512:
6
+ metadata.gz: 88c224d9aa6a18ebdd37e569014fa46e67440f09f44af04cc9d5938dc24fb400e082ddeac9d4a987487bbd268113b8730b1ebf3b41485647da4a228ad8c2c4d6
7
+ data.tar.gz: 4f37ea6a8b4c740b4d77c2087872dd1749fadfd1388dc7a656fcaeaf6bf5181ee4666d914652cc50b79ab9865852e967425acc641726ff6e7e82cf3d42c2fdcb
@@ -0,0 +1,179 @@
1
+ package org.jalonsoa.tibems;
2
+
3
+ import java.lang.Long;
4
+ import java.io.IOException;
5
+
6
+ import org.jruby.Ruby;
7
+ import org.jruby.RubyArray;
8
+ import org.jruby.RubyClass;
9
+ import org.jruby.RubyFixnum;
10
+ import org.jruby.RubyHash;
11
+ import org.jruby.RubyModule;
12
+ import org.jruby.RubyObject;
13
+ import org.jruby.RubyString;
14
+ import org.jruby.anno.JRubyClass;
15
+ import org.jruby.anno.JRubyMethod;
16
+ import org.jruby.runtime.ObjectAllocator;
17
+ import org.jruby.runtime.ThreadContext;
18
+ import org.jruby.runtime.builtin.IRubyObject;
19
+ import org.jruby.runtime.load.BasicLibraryService;
20
+
21
+ import com.tibco.tibjms.admin.ConsumerInfo;
22
+ import com.tibco.tibjms.admin.DestinationInfo;
23
+ import com.tibco.tibjms.admin.QueueInfo;
24
+ import com.tibco.tibjms.admin.TopicInfo;
25
+ import com.tibco.tibjms.admin.ServerInfo;
26
+ import com.tibco.tibjms.admin.StatData;
27
+ import com.tibco.tibjms.admin.TibjmsAdmin;
28
+ import com.tibco.tibjms.admin.TibjmsAdminException;
29
+
30
+ import java.util.Collection;
31
+ import java.util.logging.Level;
32
+ import java.util.logging.Logger;
33
+
34
+ // The Java class that backs the Ruby class Faye::WebSocketMask. Its methods
35
+ // annotated with @JRubyMethod become exposed as instance methods on the Ruby
36
+ // class through the call to defineAnnotatedMethods() above.
37
+ @JRubyClass(name="TibEMS::Admin")
38
+ public class Admin extends RubyObject {
39
+ public static final int DESTINATION_TYPE_TOPIC = 0;
40
+ public static final int DESTINATION_TYPE_QUEUE = 1;
41
+
42
+ protected static TibjmsAdmin admin = null;
43
+
44
+ private static IRubyObject Qnil;
45
+
46
+ public Admin(final Ruby runtime, RubyClass rubyClass) {
47
+ super(runtime, rubyClass);
48
+
49
+ Qnil = runtime.getNil();
50
+ }
51
+
52
+ @JRubyMethod(name = "create")
53
+ protected static IRubyObject create(ThreadContext context, IRubyObject self, RubyString url, RubyString user, RubyString pass) {
54
+ try {
55
+ admin = new TibjmsAdmin(url.asJavaString(),user.asJavaString(),pass.asJavaString());
56
+ } catch (TibjmsAdminException exp) {
57
+ }
58
+
59
+ return self;
60
+ }
61
+
62
+ @JRubyMethod(name = "close")
63
+ public IRubyObject close(ThreadContext context) {
64
+ try {
65
+ admin.close();
66
+ admin = null;
67
+ } catch (TibjmsAdminException exp) {
68
+ }
69
+ return Qnil;
70
+ }
71
+
72
+ private RubyArray destinationsHash( Ruby runtime, DestinationInfo[] destInfos, int type ) {
73
+ RubyArray info = RubyArray.newArray( runtime, destInfos.length );
74
+
75
+ for (DestinationInfo destInfo : destInfos) {
76
+ RubyHash dest = RubyHash.newHash( runtime );
77
+ RubyHash inbound = RubyHash.newHash( runtime );
78
+ RubyHash outbound = RubyHash.newHash( runtime );
79
+
80
+ dest.put("name",destInfo.getName());
81
+ dest.put("consumerCount", destInfo.getConsumerCount());
82
+ dest.put("flowControlMaxBytes", destInfo.getFlowControlMaxBytes());
83
+ dest.put("pendingMessageCount", destInfo.getPendingMessageCount());
84
+ dest.put("pendingMessageSize", destInfo.getPendingMessageSize());
85
+
86
+ if (type == DESTINATION_TYPE_TOPIC) {
87
+ TopicInfo topicInfo = (TopicInfo)destInfo;
88
+ dest.put("subscriberCount", topicInfo.getSubscriberCount());
89
+ dest.put("durableCount", topicInfo.getDurableCount());
90
+ dest.put("activeDurableCount", topicInfo.getActiveDurableCount());
91
+ } else {
92
+ QueueInfo queueInfo = (QueueInfo)destInfo;
93
+ dest.put("receiverCount", queueInfo.getReceiverCount());
94
+ dest.put("deliveredMessageCount", queueInfo.getDeliveredMessageCount());
95
+ dest.put("inTransitMessageCount", queueInfo.getInTransitMessageCount());
96
+ dest.put("maxRedelivery", queueInfo.getMaxRedelivery());
97
+ }
98
+
99
+ StatData inboundStats = destInfo.getInboundStatistics();
100
+ inbound.put("totalMessages", inboundStats.getTotalMessages());
101
+ inbound.put("messageRate", inboundStats.getMessageRate());
102
+ inbound.put("totalBytes", inboundStats.getTotalBytes());
103
+ inbound.put("byteRate", inboundStats.getByteRate());
104
+
105
+ dest.put("inbound", inbound);
106
+
107
+ StatData outboundStats = destInfo.getInboundStatistics();
108
+ outbound.put("totalMessages", outboundStats.getTotalMessages());
109
+ outbound.put("messageRate", outboundStats.getMessageRate());
110
+ outbound.put("totalBytes", outboundStats.getTotalBytes());
111
+ outbound.put("byteRate", outboundStats.getByteRate());
112
+
113
+ dest.put("outbound", outbound);
114
+
115
+ info.add(dest);
116
+ }
117
+
118
+ return info;
119
+ }
120
+
121
+ @JRubyMethod(name = "get_info")
122
+ public IRubyObject get_info(ThreadContext context) {
123
+ Ruby runtime = context.runtime;
124
+ RubyHash info = RubyHash.newHash( runtime );
125
+
126
+ try {
127
+ ServerInfo serverInfo = admin.getInfo();
128
+
129
+ info.put("diskReadRate", serverInfo.getDiskReadRate());
130
+ info.put("diskWriteRate", serverInfo.getDiskWriteRate());
131
+ info.put("syncDBSize", serverInfo.getSyncDBSize());
132
+ info.put("asyncDBSize", serverInfo.getAsyncDBSize());
133
+ info.put("msgMem", serverInfo.getMsgMem());
134
+ info.put("msgMemPooled", serverInfo.getMsgMemPooled());
135
+ info.put("maxMsgMemory", serverInfo.getMaxMsgMemory());
136
+ info.put("msgMem", serverInfo.getMsgMem());
137
+ info.put("connectionCount", serverInfo.getConnectionCount());
138
+ info.put("maxConnections", serverInfo.getMaxConnections());
139
+ info.put("sessionCount", serverInfo.getSessionCount());
140
+ info.put("producerCount", serverInfo.getProducerCount());
141
+ info.put("consumerCount", serverInfo.getConsumerCount());
142
+ info.put("durableCount", serverInfo.getDurableCount());
143
+ info.put("topicCount", serverInfo.getTopicCount());
144
+ info.put("queueCount", serverInfo.getQueueCount());
145
+ info.put("pendingMessageCount", serverInfo.getPendingMessageCount());
146
+ info.put("pendingMessageSize", serverInfo.getPendingMessageSize());
147
+ info.put("inboundMessageCount", serverInfo.getInboundMessageCount());
148
+ info.put("inboundMessageRate", serverInfo.getInboundMessageRate());
149
+ info.put("inboundBytesRate", serverInfo.getInboundBytesRate());
150
+ info.put("outboundMessageCount", serverInfo.getOutboundMessageCount());
151
+ info.put("outboundMessageRate", serverInfo.getOutboundMessageRate());
152
+ info.put("outboundBytesRate", serverInfo.getOutboundBytesRate());
153
+ info.put("logFileMaxSize", serverInfo.getLogFileMaxSize());
154
+ info.put("logFileSize", serverInfo.getLogFileSize());
155
+
156
+ // TODO: pass pattern
157
+ QueueInfo[] queueInfos = admin.getQueuesStatistics();
158
+
159
+ if (queueInfos.length > 0) {
160
+ RubyArray queues = destinationsHash( runtime, queueInfos, DESTINATION_TYPE_QUEUE );
161
+
162
+ info.put("queues", queues);
163
+ }
164
+
165
+ // TODO: pass pattern
166
+ TopicInfo[] topicInfos = admin.getTopicsStatistics();
167
+
168
+ if (topicInfos.length > 0) {
169
+ RubyArray topics = destinationsHash( runtime, topicInfos, DESTINATION_TYPE_TOPIC );
170
+
171
+ info.put("topics", topics);
172
+ }
173
+
174
+ } catch (TibjmsAdminException exp) {
175
+ }
176
+
177
+ return info;
178
+ }
179
+ }
@@ -0,0 +1,43 @@
1
+ package org.jalonsoa.tibems;
2
+
3
+ import java.lang.Long;
4
+ import java.io.IOException;
5
+
6
+ import org.jruby.Ruby;
7
+ import org.jruby.RubyArray;
8
+ import org.jruby.RubyClass;
9
+ import org.jruby.RubyFixnum;
10
+ import org.jruby.RubyModule;
11
+ import org.jruby.RubyObject;
12
+ import org.jruby.anno.JRubyMethod;
13
+ import org.jruby.runtime.ObjectAllocator;
14
+ import org.jruby.runtime.ThreadContext;
15
+ import org.jruby.runtime.builtin.IRubyObject;
16
+ import org.jruby.runtime.load.BasicLibraryService;
17
+
18
+ import org.jalonsoa.tibems.Admin;
19
+
20
+ public class TibEMSService implements BasicLibraryService {
21
+ private Ruby runtime;
22
+
23
+ // Initial setup function. Takes a reference to the current JRuby runtime and
24
+ // sets up our modules. For JRuby, we will define mask() as an instance method
25
+ // on a specially created class, Faye::WebSocketMask.
26
+ public boolean basicLoad(Ruby runtime) throws IOException {
27
+ this.runtime = runtime;
28
+ RubyModule tibems = runtime.defineModule("TibEMS");
29
+
30
+ // Create the WebSocketMask class. defineClassUnder() takes a name, a
31
+ // reference to the superclass -- runtime.getObject() gets you the Object
32
+ // class for the current runtime -- and an allocator function that says
33
+ // which Java object to constuct when you call new() on the class.
34
+ RubyClass admin = tibems.defineClassUnder("Admin", runtime.getObject(), new ObjectAllocator() {
35
+ public IRubyObject allocate(Ruby runtime, RubyClass rubyClass) {
36
+ return new Admin(runtime, rubyClass);
37
+ }
38
+ });
39
+
40
+ admin.defineAnnotatedMethods(Admin.class);
41
+ return true;
42
+ }
43
+ }
@@ -0,0 +1,64 @@
1
+ # encoding: UTF-8
2
+ require 'mkmf'
3
+ require 'English'
4
+
5
+ # 2.0-only
6
+ have_header('ruby/thread.h') && have_func('rb_thread_call_without_gvl', 'ruby/thread.h')
7
+
8
+ # 1.9-only
9
+ have_func('rb_thread_blocking_region')
10
+ have_func('rb_hash_dup')
11
+ have_func('rb_intern3')
12
+
13
+ # If the user has provided a --with-tibems-dir argument, we must respect it or fail.
14
+ inc, lib = dir_config('tibems')
15
+ if inc && lib
16
+ # TODO: Remove when 2.0.0 is the minimum supported version
17
+ # Ruby versions not incorporating the mkmf fix at
18
+ # https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/39717
19
+ # do not properly search for lib directories, and must be corrected
20
+ unless lib && lib[-3, 3] == 'lib'
21
+ @libdir_basename = 'lib'
22
+ inc, lib = dir_config('tibems')
23
+ end
24
+
25
+ if RUBY_PLATFORM =~ /x86_64/
26
+ # Add dir with /64 in libraries
27
+ libs64 = lib.split(File::PATH_SEPARATOR).map! { |l| "#{l}/64" }
28
+ lib = libs64.join(File::PATH_SEPARATOR) + File::PATH_SEPARATOR + lib
29
+ end
30
+
31
+ abort "-----\nCannot find include dir(s) #{inc}\n-----" unless inc && inc.split(File::PATH_SEPARATOR).any? { |dir| File.directory?(dir) }
32
+ abort "-----\nCannot find library dir(s) #{lib}\n-----" unless lib && lib.split(File::PATH_SEPARATOR).any? { |dir| File.directory?(dir) }
33
+ warn "-----\nUsing --with-tibems-dir=#{File.dirname inc}\n-----"
34
+ rpath_dir = lib
35
+ end
36
+
37
+ if have_header('tibems.h')
38
+ prefix = nil
39
+ elsif have_header('tibems/tibems.h')
40
+ prefix = 'tibems'
41
+ else
42
+ asplode 'tibems.h'
43
+ end
44
+
45
+ %w(emsadmin.h emserr.h admtypes.h qinfo.h status.h).each do |h|
46
+ header = [prefix, h].compact.join '/'
47
+ asplode h unless have_header header
48
+ end
49
+
50
+ if RUBY_PLATFORM =~ /x86_64/
51
+ have_library("tibems64");
52
+ have_library("tibemslookup64");
53
+ have_library("tibemsufo64");
54
+ have_library("tibemsadmin64");
55
+ else
56
+ have_library("tibems");
57
+ have_library("tibemslookup");
58
+ have_library("tibemsufo");
59
+ have_library("tibemsadmin");
60
+ end
61
+
62
+ have_library("ssl");
63
+
64
+ create_makefile('tibems')
data/lib/tibems.rb ADDED
@@ -0,0 +1,55 @@
1
+ # encoding: UTF-8
2
+ require 'date'
3
+ require 'bigdecimal'
4
+
5
+ require 'tibems/version' unless defined? TibEMS::VERSION
6
+ require 'tibems/error'
7
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
8
+ require 'jruby'
9
+ begin
10
+ require 'tibems_jars'
11
+ rescue LoadError
12
+ end
13
+ require 'tibems/tibems.jar'
14
+ org.jalonsoa.tibems.TibEMSService.new.basicLoad(JRuby.runtime)
15
+ else
16
+ require 'tibems/tibems'
17
+ end
18
+ require 'tibems/admin'
19
+
20
+
21
+ # = TibEMS
22
+ #
23
+ # A modern, simple binding to TibEMS libraries
24
+ module TibEMS
25
+ end
26
+
27
+ # For holding utility methods
28
+ module TibEMS
29
+ module Util
30
+ #
31
+ # Rekey a string-keyed hash with equivalent symbols.
32
+ #
33
+ def self.key_hash_as_symbols(hash)
34
+ return nil unless hash
35
+ Hash[hash.map { |k, v| [k.to_sym, v] }]
36
+ end
37
+
38
+ #
39
+ # Thread#handle_interrupt is used to prevent Timeout#timeout
40
+ # from interrupting query execution.
41
+ #
42
+ # Timeout::ExitException was removed in Ruby 2.3.0, 2.2.3, and 2.1.8,
43
+ # but is present in earlier 2.1.x and 2.2.x, so we provide a shim.
44
+ #
45
+ if Thread.respond_to?(:handle_interrupt)
46
+ require 'timeout'
47
+ # rubocop:disable Style/ConstantName
48
+ TimeoutError = if defined?(::Timeout::ExitException)
49
+ ::Timeout::ExitException
50
+ else
51
+ ::Timeout::Error
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,25 @@
1
+ module TibEMS
2
+ class Admin
3
+ def initialize(opts = {})
4
+ opts = TibEMS::Util.key_hash_as_symbols(opts)
5
+
6
+ if RUBY_PLATFORM !~ /java/
7
+ initialize_ext
8
+ end
9
+
10
+ ##ssl_options = opts.values_at(:sslkey, :sslcert, :sslca, :sslcapath, :sslcipher)
11
+ ##ssl_set(*ssl_options) if ssl_options.any?
12
+
13
+ url = opts[:url] || opts[:host]
14
+ user = opts[:username] || opts[:user]
15
+ pass = opts[:password] || opts[:pass]
16
+
17
+ # Correct the data types before passing these values down to the C level
18
+ url = url.to_s unless url.nil?
19
+ user = user.to_s unless user.nil?
20
+ pass = pass.to_s unless pass.nil?
21
+
22
+ create url, user, pass
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: UTF-8
2
+
3
+ module TibEMS
4
+ class Error < StandardError
5
+ ENCODE_OPTS = {
6
+ :undef => :replace,
7
+ :invalid => :replace,
8
+ :replace => '?'.freeze,
9
+ }.freeze
10
+
11
+ attr_reader :error_number, :error_message
12
+
13
+ def initialize(msg)
14
+ @server_version ||= nil
15
+
16
+ super(clean_message(msg))
17
+ end
18
+
19
+ def self.new_with_args(msg, server_version, error_number, error_message)
20
+ err = allocate
21
+ err.instance_variable_set('@server_version', server_version)
22
+ err.instance_variable_set('@error_number', error_number)
23
+ err.instance_variable_set('@error_state', error_message.respond_to?(:encode) ? error_message.encode(ENCODE_OPTS) : error_message)
24
+ err.send(:initialize, msg)
25
+ err
26
+ end
27
+
28
+ private
29
+
30
+ def clean_message(message)
31
+ return message unless message.respond_to?(:encode)
32
+
33
+ message.encode(ENCODE_OPTS)
34
+ ##message.encode(Encoding::UTF_8, ENCODE_OPTS)
35
+ end
36
+ end
37
+ end
Binary file
@@ -0,0 +1,3 @@
1
+ module TibEMS
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tibems
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: java
6
+ authors:
7
+ - Justo Alonso
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ name: jar-dependencies
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ name: rake-compiler
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: TibEMS bindings for Ruby
42
+ email:
43
+ - justo.alonso@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ext/tibems/Admin.java
49
+ - ext/tibems/TibEMSService.java
50
+ - ext/tibems/extconf.rb
51
+ - lib/tibems.rb
52
+ - lib/tibems/admin.rb
53
+ - lib/tibems/error.rb
54
+ - lib/tibems/tibems.jar
55
+ - lib/tibems/version.rb
56
+ homepage: https://github.com/jalonsoa/ruby-tibems
57
+ licenses:
58
+ - Apache-2.0
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements:
75
+ - jar 'javax.jms:javax.jms-api', '2.0'
76
+ - jar 'com.tibco:tibjms', '>= 7.0'
77
+ - jar 'com.tibco:tibjms-admin', '>= 7.0'
78
+ rubyforge_project:
79
+ rubygems_version: 2.4.8
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: TibEMS bindings for Ruby
83
+ test_files: []