Exemplu de aglet ( v. alpha 4c)import aglet.*; import java.net.URL; import java.net.MalformedURLException; import java.io.IOException; public class MyAglet extends Aglet{ private URL urlHome = null; private boolean bHome = true, bSlay = false; public void onCreation(Object init){ System.out.println("MyAglet : - I've been created..."); try{ urlHome = getAgletContext().getHostingURL(); }catch(InvalidAgletException invAgEx){ System.out.println("MyAglet : - Cannot get my hosting URL."); } } public void run(){ if(bHome == true){ System.out.println("MyAglet : - I am at home..."); try{ if(bSlay == false) dispatch(new URL("atp://jagger .agora.ro")); }catch(MalformedULRException malURLEx){ }catch(IOException ioEx){ }catch(AgletException agEx){ } try{ if(bSlay == true) dispose(); }catch(InvalidAgletException invAgEx){ System.out.println("MyAglet : - Cannot kill myself !"); } } if(bHome == false){ System.out.println("MyAglet : - I'm waiting for the message HOT_NEWS ..."); } } public void onArrival(){ System.out.println("MyAglet : - I've just come from a remote host "); bHome = !bHome; } public boolean handleMessage(Message msg){ if("HOT_NEWS".equals(msg.kind)){ try{ dispatch(urlHome); }catch(MalformedURLException malURLEx){ }catch(IOException ioEx){ }catch(InvalidAgletException invAgEx){ } return true; } return false; } } Agenți mobiliBYTE România - august 1997
(C) Copyright Computer Press Agora |