Introduction
In real life, your users are doing different things at the same moment, but our examples so far were doing the same thing - FTP upload.
This page shows how you can run many simultaneous action queues and each queue can run its own actions.
Extend our example performance action
So far the FileTransferActions is able to do one thing - upload FTP files as you can see it here
Now we will extend it a little, so it can handle HTTP transfers as well. We will change only the connect method:
@Action public void connect( @Parameter(name = "hostname") String hostname, @Parameter(name = "protocol") String protocol, @Parameter(name = "port") int port, @Parameter(name = "username") String username, @Parameter(name = "password") String password ) { if( protocol.equalsIgnoreCase( "FTP" ) ) { transferClient = new FileTransferClient( TransferProtocol.FTP ); } else { transferClient = new FileTransferClient( TransferProtocol.HTTP ); } transferClient.setPort( port ); transferClient.connect( hostname, username, password ); }
The difference is that we have introduced one more input argument called protocol and in the method body we are asking the FileTransferClient class (part of ATS) to establish a connection over FTP or HTTP.
Deploy the new need code
Here are the steps in details
Run a test with simultaneous action queues
Let's have a look at this test code:
import com.axway.ats.agent.webapp.client.ActionQueue; public void simultanousFileTransfers() throws Exception { // create the FTP load client LoadClient ftpLoader = new LoadClient( LOADER_ADDRESS ); ftpLoader.setThreadingPattern( new AllAtOncePattern( 2, false, 100, 0 ) ); // do FTP transfers ftpLoader.startQueueing( "FTP transfer" ); FileTransferActions ftpTransferActions = new FileTransferActions(); ftpTransferActions.connect( SERVER_IP, "FTP", SERVER_FTP_PORT, USER_NAME, USER_PASSWORD ); ftpTransferActions.upload( "C:/some_file.txt" ); ftpTransferActions.disconnect(); ftpLoader.executeQueuedActions(); // create the HTTP load client LoadClient httpLoader = new LoadClient( LOADER_ADDRESS ); httpLoader.setThreadingPattern( new AllAtOncePattern( 2, false, 100, 0 ) ); // do HTTP transfers httpLoader.startQueueing( "HTTP transfer" ); FileTransferActions httpTransferActions = new FileTransferActions(); httpTransferActions.connect( SERVER_IP, "HTTP", SERVER_HTTP_PORT, USER_NAME, USER_PASSWORD ); httpTransferActions.upload( "C:/some_other_file.txt" ); httpTransferActions.disconnect(); httpLoader.executeQueuedActions(); ActionQueue.waitUntilAllQueuesFinish(); }
Please spend some time looking through this code. Here is what we do:
- We use different names for both queues, so they can be distinguished
- The connect action is called with the appropriate arguments for each protocol
- We are creating one Loader for each queue. Both queues have different actions. Note that you can freely use the same or different actions from the same or different action classes.
The 2nd argument in the threading pattern constructor is false, while by default it is set to true . This argument specifies if we must wait when calling the executeQueuedActions method.
If we use true here, the first queue will get started and we will wait here until it is over. Then we will start the next queue.
But in our case we need simultaneous executions, that is why we use false. This way the test code will go on and start the second queue as soon as have started the first one.
- The last test line causes waiting until all(in our case both) action queues are completed
The result
Both queues have started at the same time, but their duration is significantly different
Back to parent page
Go to Table of Contents