Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package me.prettyprint.cassandra.jndi;
 
 
A factory for JNDI Resource managed objects. Responsible for creating a CassandraClientJndiResourcePool. Relies on a supplied URL and port which Cassandra is listening on. These parameters are defined in a web application's context.xml file. For example:

     <Resource name="cassandra/CassandraClientFactory"
               auth="Container"
               type="me.prettyprint.cassandra.jndi.CassandraClientJndiResourcePool"
               factory="me.prettyprint.cassandra.jndi.CassandraClientJndiResourceFactory"
               url="localhost"
               port="9160" />      
 

Author(s):
Perry Hoekstra (dutchman_mn@charter.net)
Since:
0.5.1-8
{
  
Creates an object using the location or reference information specified.

Parameters:
object The possibly null object containing location or reference information that can be used in creating an object.
jndiName The name of this object relative to nameCtx, or null if no name is specified.
context The context relative to which the name parameter is specified, or null if name is relative to the default initial context.
environment The possibly null environment that is used in creating the object.
Returns:
Object - The object created; null if an object cannot be created.
Throws:
java.lang.Exception - if this object factory encountered an exception while attempting to create an object, and no other object factories are to be tried.
  public Object getObjectInstance(Object objectName jndiNameContext context,
      Hashtable<?, ?> environmentthrows Exception {  
    Reference resourceRef = null;
    
    if (object instanceof Reference) {
        resourceRef = (Referenceobject;
    } else {
      throw new Exception("Object provided is not a javax.naming.Reference type");
    }
    
    RefAddr urlRefAddr = resourceRef.get("url");
    
    RefAddr portRefAddr = resourceRef.get("port");
  
    if ((urlRefAddr != null) && (portRefAddr != null)) {
      return new CassandraClientJndiResourcePool((String)urlRefAddr.getContent(), 
                                               Integer.parseInt((String)portRefAddr.getContent())); 
    }  else {
      throw new Exception("A url and port on which Cassandra is installed and listening " + 
                      "on must be provided as a ResourceParams in the context.xml");
    }
  }
New to GrepCode? Check out our FAQ X