Creating administered objects

To use JMS applications with Eclipse Amlen, you must first create Eclipse Amlen administered objects for JMS.

  1. Create the administered object.
    Use the ImaJmsFactory class to create the Eclipse Amlen administered objects for JMS. Use the methods in this class to create connection factory and destination objects for your JMS applications.
  2. Configure the administered object.
    Use the ImaProperties interface to configure the connection factory and destination objects. Cast the administered object created in step 1 to ImaProperties. Then use the appropriate put methods to set either ConnectionFactory properties or Destination properties.
  3. Validate the configured administered object.
    Once all desired properties have been set, use the ImaProperties validate method to assure the administered object is correctly configured.
  4. Store the configured administered objects in a JNDI repository.
  • The following example creates and configures a connection factory administered object.
    // Create the connection factory using the ImaJmsFactory class
    ConnectionFactory cf = ImaJmsFactory.createConnectionFactory();
    
    // Cast the connection factory object to ImaProperties
    ImaProperties props = (ImaProperties)cf;
    
    // Set the properties
    // You must configure the connection port where the Eclipse Amlen is listening for
    // connections from JMS clients
    props.put("Port", "1883");
    
    // You must also configure the host names (or IP addresses) where the Eclipse Amlen is running
    // For high availability configurations, include the list of host names (or IP addresses)
    props.put("Server", "server1.company.com, server2.company.com");
    
    // If you are using secure connections, then you must set Protocol to tcps
    props.put("Protocol", "tcps");
    
    // Validate the configured object. A null return means that the properties are valid.
    ImaJmsException [] errstr = props.validate(ImaProperties.WARNINGS);
    if (errstr == null) {
        // If there are no errors, store the object in a JNDI repository
        InitialContext ctx;
        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.PROVIDER_URL, "ldap://server3.company.com/o=jndiTest");
        try {
            ctx = new InitialContext(env);
    
            // Bind the connection factory to a name
            ctx.rebind("ConnName", cf);
        } catch (Exception e) {
            System.out.println("Unable to open an initial context: " + e);
        }
    } else {
        // Display the validation errors
        for (int i=0;  i<errstr.length; i++)
            System.out.println(""+errstr[i]);
    }
  • The following example creates and configures a destination administered object:
    // Create the destination using the ImaJmsFactory class
    // This example creates a topic destination.
    // A queue destination can be created with createQueue(String name)
    Topic topicdest = ImaJmsFactory.createTopic("mytopic");
    
    // Cast the destination object to ImaProperties
    ImaProperties props = (ImaProperties)topicdest;
    
    // Optional - Set the properties
    // The only required property for a destination is name and that property value is
    // set automatically with createTopic
    // For this example, we will not set any properties
    
    // As a best practice, validate the object. A null return means that the properties are valid.
    ImaJmsException [] errstr = props.validate(ImaProperties.WARNINGS);
    if (errstr == null) {
        // If there are no errors, store the object in a JNDI repository
        InitialContext ctx;
        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.PROVIDER_URL, "ldap://server3.company.com/o=jndiTest");
        try {
            ctx = new InitialContext(env);
    
            // Bind the connection factory to a name
            ctx.rebind("ConnName", cf);
        } catch (Exception e) {
            System.out.println("Unable to open an initial context: " + e);
        }
    } else {
        // Display the validation errors
        for (int i=0; i<errstr.length; i++)
            System.out.println(""+errstr[i]);
    }

For an example of an application that creates Eclipse Amlen administered objects for JMS, see the JMSSampleAdmin application in Sample applications.