• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jini Server Getting closed

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an application say app1 which bind an object to the jini lookup service reggie.My many client interact with the my app1 using the object i have made available at look up service. After some time by app1 is terminating itself.i.e it is getting closed down.I am register my object using the code
ServiceRegistrar registrar.register(serviceItem, Lease.FOREVER);
can you please suggest where i am doing mistaks.
 
Ranch Hand
Posts: 291
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this a Jini issue or an application issue?

When your application dies, so dies the lease renewal.

Your application is really an RMI application.

Have you taken the steps necessary to ensure its survival? E.G. having a live reference to the _impl class; making sure the main() does not exit?

Is your application terminating due to an error? Are you catching exceptions/errors and cleaning up?

Writing a remote application is a lot of work.
 
chetan raj
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thansk Edward for you notable suggestions.
My problem is that i working on the sample example given at some website
with the necessary batch files to run the code.
My server is not responding after some time. And when i am running the client
program i am getting the fallowing exception
i.e Exception occured in MyClient.main() method:java.lang.NullPointerException
This is that example program
Inteface

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface MyServerInterface extends Remote {
public String sayHello () throws RemoteException;
}

MyServer Program
import net.jini.lookup.entry.Name;
import net.jini.lookup.ServiceIDListener;
import net.jini.core.lookup.ServiceID;
import net.jini.core.lookup.ServiceRegistrar;
import net.jini.core.lookup.ServiceItem;
import net.jini.core.discovery.LookupLocator;
import net.jini.core.entry.Entry;
import net.jini.core.lease.Lease;

import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;

public class MyService extends UnicastRemoteObject implements MyServerInterface {

public MyService () throws RemoteException {
super ();
}


public String sayHello () throws RemoteException { // MyServiceInterface
System.out.println ("server: The method sayHello() in MyService was " + "called");
return ("Hello World from MyService!");
}

public static void main (String[] args) {
MyServerInterface myServer;
LookupLocator lookup;
ServiceRegistrar registrar;
ServiceItem serviceItem;

try {
/* Set the security manager to allow the RMI class loader
to go to the codebase for classes that are not available
locally. */

System.setSecurityManager (new RMISecurityManager ());

/* Create the attributes (an array of entry objects) that describe this
server and use it to register this server with the lookup service.
JoinManager finds and registers with the lookup service */

Entry[] attr = new Entry[1];
attr[0] = new Name("HelloWorldServer");
myServer = new MyService ();
serviceItem = new ServiceItem(null, myServer, attr);

lookup = new LookupLocator ("jini://localhost");
registrar = lookup.getRegistrar();
registrar.register(serviceItem, Lease.FOREVER);

System.out.println("Serrvice Ready ...");

} catch (Exception e)
{
System.out.println("server: MyService.main(): Exception " + e);
}
}
}


MyClient program
import net.jini.core.entry.Entry;
import net.jini.core.discovery.LookupLocator;
import net.jini.core.lookup.ServiceRegistrar;
import net.jini.core.lookup.ServiceTemplate;
import net.jini.lookup.entry.Name;

import java.rmi.RMISecurityManager;

public class MyClient {
public static void main (String[] args) {
Entry[] aeAttributes;
LookupLocator lookup;
ServiceRegistrar registrar;
ServiceTemplate template;
MyServerInterface myServerInterface;

try {
/* Set the security manager to allow the RMI class loader to access
the codebase for classes that are not available locally */

System.setSecurityManager (new RMISecurityManager ());

/* Find the Jini lookup service (reggie) and print its location */

lookup = new LookupLocator ("jini://localhost");

/* Get the lookup service's ServiceRegistrar and perform a search to find
the service that has the name attribute name of "HelloWorldServer".
The lookup service returns an Proxy object to the service */

registrar = lookup.getRegistrar();
aeAttributes = new Entry[1];
aeAttributes[0] = new Name ("HelloWorldServer");
template = new ServiceTemplate (null, null, aeAttributes);
myServerInterface = (MyServerInterface) registrar.lookup (template);

System.out.println ("Calling sayHello()->" + myServerInterface.sayHello () + "<-");
} catch (Exception e) {
System.out.println ("client: MyClient.main() exception: " + e);
}
}
}


Please suggest me where i shall make changes in this code such that the
service object remain availabe for long time, unless some network failure etc.
Also suggest me few site where i am find some reference material and workable examples on jini technology.
 
Edward Harned
Ranch Hand
Posts: 291
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This sample code leaves a lot to be desired. But, try putting the following code at the bottom of the main() so that it does not exit.

 
chetan raj
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Edward for you prompt reply.
can you please send me few workable examples which uses net.jini.lookup.JoinManager instead of ServiceItem, Registar etc.

