 |
Recently there have been introduced new ways of interacting with SLEE from J2EE?.
This page is meant to give quick reference how programmer can utilize those ways in source
of his programs.
Specification conforming way of connecting to SLEE
Mobicents supports this way of contacting with SLEE. In v1.0 of specification detailed information can be found in section
F2 of appendix F. However for now ConnectionFactory is accesbile only from container JVM.
This is how it can be accesed and used:
InitialContext ctx = new InitialContext();
SleeConnectionFactory factory =
(SleeConnectionFactory)ctx.lookup("java:MobicentsConnectionFactory");
// Obtain a connection to the SLEE from the factory
SleeConnection connection = factory.getConnection();
// Locate the event types for two different events
EventTypeID eventTypeOne = connection.getEventTypeID("MyEventOne","MyVendor","0.1");
EventTypeID eventTypeTwo = connection.getEventTypeID("MyEventTwo","MyVendor","0.1");
MyEventOne eventOne = ...;
MyEventTwo eventTwo = ...;
// Fire an asynchronous events
ExternalActivityHandle handle = connection.createActivityHandle();
connection.fireEvent(eventOne, eventTypeOne, handle, null);
connection.fireEvent(requestOne, eventTypeTwo, handle, null);
Work on v1.1 section 15.13.2-4 connection model will begin shortly.
SleeService
SleeService is class which is publicly accesbile through JNDI. It should be used just as ConnectionFactory as it exposes interface of SleeConnection.
This is proper way of using this facility:
....
SleeService service=null
...
try{
Properties properties = new Properties();
//JNDI lookup properties
properties.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
String tmpIP=getIpFromProps();
if(tmpIP==null)
tmpIP="127.0.0.1";
properties.put("java.naming.provider.url", "jnp://"+tmpIP+":1099");
InitialContext ctx=new InitialContext(properties);
service=(RemoteSleeService)ctx.lookup("/SleeService");
}catch(NamingException ne) {
ne.printStackTrace();
}catch(Exception E) {
E.printStackTrace();
}
// }
if(service!=null) {
try {
// Locate the event type, in X-event-jar.xml
EventTypeID requestType = service.getEventTypeID("EventName","EventVendor","EventVersion");
EventX event=...;
// Fire an asynchronous event
ExternalActivityHandle handle = service.createActivityHandle();
Address address=new Address(AddressPlan.SMTP,UID);
service.fireEvent(request, requestType, handle, address);
//connection.endExternalActivity(handle);
}catch(RemoteException RE) {
System.out.println("REMOTE EXCEPTION!!!");
RE.printStackTrace();
}
}
EJB
There is also EJB proxy to SleeConnection. Way it should be utilized is not different from SleeService and ConnectionFactory.
There is a property file in org.mobicents.slee.connector.proxy dir ( in src dir of project), which specifies jndi lookup properties to serach for ConnectionFactory in container.
( provides proxy with jnp host and initial context factory name)
Remote Interface
Here is how remote interface ofEJB Proxy should be accessed.
private org.mobicents.slee.connector.proxy.SleeConnectionProxyHome getHome()
throws NamingException {
getLog().info(" == RETRIEVING HOME OBJECT FOR EJBS( JNDI LOOKUP:"+org.mobicents.slee.connector.proxy.SleeConnectionProxyHome.JNDI_NAME+" ) ==");
return (org.mobicents.slee.connector.proxy.SleeConnectionProxyHome) getContext()
.lookup(
org.mobicents.slee.connector.proxy.SleeConnectionProxyHome.JNDI_NAME);
}
private InitialContext getContext() throws NamingException {
Hashtable props = new Hashtable();
props.put(InitialContext.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
//JNP url should point to jboss container with Mobicents and ejb connection proxy
props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099");
// This establishes the security for authorization/authentication
// props.put(InitialContext.SECURITY_PRINCIPAL,"username");
// props.put(InitialContext.SECURITY_CREDENTIALS,"password");
InitialContext initialContext = new InitialContext(props);
return initialContext;
}
Breaking to make it more readable.
...
try {
getLog().info(" == CREATING EJB ==");
org.mobicents.slee.connector.proxy.SleeConnectionProxy myBean1 = getHome()
.create();
org.mobicents.slee.connector.proxy.SleeConnectionProxy myBean2 = getHome()
.create();
org.mobicents.slee.connector.proxy.SleeConnectionProxy myBean3 = getHome()
.create();
ExternalActivityHandle ah = myBean1.createActivityHandle();
EventTypeID sip = myBean1.getEventTypeID("com.opencloud.sleetck.lib.resource.events.TCKResourceEventX.X1","jain.slee.tck","1.0");
//Response resp=new Response();
getLog().info( " == EVENTTYPEID:[ "+sip+" ] ==");
String []tmp={"111111","222222222","33333333333","444","5555"};
Object[] message=new Object[7];
int[] a={1,2,3,4,5};
message[0]="ServiceID[SomeNotExistingService#mobicents#0.1]";
message[1]=a;
message[2]=tmp;
message[3]=new ComponentKey("ALA","mA","KOTA");
message[4]=new ComponentKey("ALA1","mA2","KOTA3");
TCKResourceEventX event = new TCKResourceEventImpl(12,
TCKResourceEventX.X1,message , null);
myBean1.fireEvent(event,sip,ah,null);
} catch (RemoteException e) {
result.setError(e);
e.printStackTrace();
} catch (CreateException e) {
result.setError(e);
e.printStackTrace();
} catch (NamingException e) {
result.setError(e);
e.printStackTrace();
} catch (ResourceException e) {
result.setError(e);
e.printStackTrace();
} catch (UnrecognizedEventException e) {
result.setError(e);
e.printStackTrace();
}
...
Local Interface
Here is how local interface of EJB Proxy should be accessed.
( Will follow shortly )
Tips
Connections should be reused since there is limited pool of them - in all cases.
-- Main.baranowb - 12 Apr 2005
|