Writing /home/webuser/www.agentscape.org/agentscape-wiki/data/cache/0/0dd4f1b1dd5493e6a492d5fae63fa624.i failed
Unable to save cache file. Hint: disk full; file permissions; safe_mode setting.
Writing /home/webuser/www.agentscape.org/agentscape-wiki/data/cache/0/0dd4f1b1dd5493e6a492d5fae63fa624.xhtml failed

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

development:programmatic_startup [2013/01/31 12:04]
reinier
development:programmatic_startup [2013/02/01 15:11] (current)
reinier
Line 64: Line 64:
 // for now we convert the document to an inputstream // for now we convert the document to an inputstream
 hbs.startHost(new ByteArrayInputStream(doc.toString().getBytes()), "host1"); hbs.startHost(new ByteArrayInputStream(doc.toString().getBytes()), "host1");
 +</code>
 +
 +===== Waiting for startup to finish =====
 +
 +After the bootstrapper was requested to start the host, the host will be started in its own thread. This may take a while to complete. To make sure that the host was completely started, you could use the following snippet (it will be part of the HostBootstrapper once 2.0-m5 is released):
 +
 +<code java>
 +boolean isStartupComplete (HostBootstrapper hb) throws Exception
 +{
 + // this one should return the host ID of the instance that was started
 +
 + SystemServiceInfo hostInfo = hb.getHostManager();
 + SystemServiceConfig hostConfig = hostInfo.getConfig();
 + AgentScapeID hostId = hostConfig.getServiceId();
 + AgentScapeID locId = hostConfig.getLocationId();
 +
 + // connect to the local API
 +
 + AgentScapeApi api = AgentScapeClient.getAgentScapeClient(hostId);
 + if (api == null)
 + {
 + System.err.println ("Could not obtain API");
 + }
 + try
 + {
 + List<AgentScapeID> locations = api.listLocations();
 +
 + if (locations == null || !locations.contains(locId))
 + {
 + throw new Exception("Cannot find location " + locId +
 + " in list " + locations);
 + }
 + }
 + catch (RemoteException e)
 + {
 + throw new Exception("Unable to list locations", e);
 + }
 +
 + // the location is up
 + // check if the host is alive as well
 +
 + LookupCache lc = hostInfo.getContext().getLookupCache();
 + LocationManager lm = null;
 +
 + // note: we must loop for a number of times
 +
 + try
 + {
 + lm = lc.getLocationManager(locId);
 +
 + boolean found = false;
 + long startTime = System.currentTimeMillis();
 +
 + while (!found)
 + {
 + int RETRIES = 10;  // times
 + int DELAY = 500;  // in ms
 +
 + for (int i = 0; i < RETRIES && !found; i++)
 + {
 + Set<AgentScapeID> hosts = lm.list_hosts().keySet();
 + if (hosts.contains(hostId))
 + {
 + found = true;
 + break;
 + }
 + else
 + {
 + try
 + {
 + Thread.sleep(DELAY);
 + }
 + catch (InterruptedException e)
 + {
 + // ignore
 + }
 + }
 + }
 +
 + if (!found)
 + {
 + long endTime = System.currentTimeMillis();
 + double timeSec = (endTime - startTime) / 1000.0;
 + System.err.println(String.format("Waited for more than %.1f sec for host to boot", timeSec));
 + return false;
 + }
 + }
 +
 + long endTime = System.currentTimeMillis();
 + double timeSec = (endTime - startTime) / 1000.0;
 + System.err.println(String.format("Host startup in %.1f sec", timeSec));
 + return true;
 + }
 + catch (LocationUnknownException e)
 + {
 + throw new StartupException("Unable to query location manager", e);
 + }
 + finally
 + {
 + lc.releaseSystemService(lm);
 + }
 +}
 </code> </code>
development/programmatic_startup.txt ยท Last modified: 2013/02/01 15:11 by reinier
[unknown link type]Back to top