Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
JRuby 9.0.0.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
reidmorrison committed Aug 29, 2015
1 parent dbbeecb commit f4d7787
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 148 deletions.
2 changes: 1 addition & 1 deletion jruby-jms.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
spec.email = ['reidmo@gmail.com']
spec.homepage = 'https://github.com/reidmorrison/jruby-jms'
spec.summary = 'JRuby interface into JMS'
spec.description = 'JRuby-JMS is a Java and Ruby library that exposes the Java JMS API in a ruby friendly way. For JRuby only.'
spec.description = 'jruby-jms is a complete JRuby API into Java Messaging Specification (JMS) V1.1. For JRuby only.'
spec.files = FileList['./**/*'].exclude('*.gem').map { |f| f.sub(/^\.\//, '') }
spec.test_files = Dir['test/**/*']
spec.license = 'Apache License V2.0'
Expand Down
18 changes: 9 additions & 9 deletions lib/jms/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ class Connection
# call the supplied code block, then close the connection upon completion
#
# Returns the result of the supplied block
def self.start(params = {}, &proc)
raise "Missing mandatory Block when calling JMS::Connection.start" unless proc
def self.start(params = {}, &block)
raise(ArgumentError, 'Missing mandatory Block when calling JMS::Connection.start') unless block
connection = Connection.new(params)
connection.start
begin
proc.call(connection)
block.call(connection)
ensure
connection.close
end
Expand All @@ -63,9 +63,9 @@ def self.start(params = {}, &proc)
# Note: It is important that each thread have its own session to support transactions
# This method will also start the session immediately so that any
# consumers using this session will start immediately
def self.session(params = {}, &proc)
def self.session(params = {}, &block)
self.start(params) do |connection|
connection.session(params, &proc)
connection.session(params, &block)
end
end

Expand Down Expand Up @@ -248,11 +248,11 @@ def stop
# session is transacted.
# Default: JMS::Session::AUTO_ACKNOWLEDGE
#
def session(params={}, &proc)
raise "Missing mandatory Block when calling JMS::Connection#session" unless proc
def session(params={}, &block)
raise(ArgumentError, 'Missing mandatory Block when calling JMS::Connection#session') unless block
session = self.create_session(params)
begin
proc.call(session)
block.call(session)
ensure
session.close
end
Expand Down Expand Up @@ -436,7 +436,7 @@ def to_s
# since on_message will Not be called if the connection is lost
#
def on_message(params, &block)
raise "JMS::Connection must be connected prior to calling JMS::Connection::on_message" unless @sessions && @consumers
raise 'JMS::Connection must be connected prior to calling JMS::Connection::on_message' unless @sessions && @consumers

consumer_count = params[:session_count] || 1
consumer_count.times do
Expand Down
136 changes: 0 additions & 136 deletions lib/jms/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,142 +38,6 @@ module JMS::Message
# Clears out the properties of this message
#

# For Backward compatibility with JRuby prior to 1.6
# JRuby 1.6 now does all this for us. Thank you headius :)
unless self.instance_methods.include? :jms_delivery_mode

# Header Fields - Attributes of the message

# Returns the JMS Delivery Mode
# One of the following will be returned
# JMS::DeliveryMode::PERSISTENT
# JMS::DeliveryMode::NON_PERSISTENT
def jms_delivery_mode
getJMSDeliveryMode
end

# Set the JMS Delivery Mode
# Values can be
# JMS::DeliveryMode::PERSISTENT
# JMS::DeliveryMode::NON_PERSISTENT
def jms_delivery_mode=(mode)
raise "Sorry, due to incompatibility with JRuby 1.6, please call jms_delivery_mode_sym when using symbols" if mode.is_a? Symbol
self.setJMSDeliveryMode(mode)
end

# Is the message persistent?
def persistent?
getJMSDeliveryMode == JMS::DeliveryMode::PERSISTENT
end

# Returns the Message correlation ID as a String
# The resulting string may contain nulls
def jms_correlation_id
String.from_java_bytes(getJMSCorrelationIDAsBytes) if getJMSCorrelationIDAsBytes
end

# Set the Message correlation ID
# correlation_id: String
# Also supports embedded nulls within the correlation id
def jms_correlation_id=(correlation_id)
setJMSCorrelationIDAsBytes(correlation_id.nil? ? nil : correlation_id.to_java_bytes)
end

# Returns the Message Destination
# Instance of JMS::Destination
def jms_destination
getJMSDestination
end

# Set the Message Destination
# jms_destination: Must be an instance of JMS::Destination
def jms_destination=(destination)
setJMSDestination(destination)
end

# Return the message expiration value as an Integer
def jms_expiration
getJMSExpiration
end

# Set the Message expiration value
# expiration: Integer
def jms_expiration=(expiration)
setJMSExpiration(expiration)
end

# Returns the Message ID as a String
# The resulting string may contain embedded nulls
def jms_message_id
getJMSMessageID
end

# Set the Message correlation ID
# message_id: String
# Also supports nulls within the message id
def jms_message_id=(message_id)
setJMSMessageID(message_id)
end

# Returns the Message Priority level as an Integer
def jms_priority
getJMSPriority
end

# Set the Message priority level
# priority: Integer
def jms_priority=(priority)
setJMSPriority(priority)
end

# Indicates whether the Message was redelivered?
def jms_redelivered?
getJMSRedelivered
end

# Set whether the Message was redelivered
# bool: Boolean
def jms_redelivered=(bool)
setJMSPriority(bool)
end

# Returns the Message reply to Destination
# Instance of JMS::Destination
def jms_reply_to
getJMSReplyTo
end

# Set the Message reply to Destination
# reply_to: Must be an instance of JMS::Destination
def jms_reply_to=(reply_to)
setJMSReplyTo(reply_to)
end

# Returns the Message timestamp as Java Timestamp Integer
#TODO Return Ruby Time object?
def jms_timestamp
getJMSTimestamp
end

# Set the Message timestamp as Java Timestamp Integer
# timestamp: Must be an Java Timestamp Integer
#TODO Support Ruby Time
def jms_timestamp=(timestamp)
setJMSTimestamp(timestamp)
end

# Returns the Message type supplied by the client when the message was sent
def jms_type
getJMSType
end

# Sets the Message type
# type: String
def jms_type=(type)
setJMSType(type)
end
end

# Return the JMS Delivery Mode as a Ruby symbol
# :persistent
# :non_persistent
Expand Down
3 changes: 3 additions & 0 deletions lib/jms/message_consumer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ def each(params={}, &block)
def on_message(params={}, &proc)
raise(ArgumentError, 'MessageConsumer::on_message requires a code block to be executed for each message received') unless proc

# Turn on Java class persistence: https://github.com/jruby/jruby/wiki/Persistence
self.class.__persistent__ = true

@listener = JMS::MessageListenerImpl.new(params, &proc)
self.setMessageListener(@listener)
end
Expand Down
5 changes: 4 additions & 1 deletion lib/jms/session_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def initialize(connection, params={})
timeout: session_params[:pool_timeout] || 60,
close_proc: nil,
logger: logger) do
connection.create_session(session_params)
session = connection.create_session(session_params)
# Turn on Java class persistence: https://github.com/jruby/jruby/wiki/Persistence
session.class.__persistent__ = true
session
end

# Handle connection failures
Expand Down
2 changes: 1 addition & 1 deletion test/connection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class JMSTest < Minitest::Test
it 'create a session without a block and throw exception' do
connection = JMS::Connection.new(@config)

assert_raises(RuntimeError) { connection.session }
assert_raises(ArgumentError) { connection.session }

assert_nil connection.stop
assert_nil connection.close
Expand Down

0 comments on commit f4d7787

Please sign in to comment.