16
Tue, Jul
4 New Articles

IBM Toolbox for Java and Data Queues

Java
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Many applications depend on passing a number of different messages from one system to another. When you think of an application of this nature, the first thing that comes to mind is Web Services. The most common way to use Web Services is to have specific messages defined in XML passed to a server that processes the XML message. Some people consider using RMI or CORBA for an application dependent on messaging.

When you're thinking of adopting a particular technology, you must consider many things. Just a couple of those things should be the time it will take to educate yourself and others within your department as well as the cost of the technology and the overhead of running a particular technology within your environment. Depending on the development skills within your workshop, Web Services, RMI, and CORBA may be a lot to handle up front. However, if you have a development area that depends on the iSeries and the developers within your area are familiar with Java, you may want to consider IBM Toolbox for Java and the data queue implementation for passing messages.

IBM Toolbox for Java is a set of Java classes that allow you to write Java applications that interact with data on your iSeries. IBM Toolbox for Java uses the Host Servers to communicate with different iSeries objects.

Allow Multiple Clients to Pass Messages to Different Data Queues

I recently returned from a cruise. The cruise ship had an elevator to take passengers to different floors on the ship. The elevator attendant asked the passengers which floors they wanted to go to and then pressed the numbers for those floors on the elevator's keypad. This is a good analogy of the architecture that I am going to talk about.

The iSeries server has one main data queue that listens for clients that want to open communications and close communications. In order for the client to communicate with the server, an open session request message must be sent to the server. When the main data queue receives that request message from the client, it creates another data queue that the client uses for communications. On the server, a separate thread is created that listens to requests on the data queue that was created for that particular client. The server sends a response message to the client, informing the client which data queue it is supposed to communicate with. The client then sends every message to that data queue. Once the client is done communicating with the server, it sends a close session message, which deletes the data queue that the client was using and destroys the thread that was used to listen on that data queue.

You can think of the main data queue as the attendant who is waiting for the passengers to enter the elevator. The passengers are clients. Once the passengers successfully enter the elevator, they communicate on different data queues that are assigned by the attendant. When the passengers are ready to come off the elevator, they send a close session to the attendant, who deletes the data queue that the client was using along with the thread that was created for them.

The Open Session and Close Session Message and Response

The first thing that must be defined is the messages that will be passed to and from the server. In the past, developers created their own message formats and documented them in great detail. However, XML has evolved as the standard way of creating and passing messages between different systems. XML is also easy to read, which makes it convenient when debugging a problem.

The first message we will create is the Open-Session-Request message. This message will be sent from the client to the server's main data queue. Note that the main data queue will listen only for clients that want to open a session and close a session. Once the main data queue receives the Open-Session-Request, it creates another data queue for that particular client to communicate with. The server then dynamically creates a session ID that the client uses to talk to the data queue that was assigned. An Open-Session-Response will be created that will have the name of the data queue for that client to communicate with, along with a session ID.

The Open-Session-Request XML that will be used to send to the server will look like this:

The Open-Session-Response XML that the server will send to the client will look like this:

 session-id= />

Here, the data-queue-communication-object is the name of the data queue that the client will use to communicate with, and session-id-value is dynamically created for that particular client.

Once the client receives the Open-Session-Response, it knows which data queue to communicate with and can send further messages to the server for processing. When the client is done, it sends a Close-Session-Request to the main data queue, which notifies the server that the client is done communicating. The Close-Session-Request sends the data queue that was created for communications within the Close-Session-Request. This way, the main data queue knows which data queue to remove and which thread to destroy. Once this is done, the server sends the Close-Session-Response to the client, which allows the client to know that communications have ended successfully.

The Close-Session-Request looks like this:

 session-id= />

Here, data-queue-communication-object is the name of the data queue that the client used for communications with the server, and session-id-value is what the client was assigned to communicate with the server.

The Close-Session-Response that's used to notify the client that communications ended successfully looks like this:



More messages could be defined, but we will look only at the open session and close session messages.

Creating Additional Data Queues per Client

There are many advantages to using data queues when receiving messages from a client:

  • Many clients can send messages to one single data queue.
  • Messages on a data queue are free-format, meaning that a long string value can be sent.
  • The data queue can be used for either synchronous or asynchronous processing.
  • Messages within a data queue can be ordered as last-in first-out (LIFO), first-in first-out (FIFO), or keyed. When the data queue is marked as keyed, a message can be taken off the queue by specifying a single key.

To ensure that the correct clients are sending messages to the server, we will use the KeyedDataQueue. All clients that are distributed will have a keyed value that is used to communicate with the main data queue on the server. Clients that try to send messages to the data queue without the key will not be successful. By using a KeyedDataQueue, we have control over which clients are sending messages to our server.

The client must send an Open-Session-Request message to start communications with the server. Once the server receives an Open-Session-Request, it creates a keyed data queue to be used for communications by the client. The server also dynamically creates a session ID and sends this information back to the client in the Open-Session-Response. When a message is sent to a keyed data queue, a key must be sent along with it. We will use the session ID as the key for communications. Anytime a client wants to send another message after a session has been opened, it must use the session ID as the key. This is done to ensure that only that one single client can send and receive messages from that data queue. An example of this is shown in Figure 1.

http://www.mcpressonline.com/articles/images/2002/GarbersFig1--05090500.jpg

Figure 1: The Open-Session-Request is sent to the server's main data queue, which starts a new thread for that client and creates a keyed data queue for only that client to communicate with. The server then informs the client of which keyed data queue to communicate with by sending an Open-Session-Response. (Click images to enlarge.)

When the client is done communicating, it sends a Close-Session-Request to the main data queue, which then deletes the data queue that was created for that client, and the separate thread that was used to monitor the client's queue is destroyed. This is shown in Figure 2.


http://www.mcpressonline.com/articles/images/2002/GarbersFig2--05090500.jpg

Figure 2: The client sends a Close-Session-Request to the server's main data queue. Once it's received, the client's keyed data queue is removed and the thread the server was using to allow the client to communicate with is destroyed. A Close-Session-Response is sent to the client to indicate that communications have ended.

The More, the Merrier

As you can see, the more clients there are, the more data queues there are. Each client communicates with its own data queue that is monitored by its own server thread. If one particular client has a problem, it should not affect the other clients. This architecture also makes it easy to debug client problems because the data queue and thread of each client are independent.

Benjamin Garbers is a Software Engineer within the Rochester Support Center. He is currently developing Internet applications for IBM's iSeries Technical Web site.

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: