jar
CLASSPATH=${CLASSPATH}:${APP}/jmsra/imqbroker.jar
CLASSPATH=${CLASSPATH}:${GLASSFISH}/imq/lib/imq.jar
CLASSPATH=${CLASSPATH}:${GLASSFISH}/imq/lib/jms.jar
CLASSPATH=${CLASSPATH}:liblib-connector.jar
java $*
Then you can invoke the class by doing this:
./run com.liblib.LegacyConnector
To stop the application you need to use Ctrl+C, because the listener won??™t quit on its own.
Now that we??™ve looked at the Java parts of the connector, we need to see the code that ties
it all together. We??™ll take it piece by piece, beginning with the header of the file. Open up a file
called liblib_connector.rb and put liblib-connector.jar in the same directory:
require 'java'
require 'liblib-connector.jar'
BookDescription = Struct.new :id, :name, :authors, :isbn, :instances
module LegacySystem
end
All your code will live in the LegacySystem module, except for the book description. The
first thing you need to do within the LegacySystem module is to import some classes that you
want to use, and create some handy things:
LegacyConnector = com.liblib.LegacyConnector
LegacyMessageHandler = com.liblib.LegacyMessageHandler
Connection = LegacyConnector.new
Transactions = {}
@@current_trans_id = 0
class RubyHandler
include LegacyMessageHandler
CHAPTER 13 ?– JRUBY AND MESSAGE-ORIENTED SYSTEMS 241
def handle(id, msg)
Transactions[id.to_i] = msg
end
end
Connection.handler = RubyHandler.new
First, you include the two Java classes you created earlier. Then, you create a new
instance of the LegacyConnector.
Pages:
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363