/** * Create a df component description. * @param component The component. * @param service The service. * @return The df component description. */ public IDFComponentDescription createDFComponentDescription(IComponentIdentifier component, IDFServiceDescription service) { DFComponentDescription ret = new DFComponentDescription(); ret.setName(component); if(service!=null) ret.addService(service); return ret; }
/** * Create a df component description. * @param component The component. * @param service The service. * @return The df component description. */ public IDFComponentDescription createDFComponentDescription(IComponentIdentifier component, IDFServiceDescription service) { DFComponentDescription ret = new DFComponentDescription(); ret.setName(component); if(service!=null) ret.addService(service); return ret; }
/** * Create a df component description. * @param component The component. * @param service The service. * @return The df component description. */ public IDFComponentDescription createDFComponentDescription(IComponentIdentifier component, IDFServiceDescription service) { DFComponentDescription ret = new DFComponentDescription(); ret.setName(component); if(service!=null) ret.addService(service); return ret; }
/** * Refresh the view. */ protected void refresh() { // df.search(df.createDFComponentDescription(null, null), null).addResultListener(new SwingDefaultResultListener(this) df.search(new DFComponentDescription(null), null, remotecb.isSelected()).addResultListener(new SwingDefaultResultListener(this) { public void customResultAvailable(Object result) { IDFComponentDescription[] ads = (IDFComponentDescription[])result; // System.out.println("Found: "+SUtil.arrayToString(ads)); if(old_ads == null || !Arrays.equals(old_ads, ads)) { component_table.setComponentDescriptions(ads); updateServices(ads); updateDetailedService(); old_ads = ads; } } }); }
/** * Refresh the view. */ protected void refresh() { // df.search(df.createDFComponentDescription(null, null), null).addResultListener(new SwingDefaultResultListener(this) df.search(new DFComponentDescription(null), null, remotecb.isSelected()).addResultListener(new SwingDefaultResultListener(this) { public void customResultAvailable(Object result) { IDFComponentDescription[] ads = (IDFComponentDescription[])result; // System.out.println("Found: "+SUtil.arrayToString(ads)); if(old_ads == null || !Arrays.equals(old_ads, ads)) { component_table.setComponentDescriptions(ads); updateServices(ads); updateDetailedService(); old_ads = ads; } } }); }
/** * Create a df component description. * @param component The component. * @param service The service. * @return The df component description. */ public IDFComponentDescription createDFComponentDescription(IComponentIdentifier component, IDFServiceDescription service, long leasetime) { DFComponentDescription ret = new DFComponentDescription(); ret.setName(component); if(service!=null) ret.addService(service); ret.setLeaseTime(new Date(clockservice.getTime()+leasetime)); return ret; }
/** * First the player searches a dealer, then sends a join-request to this * dealer. */ public void body() { //System.out.println("Searching dealer..."); // Create a service description to search for. IDF df = (IDF)SServiceProvider.getService(getAgent(), IDF.class, RequiredServiceInfo.SCOPE_PLATFORM).get(); IDFServiceDescription sd = new DFServiceDescription(null, "blackjack", null); IDFComponentDescription ad = new DFComponentDescription(null, sd); ISearchConstraints sc = new SearchConstraints(-1, 0); IDFComponentDescription[] result = df.search(ad, sc).get(); if(result==null || result.length==0) { getLogger().warning("No blackjack-dealer found."); fail(); } else { // at least one matching description found, getLogger().info(result.length + " blackjack-dealer found"); // choose one dealer randomly out of all the dealer-agents IComponentIdentifier dealer = result[new Random().nextInt(result.length)].getName(); getBeliefbase().getBelief("dealer").setFact(dealer); } }
/** * Create a new df component description. * @param component The component id. * @param services The services. * @param languages The languages. * @param ontologies The ontologies. * @param protocols The protocols. * @return The component description. */ public IDFComponentDescription createDFComponentDescription(IComponentIdentifier component, IDFServiceDescription[] services, String[] languages, String[] ontologies, String[] protocols, Date leasetime) { DFComponentDescription ret = new DFComponentDescription(); ret.setName(component); ret.setLeaseTime(leasetime); for(int i=0; services!=null && i<services.length; i++) ret.addService(services[i]); for(int i=0; languages!=null && i<languages.length; i++) ret.addLanguage(languages[i]); for(int i=0; ontologies!=null && i<ontologies.length; i++) ret.addOntology(ontologies[i]); for(int i=0; protocols!=null && i<protocols.length; i++) ret.addProtocol(protocols[i]); return ret; }
/** * Test registering. */ protected int testRegister(int num, IDF df, Date lt) { // Try to register by the df TestReport tr = new TestReport("#"+num++, lt!=null ? "Test register with lease time." : "Test register."); getLogger().info(tr.getDescription()); try { df.register(new DFComponentDescription(getAgent().getComponentIdentifier(), SERVICES, null, null, null, lt)).get(); getLogger().info(" register ok."); tr.setSucceeded(true); } catch(GoalFailureException gfe) { getLogger().info(" register failed: "+gfe); tr.setFailed(gfe); } getBeliefbase().getBeliefSet("testcap.reports").addFact(tr); return num; }
/** * Test deregistering. */ protected int testDeregister(int num, IDF df) { // Try to deregister by the df TestReport tr = new TestReport("#"+num++, "Test deregister."); getLogger().info(tr.getDescription()); try { df.deregister(new DFComponentDescription(getAgent().getComponentIdentifier())).get(); getLogger().info(" deregister ok."); tr.setSucceeded(true); } catch(GoalFailureException gfe) { getLogger().info(" deregister failed: "+gfe); tr.setFailed(gfe); } getBeliefbase().getBeliefSet("testcap.reports").addFact(tr); return num; } }
/** * Search the environent agent and store its AID in the beliefbase. */ protected void searchEnvironmentAgent() { try { IDF df = (IDF)SServiceProvider.getService(getAgent(), IDF.class, RequiredServiceInfo.SCOPE_PLATFORM).get(); IDFServiceDescription sd = new DFServiceDescription(null, "dispatch vision", null); IDFComponentDescription ad = new DFComponentDescription(null, sd); IDFComponentDescription[] tas = df.search(ad, null).get(); if(tas.length!=0) { getBeliefbase().getBelief("environmentagent").setFact(tas[0].getName()); if(tas.length>1) System.out.println("WARNING: more than environment agent found."); } } catch(GoalFailureException gfe) { getLogger().warning("DF search failed: "+gfe); } } }
/** * Create a new df component description. * @param component The component id. * @param services The services. * @param languages The languages. * @param ontologies The ontologies. * @param protocols The protocols. * @return The component description. */ public IDFComponentDescription createDFComponentDescription(IComponentIdentifier component, IDFServiceDescription[] services, String[] languages, String[] ontologies, String[] protocols, Date leasetime) { DFComponentDescription ret = new DFComponentDescription(); ret.setName(component); ret.setLeaseTime(leasetime); for(int i=0; services!=null && i<services.length; i++) ret.addService(services[i]); for(int i=0; languages!=null && i<languages.length; i++) ret.addLanguage(languages[i]); for(int i=0; ontologies!=null && i<ontologies.length; i++) ret.addOntology(ontologies[i]); for(int i=0; protocols!=null && i<protocols.length; i++) ret.addProtocol(protocols[i]); return ret; }
/** * Create a new df component description. * @param component The component id. * @param services The services. * @param languages The languages. * @param ontologies The ontologies. * @param protocols The protocols. * @return The component description. */ public IDFComponentDescription createDFComponentDescription(IComponentIdentifier component, IDFServiceDescription[] services, String[] languages, String[] ontologies, String[] protocols, Date leasetime) { DFComponentDescription ret = new DFComponentDescription(); ret.setName(component); ret.setLeaseTime(leasetime); for(int i=0; services!=null && i<services.length; i++) ret.addService(services[i]); for(int i=0; languages!=null && i<languages.length; i++) ret.addLanguage(languages[i]); for(int i=0; ontologies!=null && i<ontologies.length; i++) ret.addOntology(ontologies[i]); for(int i=0; protocols!=null && i<protocols.length; i++) ret.addProtocol(protocols[i]); return ret; }
try IDFComponentDescription[] results = df.search(new DFComponentDescription(null, SERVICES, null, null, null, null), null).get(); if(find==(results.length!=0))
/** * Search the environent agent and store its AID in the beliefbase. */ protected IComponentIdentifier searchEnvironmentAgent() { IComponentIdentifier res = (IComponentIdentifier)getBeliefbase().getBelief("environmentagent").getFact(); if(res==null) { IDF df = (IDF)SServiceProvider.getService(getAgent(), IDF.class, RequiredServiceInfo.SCOPE_PLATFORM).get(); IDFServiceDescription sd = new DFServiceDescription(null, "hunter-prey environment", null); IDFComponentDescription ad = new DFComponentDescription(null, sd); IDFComponentDescription[] tas = df.search(ad, null).get(); if(tas.length!=0) { // Found. res = tas[0].getName(); getBeliefbase().getBelief("environmentagent").setFact(res); if(tas.length>1) getLogger().warning("More than environment agent found."); } else { // Not found. throw new PlanFailureException(); } } return res; }
/** * Search the environent agent and store its AID in the beliefbase. */ protected IComponentIdentifier searchEnvironmentAgent() { IComponentIdentifier res = (IComponentIdentifier)getBeliefbase().getBelief("environmentagent").getFact(); if(res==null) { IDF df = (IDF)SServiceProvider.getService(getAgent(), IDF.class, RequiredServiceInfo.SCOPE_PLATFORM).get(); IDFServiceDescription sd = new DFServiceDescription(null, "dispatch vision", null); IDFComponentDescription ad = new DFComponentDescription(null, sd); IDFComponentDescription[] tas = df.search(ad, null).get(); if(tas.length!=0) { // Found. res = tas[0].getName(); getBeliefbase().getBelief("environmentagent").setFact(res); if(tas.length>1) getLogger().warning("More than environment agent found."); } else { // Not found. throw new PlanFailureException(); } } return res; }
IDFComponentDescription dfadesc = new DFComponentDescription(null, sd);
/** * The body method is called on the * instantiated plan instance from the scheduler. */ public void body() { IDFComponentDescription desc = (IDFComponentDescription)getParameter("description").getValue(); if(desc==null || desc.getName()==null) { desc = new DFComponentDescription(getScope().getComponentIdentifier()); } DFDeregister dre = new DFDeregister(); dre.setComponentDescription(desc); IGoal req = createGoal("rp_initiate"); req.getParameter("receiver").setValue(getParameter("df").getValue()); req.getParameter("action").setValue(dre); req.getParameter("ontology").setValue(SFipa.COMPONENT_MANAGEMENT_ONTOLOGY_NAME); dispatchSubgoalAndWait(req); } }
/** * The body method is called on the * instantiated plan instance from the scheduler. */ public void body() { DFModify mo = new DFModify(); IDFComponentDescription desc = (IDFComponentDescription)getParameter("description").getValue(); Number lt = (Number)getParameter("leasetime").getValue(); // When AID is ommited, enter self. Hack??? if(desc.getName()==null || lt!=null) { IComponentIdentifier bid = desc.getName()!=null ? desc.getName() : getScope().getComponentIdentifier(); Date leasetime = lt==null ? desc.getLeaseTime() : new Date(getTime()+lt.longValue()); desc = new DFComponentDescription(bid, desc.getServices(), desc.getProtocols(), desc.getOntologies(), desc.getLanguages(), leasetime); } mo.setComponentDescription(desc); IGoal req = createGoal("rp_initiate"); req.getParameter("receiver").setValue(getParameter("df").getValue()); req.getParameter("action").setValue(mo); req.getParameter("ontology").setValue(SFipa.COMPONENT_MANAGEMENT_ONTOLOGY_NAME); dispatchSubgoalAndWait(req); getParameter("result").setValue(((DFModify)((Done)req.getParameter("result").getValue()).getAction()).getResult()); } }
/** * The body method is called on the * instantiated plan instance from the scheduler. */ public void body() { // System.out.println("df register"); DFRegister re = new DFRegister(); IDFComponentDescription desc = (IDFComponentDescription)getParameter("description").getValue(); Number lt = (Number)getParameter("leasetime").getValue(); // When AID is omitted, enter self. Hack??? if(desc.getName()==null || lt!=null) { IComponentIdentifier bid = desc.getName()!=null ? desc.getName() : getScope().getComponentIdentifier(); Date leasetime = lt==null ? desc.getLeaseTime() : new Date(getTime()+lt.longValue()); desc = new DFComponentDescription(bid, desc.getServices(), desc.getProtocols(), desc.getOntologies(), desc.getLanguages(), leasetime); } re.setComponentDescription(desc); IGoal req = createGoal("rp_initiate"); req.getParameter("receiver").setValue(getParameter("df").getValue()); req.getParameter("action").setValue(re); req.getParameter("ontology").setValue(SFipa.COMPONENT_MANAGEMENT_ONTOLOGY_NAME); dispatchSubgoalAndWait(req); getParameter("result").setValue(((DFRegister)((Done)req.getParameter("result").getValue()).getAction()).getResult()); } }