Creating administered objects
To use JMS applications with Eclipse Amlen, you must first create Eclipse Amlen administered objects for JMS.
- 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.