I have the following examples but its join method construtor has some errors

interface
public interface MyServerInterface extends Remote
{
public String sayHello () throws RemoteException;
}

MyServer
import net.jini.core.entry.*;
import net.jini.core.lookup.*;
import net.jini.lookup.entry.*;
import com.sun.jini.lookup.entry.*;
import com.sun.jini.lease.*;
import java.rmi.*;
import net.jini.lookup.ServiceIDListener;
import net.jini.lookup.JoinManager;
import net.jini.lease.LeaseRenewalManager;

import java.rmi.server.*;

/***************************************************************************

MyServer -- The Jini Server Class

***************************************************************************/

public class MyServer extends UnicastRemoteObject
implements MyServerInterface, ServiceIDListener
{

public MyServer () throws RemoteException
{
super ();
}


public void serviceIDNotify (ServiceID sidIn) // ServiceIDListener
{
System.out.println ("server: received ServiceID " + sidIn);
System.out.println ("*-----------------------------------------"
+ "--------------------------------*");
}


public String sayHello () throws RemoteException // MyServiceInterface
{
System.out.println ("server: sayHello() called");
return ("Hello World from MyServer!");
}


public static void main (String[] args)
{
MyServer myServer;
Entry[] aeAttributes;
JoinManager joinmanager;

try
{
System.setSecurityManager (new RMISecurityManager ());
System.out.println ("*-----------------------------------------"
+ "--------------------------------*");

aeAttributes = new Entry[1];
aeAttributes[0] = new Name ("MyServerName");
myServer = new MyServer ();

System.out.println ("server: registering with lookup services...");
joinmanager = new JoinManager
(
myServer,
aeAttributes,
myServer,null,
new LeaseRenewalManager ()
);
System.out.println ("server: registered with lookups");
}

catch (Exception e)
{
System.out.println("main(): Exception " + e);
}
}
}


Client


import net.jini.core.entry.*;
import net.jini.core.lookup.*;
import net.jini.core.discovery.*;
import net.jini.lookup.entry.*;
import java.rmi.*;

/***************************************************************************

MyClient -- The Jini Client Class

***************************************************************************/

class MyClient
{
public static void main (String[] args)
{
Entry[] aeAttributes;
LookupLocator lookup;
ServiceRegistrar registrar;
ServiceTemplate template;
MyServerInterface myServerInterface;

try
{
System.setSecurityManager (new RMISecurityManager ());
System.out.println ("*-----------------------------------------"
+ "--------------------------------*");

lookup = new LookupLocator ("jini://localhost");
registrar = lookup.getRegistrar ();
System.out.println ("client: got proxy1 to Lookup ["
+ registrar.getClass().getName() + "]");

aeAttributes = new Entry[1];
aeAttributes[0] = new Name ("MyServerName");
template = new ServiceTemplate (null, null, aeAttributes);
myServerInterface = (MyServerInterface) registrar.lookup (template);
System.out.println ("client: got proxy2 to MyServer ["
+ myServerInterface.getClass().getName() + "]");

if (myServerInterface instanceof MyServerInterface)
{
System.out.println
(
"client: called proxy2.sayHello() ---->"
+ myServerInterface.sayHello () + "<----"
);
}
System.out.println ("*-----------------------------------------"
+ "--------------------------------*\n");
}

catch (Exception e)
{
System.out.println ("main(): " + e);
}
}
}
 
Edward Harned
Ranch Hand
Posts: 291
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't send you files on this forum. What I can do is point you to an open source product that contains the code you want.

Tymeac is a general purpose back end server that has a wide range of servers including Jini.

Download the source and use it as you wish.

http://sourceforge.net/projects/tymeacse/
 
chetan raj
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Edward for you suggestions and for the link.
The link which you have send is not much helpful to me.
But can you send me few links where i can find few jini working examples.
and also site where i can get free jini e-books for downloads.
 
Edward Harned
Ranch Hand
Posts: 291
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you deem the link to pre-written code unuseful, I can only assume you want someone to spoon feed you with code specifically written for your application.

Perhaps you should hire an independent consultant to write the code for you.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
chetan,

Have you checked out jini.org or Jan Newmarch's Guide to Jini Technologies, yet?

Edward,

Be nice...
 
Edward Harned
Ranch Hand
Posts: 291
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I'll be nice.
 
chetan raj
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai Nathan,
thanks for the link. I am just a beggining for the jini i was looking for
some very simple examples of jini to start with.
ok thanks to you and also to Edward.
 
reply
    Bookmark Topic Watch Topic
  • New Topic