Creating java application

You can find the extended version of this example, known as ExampleAlignmentClient.java in our latest release package (or just check it here).

  1. Firstly, you need to create ExampleAlignmentClient.java and import all necessary packages. We will use java.util.Map structure to encapsulate offsets data:
    import java.util.HashMap;
    import java.util.Map;
  2. Now, import Tudas classes:
    import ch.cern.totem.tudas.clients.java.DatabaseAccessProvider;
    import ch.cern.totem.tudas.clients.java.data.manager.RomanPotManager;
  3. Create your example class and main method, where we'll write whole application code:
    public class ExampleAlignmentClient {
        public static void main(String[] args) {
        }
    }
  4. It is recommended to surround all Tudas library invocations with try-catch block in order to properly handle exceptions. The main Tudas exception class is called TudasException. You can catch it and just print the exception (find more details about exceptions handling here):
    DatabaseAccessProvider serviceProvider = null;
    try {
          //write your code here
    } catch(TudasException e) {
        System.out.println(e);
    } finally {
        if (serviceProvider != null) {
           try {
              serviceProvider.close();
           } catch (TudasException e) {
              System.out.println(e);
           }
        }
    }
  5. Before you perform any database operation, you have to initialize DatabaseAccessProvider - main Tudas class, managing connection with Tudas Server and offering all Tudas services. Remember, that once you've created DatabaseAccessProvider object, it should be also initialized by calling initialize() method. Only then, it is fully configured and ready to establish connection with Tudas Server:
    serviceProvider = new DatabaseAccessProvider();
    serviceProvider.initialize();
    As you could see in step 4, there is also need of closing DatabaseAccessProvider at the end of your program, preferably during exception handling. We make sure if it has been already initialized and if so, we call close() method.
  6. DatabaseAccessProvider delivers set of services, connected with different functionalities, offered by our system. One of them is RomanPotManager, which is able to, inter alia, save and load roman pot offsets data. To create RomanPotManager, simply invoke getRomanPotManager() on your serviceProvider object:
    RomanPotManager rpManager = serviceProvider.getRomanPotManger();
  7. In order to save roman pot offsets into the database, we'll need three parameters: start time of validity interval, string label describing measurement and offets structure. Offsets are stored in roman pot label - offset value map (roman pot labels have to be prepared according to standard convention). It may look like as follows:
    Map<String, Double> offsets = new HashMap<String, Double>();
    offsets.put("020", 1.0);
    offsets.put("125", 2.0);
    offsets.put("103", 3.0);
  8. Finally, you can save your offset data into the database. In this example we use 12345 as validity interval start time and "beta90" as measurement label:
    int offsetsVersion = rpManager.saveOffsets(12340, "beta90", offsets);
    As you can see, the method returns offsetsVersion, which is number describing version of the data in the database. If you save the same data more then once, you'll get successive version number (data in Totem Offline Database is never deleted or overriden, for most of our interfaces, we offer unified versioning mechanism).
  9. Loading data is just reverse process - you offer timestamp and label parameters, and RomanPotManager returns offsets map:
    Map<String, Double> resultOffsets = rpManager.loadOffsets(12341, "beta90");
    This method always returns the latest version of data connected with specified arguments. Alternatively, you can also manually set version of data that should be loaded from the database. In our case:
    Map<String, Double> resultOffsets = rpManager.loadOffsets(12341, "beta90", offsetsVersion);
  10. If you'd like to ensure if loaded data is correct, just print a content of resultOffests map:
    for (String romanPotID : resultOffsets.keySet()) {
       System.out.println("RP id=" + romanPotID + " value=" + resultOffsets.get(romanPotID));
    }
  11. Now, your application code is complete. You can compile and test it. Assuming that your tudas.jar library is located on path: ./lib/tudas.jar and you have your ExampleAlignmentClient.java source code in current directory, all you need to do is to execute commands:
     javac -cp ./lib/tudas.jar ExampleLuminosityClient.java
     java -cp .:./lib/tudas.jar ExampleLuminosityClient
Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r3 - 2012-09-06 - unknown
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    TOTEM All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
or Ideas, requests, problems regarding TWiki? use Discourse or Send feedback