[Aglets-users] How to specify the port no.
Status: Beta
Brought to you by:
cat4hire
From: sridevi s. <sri...@ya...> - 2008-03-28 10:38:12
|
Sir, I have a Master aglet running on port 4434 and a Slave aglet running on port 5000 on the same machine. My problem is when I send back a msg from Slave (5000) back to Master (4434), using the statement getAgletContext().getAgletProxy(getMaster()).sendMessage(msg); it is taking the path as "atp://ss/" only instead of "atp://ss:4434/" hence I am getting a NullPointer exception. How do I specify the port no in the above statement of the slave file? The contents of Master.java is package sample; import com.ibm.aglet.*; import com.ibm.agletx.patterns.*; import com.ibm.agletx.util.*; import java.net.*; import java.util.*; public class Master extends Aglet { public Vector serverPool; public void onCreation(Object init) { try { serverPool = new Vector(); serverPool.addElement(new URL("atp://ss:5000/")); Slave.create(null,"sample.slavold", getAgletContext(),this, serverPool,new String()); } catch (Exception e) {System.out.println(" Error in on create of master "); e.printStackTrace(); } } public boolean handleMessage(Message msg1) { if (msg1.sameKind("lic")) { try{int us=0; System.out.println(" In handlemsg of master "); us=((Integer)msg1.getArg("uts")).intValue(); System.out.println("units allot in Master "+us); return true; } catch(Exception e){e.printStackTrace(); System.out.println(" excep in handlemsg ");} } return false; } } Contents of Slave.java is package sample; import com.ibm.aglet.*; import com.ibm.agletx.patterns.*; import java.net.*; import java.util.*; import java.sql.*; import java.io.*; public class slavold extends Slave implements Serializable{ int units; Message msg; String databaseURL = "jdbc:odbc:qq"; transient Connection databaseConnection = null; public slavold(){ System.out.println("in slave constructor"); units=0; } public void initializeJob() { try{ units=10; System.out.println("Agent starting..in slave."); }catch(Exception e){ System.err.println("Exception caught while loading the driver "); e.printStackTrace(); } } public void doJob() { System.out.println("Running job."); try{ // connect to the database java.sql.Driver driver = (java.sql.Driver) Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance(); System.out.println("Connecting to the database [" + databaseURL+"]"); databaseConnection =DriverManager.getConnection(databaseURL,"",""); System.out.println("connected!"); // issue a query Statement st = databaseConnection.createStatement(); ResultSet rs = st.executeQuery("SELECT pts FROM emp where id='bbb'"); while(rs != null && rs.next() ) { units=rs.getInt(1); System.out.println("Units in Slave" + units ); } rs.close(); st.close(); System.out.println("comin out of dojob()"); System.out.println("going back to master"); }catch(SQLException e){ System.err.println("Exception caught while performing connection/querying.. "); e.printStackTrace(); } catch(Exception e){ System.err.println("Exception caught "); e.printStackTrace(); } } public void onReturn() { try { System.out.println("in on ret"); System.out.println("Units in onret " + units ); Message msg1 = new Message("loc"); msg1.setArg("uts", units); getAgletContext().getAgletProxy(getMaster()).sendMessage(msg1); } catch (Exception e) { System.out.println("Err in on ret"); e.printStackTrace(); } } } --------------------------------- Looking for last minute shopping deals? Find them fast with Yahoo! Search. |