Terminal Connection Pool

In many cases, using a connection pool in a Terminal-based project gives a big improvement in performance, as opening a session and, in many cases, logging into the Terminal is a time-consuming operation. For this reason, OpenLegacy allows the use of Connection Pools when creating such Terminal-based projects.

To achieve this functionality, the user will need to do the following:


First, we need to enable the pool in the project's configuration, this is done by adding the following properties to the YAML file located in the resource folder:

ol: h3270: project: h3270Pool: {sdk name}: pool: enable: true maxSize: 5 minSize: 1 keepAliveInterval: 1000

Let’s take a minute to explain these properties:

  • enable - boolean - by default, the pool is not enabled. To enable it, we need to set the Enable flag to true

  • maxSize - int - the maximum number of allowed open sessions to the legacy

  • minSize - int - the minimum number of allowed open sessions to the legacy

  • keepAliveInterval - long - the amount of time between each keep-alive action


To meet the conditions above, every project must implement three methods:

  • Init Action- The actions taken once a new session is created, such as log in to the terminal.

  • Clean Up Action- The actions taken once the application returns a session into the pool, for example navigating back to the main menu screen.

  • Keep Alive Action - An action that keeps the session alive when the session is stored in the pool. This action is usually is very quick. If the application takes a session from the pool, the applicative action will wait for the Keep Alive Action to complete due to synchronization.

Following is a code snippet we created to show a basic implementation of such pool configurations:

@Setter @Getter @Slf4j public class MfTerminalSessionActionsImpl implements TerminalPoolActions { TerminalAction initAction = (TerminalAction) (new MfTerminalSessionActionsImpl.InitDummyAction()); TerminalAction cleanUpAction = (TerminalAction) (new CleanupDummyAction()); TerminalAction keepAliveAction = (TerminalAction) (new MfTerminalSessionActionsImpl.KeepAliveDummyAction()); static class CleanupDummyAction implements TerminalAction { @Override public void perform(TerminalSession session, Object entity, Object... keys) { log.info("performing clean up action"); ScreenEntity screen = session.doAction(TerminalActions.escape()); while (!(screen instanceof EmptyScreen)) { screen = session.doAction(TerminalActions.escape()); } screen = session.doAction(TerminalActions.escape()); EmptyScreen emptyScreen = (EmptyScreen) screen; emptyScreen.setInput("INQ1"); session.doAction(TerminalActions.enter(), emptyScreen, LoansInquiry.class); } @Override public boolean isMacro() { return false; } @Override public String getAdditionalCommand() { return ""; } } class InitDummyAction implements TerminalAction { @Override public void perform(TerminalSession session, Object entity, Object... keys) { log.info("performing init action"); try { EmptyScreen emptyScreen = session.getEntity(EmptyScreen.class); emptyScreen.setInput("INQ1"); session.doAction(TerminalActions.enter(), emptyScreen, LoansInquiry.class); } catch (Exception e) { ScreenEntity screen = session.doAction(TerminalActions.escape()); while (!(screen instanceof EmptyScreen)) { screen = session.doAction(TerminalActions.escape()); } } } @Override public boolean isMacro() { return false; } @Override public String getAdditionalCommand() { return ""; } } class KeepAliveDummyAction implements TerminalAction { @Override public void perform(TerminalSession session, Object entity, Object... keys) { log.info("performing keep alive action"); ScreenEntity screen = session.doAction(TerminalActions.escape()); while (!(screen instanceof EmptyScreen)) { screen = session.doAction(TerminalActions.escape()); } EmptyScreen emptyScreen = (EmptyScreen) screen; emptyScreen.setInput("INQ1"); session.doAction(TerminalActions.enter(), emptyScreen, LoansInquiry.class); } @Override public boolean isMacro() { return false; } @Override public String getAdditionalCommand() { return ""; } } }

For Spring to load the pool implementation, you will need to register it as a Bean to your projects configuration class located at:

package com.h3270_pool.openlegacy.config;

named - {SDK Project name}Configuration.java

For example, in the attached project we called the pool implementation class MfTerminalSessionActionsImpl, and the SDK name h3270Pool, this resulted with:

 


Attached below are sample API and SDK projects implementing the pool

 

To test them, you run the API* and execute one call, then you will be able to see in the logs that the pool actions are being executed as expected

 

*To run the API please add your OpenLegacy License string to the API YAML.