You can also write your own adapters to tailor MQe for your own environment. This topic describes some adapter examples that are supplied to help you with this task.
This example is not intended as a replacement for the adapters that are supplied with MQe, but as a simple introduction on how to create a communications adapter.
To use your communications adapter, you must specify the correct class name when creating the listener on the server queue manager, and specify the connection definition on the client queue manager.
All communications adapters must inherit from MQeCommunicationsAdapter and must implement the required methods. In order to show how this might be done we shall use the example adapter, examples.adapters.MQeTcpipLengthGUIAdapter. This is a simple example that accepts data to be written. It also places the data length and the amount of data to be written to standard out, at the front of the data. When the adapter reads data, the data length is written to standard out. Proper error checking and recovery is not carried out. This must be added to any adapter written by a user.
MQe adapters use the default constructor. For this reason, an activate() method is used in order to set up the adapter with an open() method used to prepare the adapter for communication.
if (!listeningAdapter) { // if we are not a listening adapter we need the address of the server address = info.getProperty (MQeCommunicationsAdapter.COMMS_ADAPTER_ADDRESS); }
if (listeningAdapter && null == serverSocket) { serverSocket = new ServerSocket(port); } else if (!responderAdapter && null == mySocket) { mySocket = new Socket(InetAddress.getByName(address), port); }
MQeTcpipLengthGUIAdapter clientAdapter = (MQeTcpipLengthGUIAdapter) MQeCommunicationsAdapter.createNewAdapter(info); // set the boolean variables so the adapter // knows it is a responder. the listening // variable will have been set to true as // the MQePropertyProvider has the relevant // information to create // this listening adapter. We must therefore reset the // listeningAdapter variable to false and the //responderAdapter variable to true. clientAdapter.responderAdapter = true; clientAdapter.listeningAdapter = false; // Assign the new socket to this new adapter clientAdapter.setSocket(clientSocket); return clientAdapter;
do { try { clientSocket = serverSocket.accept(); } catch (InterruptedIOException iioe) { if (MQeThread.getDemandStop()) { throw iioe; } } } while (null == clientSocket);
Parent topic: Using adapters