Re: Jini+JavaSpace05 to j2ee

Heiko Braun <[email protected]> Fri, 21 Dec 2007 09:39:20 +0100
Newsgroups gmane.comp.java.sun.jini
Organization JBoss / Red Hat
Message-ID <[email protected]>
IMO, you shouldn't mess with the threading in a managed 
environment like a servlet container. Instead use a 
JCA adapter like Nati suggested. 

/Heiko

On Thu, 2007-12-20 at 21:26 +0000, Luis Arce wrote:
> Hi all,
> 
> Anyone know what is the best practice for connect Jini+JavaSpace05 to j2ee 
> (ejb,servlet or J2EE-JCA).
> 
> My code is the next:
> 
> public class Jini
>   extends HttpServlet
>   implements DiscoveryListener,LeaseListener
> {
>   public void init(ServletConfig config)
>     throws ServletException
>   {
>     super.init(config);
>     try
>     {
>       Long tiempo=System.currentTimeMillis();
>       System.setSecurityManager(new RMISecurityManager());
>       LookupDiscovery descubrir=
> 	new LookupDiscovery(LookupDiscovery.ALL_GROUPS);
>       descubrir.addDiscoveryListener(this);
>       Thread.currentThread().sleep(Lease.FOREVER);
>     }
>     catch(RemoteException e)
>     {
>       System.out.println(e.toString());
>     }
>     catch(Exception e)
>     {
>       System.out.println(e.toString());
>     }
>   }
> 
>   public void service(HttpServletRequest request,
> 		      HttpServletResponse response)
>     throws ServletException,IOException
>   {
> 
> 
>     PrintWriter out=response.getWriter();
>     out.write("Hola");
>     out.close();
>   }
> 
>   public void discovered(DiscoveryEvent evt)
>   {
>     try
>     {
>       ServiceRegistrar[] registrars=evt.getRegistrars();
>       for(int n=0;n<registrars.length;n++)
>       {
> 	System.out.println("Descubriendo");
> 	ServiceRegistrar registrar=registrars[n];
> 	ServiceTemplate tmpl=new ServiceTemplate(null,new Class[]
> 	    { JavaSpace05.class },null);
> 	JavaSpace05 jsprueba=(JavaSpace05)registrar.lookup(tmpl);
> 	if(jsprueba!=null)
> 	{
> 	  System.out.println("Escribiendo grid");
> 	  Factura factura=new Factura();
> 	  factura.nombre="prueba1";
> 	  factura.nombre="valor1";
> 	  Entry prueba=factura;
> 	  jsprueba.write(prueba,null,Long.MAX_VALUE);
> 	}
>       }
>     }
>     catch(RemoteException e)
>     {
>       System.out.println(e.toString());
>     }
>     catch(TransactionException e)
>     {
>       System.out.println(e.toString());
>     }
>   }
> 
>   public void discarded(DiscoveryEvent evt)
>   {
>     System.out.println("Descartando "+evt.toString());
>   }
> 
>   public void notify(LeaseRenewalEvent evt)
>   {
>     System.out.println("Expirado"+evt.toString());
>   }
> }
> 
> Best regards,
> Luis Arce
> 
> _________________________________________________________________
> Consigue aquí las mejores y mas recientes ofertas de trabajo en América 
> Latina y USA: http://latam.msn.com/empleos/
> 
> --------------------------------------------------------------------------
> Getting Started:     http://www.jini.org/wiki/Category:Getting_Started
> Community Web Site:  http://jini.org
> jini-users Archive:  http://archives.java.sun.com/archives/jini-users.html
> Unsubscribing:       email "signoff JINI-USERS"  to [email protected]

--------------------------------------------------------------------------
Getting Started:     http://www.jini.org/wiki/Category:Getting_Started
Community Web Site:  http://jini.org
jini-users Archive:  http://archives.java.sun.com/archives/jini-users.html
Unsubscribing:       email "signoff JINI-USERS"  to [email protected]