Results 1 to 4 of 4
  1. #1
    amishera2007 is offline Member
    Join Date
    Apr 2009
    Posts
    2
    Rep Power
    0

    Default NoSuchObjectException: No such object in table

    Hi,
    I have written this simple client server application using RMI.

    Server
    Java Code:
    import java.io.FileInputStream;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.rmi.registry.Registry;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.NotBoundException;
    import java.rmi.RemoteException;
    import java.rmi.server.UnicastRemoteObject;
    import java.util.Date;
    import java.util.Iterator;
    import java.util.Properties;
    	
    public class Server {
    	private static final long WAIT_TIME = 3000;
    	static String regServerHost;
    	static int regServerPort;
    	static FileWriter fWriter;
    	static String hostId;
    	static TransactionManager manager;
    	
    	static void init() {
    		try {
    			fWriter = new FileWriter("server-"+hostId+".log");
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    	}
    	
        private static void registerRemoteObject() {
            Registry registry;
        	
    	    // Bind the remote object's stub in the registry
    		try {
    			log("Server: regserverport "+regServerPort);
    			log("Server: remote object name "+Globals.remoteObjectName);
    			
    			manager = new TransactionManagerImpl(hostId);
    			// manager = (TransactionManager) UnicastRemoteObject.exportObject(new TransactionManagerImpl(hostId), 0);
    			registry = LocateRegistry.getRegistry(regServerPort);
    			registry.rebind(Globals.remoteObjectName, manager);
    			
    			log("server: bound complete");
    		} catch (RemoteException e) {
    			log("server: exception");
    			e.printStackTrace();
    		} catch (Exception e) {
    			log("server: exception");
    			e.printStackTrace();
    		}
        }
        
        private static boolean lookupobj() {
        	Registry registry;
        	TransactionManager manager = null;
        	try {
    			registry = LocateRegistry.getRegistry(regServerPort);
    			manager = (TransactionManager) registry.lookup(Globals.remoteObjectName);
    		} catch (RemoteException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		} catch (NotBoundException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		if (manager == null)
    			return false;
    		return true;
        }
        
        private static void startServer() {	
    		try {
    		    registerRemoteObject();
    		    log("successfully registered remote object");
    		    int counter = 0;		    
    		    while (counter < Globals.numberOfNodes) {
    		    	synchronized(Globals.threadsSet) {
    		    		Globals.threadsSet.add(Thread.currentThread());
    		    	}
    		    	try {
    		    		Thread.sleep(WAIT_TIME);
    		    	} catch (Exception e) {}
    		    	
    		    	synchronized(Globals.accessCount) {
    		    		counter = Globals.accessCount;
    		    	}
    //		    	log(Globals.remoteObjectName+" " +lookupobj());
    		    }
    		    //Utils.writeToServerLogFile(Globals.serverLogFile);
    		} catch (Exception e) {
    		    System.err.println("Server exception: " + e.toString());
    		    e.printStackTrace();
    		}
        }
        
    	public static void main(String args[]) {
    		hostId = args[0];
    		regServerHost = args[2];
        	regServerPort = Integer.parseInt(args[1]);
    
        	init();
        	
        	loadSystemProperties();
        	
        	log(hostId+" started itself ");
        	
    		startServer();
    	}
    
    	private static void loadSystemProperties() {
    		Properties properties = new Properties();
    		
    	    try {
    	        properties.load(new FileInputStream("system.properties"));
    	    } catch (IOException e) {
    	    }
    	    
    	    Globals.serverLogFile = properties.getProperty("serverLogFile");
    	    Globals.remoteObjectName = properties.getProperty("remoteObjectName");
    	    Globals.numberOfNodes = Integer.parseInt(properties.getProperty("numberOfNodes"));
    	}
    	
    	private static void log(String msg) {
        	try {
        		System.out.println(new Date()+" "+msg);
    			fWriter.write(msg+"\n");
    			fWriter.flush();
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
        }
    }
    Client
    Java Code:
    import java.io.FileInputStream;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.registry.Registry;
    import java.util.Properties;
    import java.util.Random;
    
    public class Client {
    	private static int numberOfRuns = 1;
    	private static String remoteObjectName;
    	private static FileWriter fWriter;
    	private static String hostId;
    	
    	static void init() {
    		try {
    			fWriter = new FileWriter("client-"+hostId+".log");
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    	}
    
        public static void main(String[] args) {
    		String host = args[2];
    		int serverPort = Integer.parseInt(args[1]);
    		hostId = args[0];
    		Globals.hostId = hostId;
    		
    		init();
    		
    		host = "sun114-12.cise.ufl.edu";
    		
    		log("host is "+host);
    		log("client "+hostId+" started");
    		loadSystemProperties();
    		Transaction ts = new Transaction(host, serverPort, remoteObjectName);
    
    		try {
    			int st = Utils.getInitialSleepTime();
    			Thread.sleep(st);
    			
    			int i;
    			log(ts.sayHello());
    			
    		} catch (Exception e) {
    		    System.err.println("Client exception: " + e.toString());
    		    e.printStackTrace();
    		}
        }
        
        private static void log(String output) {
        	System.out.println("Client: "+output);
        }
        
        private static int getInteger() {
        	Random ran = new Random();
    		int rNum = 1 + ran.nextInt(1000); 
    		return rNum;
        }
        
        private static void loadSystemProperties() {
    		Properties properties = new Properties();
    		
    	    try {
    	        properties.load(new FileInputStream("system.properties"));
    	    } catch (IOException e) {
    	    }
    	    
    	    numberOfRuns = Integer.parseInt(properties.getProperty("numberOfRuns"));
    	    remoteObjectName = properties.getProperty("remoteObjectName");
    	    Globals.numberOfNodes = Integer.parseInt(properties.getProperty("numberOfNodes"));
    	    Globals.remoteHosts = new String[Globals.numberOfNodes];
    	    
    	    for (int i = 1;i <= Globals.numberOfNodes;i++) {
    	    	Globals.remoteHosts[i-1] = properties.getProperty("node"+i);
    	    }
    	}
    }
    
    [U]Transaction[/U]
    
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.rmi.NotBoundException;
    import java.rmi.RemoteException;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.registry.Registry;
    
    public class Transaction {
    	TransactionManager manager;
    	String remoteObjectName;
    	PrintWriter fWriter;
    	
    	private void lookupRemoteObject(int i, int serverPort) {
    		Registry registry;
    		boolean flag = false;
    
    		String host = Globals.remoteHosts[i];
    		System.out.println("host is "+host);
    		while (!flag) {
    			try {
    				registry = LocateRegistry.getRegistry(host, serverPort);
    				manager = (TransactionManager) registry.lookup(remoteObjectName);
    				if (manager != null) {
    					flag = true;
    				} else {
    					Utils.pause(3000);
    				}
    			} catch (RemoteException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace(fWriter);
    				//fWriter.flush();
    			} catch (NotBoundException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace(fWriter);
    				//fWriter.flush();
    			} catch (Exception e) {
    				//e.printStackTrace();
    				//fWriter.flush();
    			}
    		}
    	}
    	
    	public Transaction(String host, int serverPort, String remoteObjectName) {
    		try {
    			fWriter = new PrintWriter("transaction-"+Globals.hostId+".log");
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    
    		this.remoteObjectName = remoteObjectName;
    		int i = 1;
    		lookupRemoteObject(i, serverPort);
    	}
    	
    	/*Tuple in(Tuple inTouple) {
    		Tuple matchedTuple = null;
    		
    	    try {
    			matchedTuple = manager.getTuple(inTouple);
    		} catch (RemoteException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		
    		return matchedTuple;
    	}*/
    	
    	/* Tuple out(Tuple t) {
    		Tuple outTuple = new Tuple("",null);
    		try {
    			System.out.println("calling tuplemanager");
    			// String name = manager.putTuple(t);
    			System.out.println("put tuple returned ");
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    		
    		return outTuple;
    	} */
    	
    	/*Tuple out(Tuple t) throws RemoteException {
    		return manager.putTuple(t);
    	}
    	
    	Tuple in(Tuple t) throws RemoteException {
    		return manager.getTuple(t);
    	}*/
    	
    	public String sayHello() {
    		try {
    			return manager.sayHello();
    		} catch (RemoteException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace(fWriter);
    			fWriter.flush();
    		}
    		return "";
    	}
    	
    	public void acquireLock() {
    		try {
    			manager.acquireLock();
    		} catch (RemoteException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    	}
    }
    After registering the remote object the server shows

    "Successfully registered remote object"

    But when the client executes ts.sayHello() the following exception is shwon:
    NoSuchObjectException: No Such Object in Table.

    This is driving me crazy because there is obviously no reason for this. And I am at a loss how to debug and find out the problem.

    Please help me with this.
    Last edited by amishera2007; 04-07-2009 at 01:51 AM.

  2. #2
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    10

    Default

    "Successfully registered remote object" print when your server is starting, which seems not a good indicator for client connect to server...

  3. #3
    Join Date
    Apr 2009
    Posts
    1
    Rep Power
    0

    Default Send mail without SMTP Server/Protocal

    How can i send mail without using SMTP protocal can anyone send me code or way i can do ..

    thanks

    vikram

  4. #4
    amishera2007 is offline Member
    Join Date
    Apr 2009
    Posts
    2
    Rep Power
    0

    Default

    I put an additional line here:

    Java Code:
    try {
    
    			log("Server: regserverport "+regServerPort);
    
    			log("Server: remote object name "+Globals.remoteObjectName);
    
    			TransactionManager manager = (TransactionManager) UnicastRemoteObject.exportObject(new TransactionManagerImpl(hostId), 0);
    
    			registry = LocateRegistry.getRegistry(regServerPort);
    
    			registry.rebind(Globals.remoteObjectName, manager);
    
    			[B]log("successfully bound object");[/B]
    
    		} catch (RemoteException e) {
    
    			// TODO Auto-generated catch block
    
    			e.printStackTrace();
    
    		}
    So now either the binding is successful or there should be some error message but the server outputs:

    successfully bound object

    So now what to do? how can I know whether the object is bound properly at the server?

Similar Threads

  1. Replies: 2
    Last Post: 11-26-2010, 03:12 AM
  2. Add filter like MSExcel to SWT table object.
    By nitinkrgoyal in forum SWT / JFace
    Replies: 0
    Last Post: 03-20-2009, 10:57 AM
  3. Replies: 1
    Last Post: 03-04-2009, 07:14 PM
  4. Replies: 1
    Last Post: 07-22-2008, 05:27 PM
  5. Creating object of Type Object class
    By venkatv in forum New To Java
    Replies: 3
    Last Post: 07-17-2007, 04:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •