(with apologies to Johnny Depp, but a nod to International Talk Like a Pirate Day (which happens during Fall semester, but we can celebrate any time we like))

CS262 Problem 3: Mobile code of the Caribbean

Arr, me hearties, tis time to go on a treasure hunt. There be all sorts of booty to be had in this here network, and your assignment is to find it all.

You'll be buildin' yer own treasure sites; the name of these sites should be a secret; yea will be getting private instructions from Cap'n Waldo or first matey Ian as to what to call your site real soon. In each o' these sites yea will be storin' a treasure in a local treasure chest. What treasure be in the stash is up to you; make it something good. Yea should make this magic treasure; when someone scurvy knave takes the treasure out o' a chest, there still be plenty for the next cur (though it don't need to be the same).

These sites be places where the treasure-huntin ships o yer comrades can go to find the goods. You will also be makin' your own ship, and sendin' it out to collect treasure. Your ships have to go to the treasure, it won't be coming to them. Be careful about finding the places where treasure may be; not every land listed in an RMI registry be a place where ships can go.

Yea should also beware--not all places that an ship can go be friendly. Some places look like there should be treasure there, but ships what go to these places are never heard from again. Arrrr..

One very friendly place is the isle of Tortuga, where a pirate and his ship can go to deposit their treasure and enjoy their ill-got gains. There be a special treasure chest there, where yea can put your goods so that you can get your just rewards...




In other words...

For the third assignment, we will create a simple agent system. The assignment has two parts--you need to produce a service that will act as an environment for the agent, and then you will need to produce an agent (or set of agents) that goes to these sites, interact with the sites, and return to a known spot where they can dump the results of their interactions.

The agent objects are defined by the TreasureShip interface. The main method in this interface allows the agent to receive a thread of control from the environment, and a reference to an object with which the agent can interact in that environment.Notice that TreasureShip objects must be serializable--this will be the mechanism that is used to move the agent (or, perhaps more accurately, for the agent to move itself) from one place to another. Note that the implementation you give to this interface will almost certainly need to have some additional methods to allow the object to do the kinds of interaction that is needed with the various environments, to store information that is moved along with the ship from one environment to another, and to let the ship both make sure that it gets to all of the sites and that it gets back to the final site safely.

The other method for the TreasureShip returns a name for the agent, which should be the email name of the person on whose behalf the agent is working.

The local object with which the TreasureShip interacts is the treasure chest, defined by a simple interface that allows the TreasureShip to extract a copy of the treasure from the chest. You will need to implement your own local version of the treasure chest, and decide what kind of treasure it will contain and hand out.

The place where TreasureShip meets treasure chest is defined by the interface TreasureSite. By calling the method dockShip a TreasureShip gets moved into the site; once there the ship can expect having its startShip method called. Note that each Treasure site object should be capable of being shut down; please let me do this rather than shutting down a site after you have visited.

While the interaction between the TreasureSite, the TreasureShip, and the TreasureChest is fairly straightforward, you are going to have to build up an itinerary for your ship; that is, you need to set up some way for the ship to get to all of the TreasureSites available on the network. They will all be named, but you don't know the names (since I'll send the name you should use for your site in individual mail; please don't collude and share these names). Instead, you will have to discover which of the sets of named services running on the cs262 machines actually supports the TreasureSite interface, and then set up a way of moving from one to the other with your ship or sets of ships.

To make things somewhat more interesting, I will also be placing some TreasureSite objects in the network. Some of these will contain treasure that will be freely given out; others will quietly eat your ship, making sure that any ship that goes to that site is never heard from again. So you will need to build some kind of resilience mechanism into your system. Do not assume that the rogue sites will be so kind as to throw an exception or otherwise inform you that they have eaten your ship...this is piracy, after all.

Your ship should end its treasure hunt at the TreasureSite called Tortuga. This is a special site with a special kind of treasure chest that implements the TreasureRepository interface. This is a subtype of the TreasureChest interface, but you should not try to take treasure from this chest (Arr, have yea no honor with your brother pirates?) but instead use this as a place to store the treasure that you have found. What you want to do with this treasure chest is use the fillChest method. You fill the chest by providing your name (use your email id, as usual) and the name of the place where you got the treasure and the treasure you found there. It is from this repository that I will do my grading; I'll go to the repository after you have run your ships and see what treasure you picked up, and where.

Groups

As with the other assignments, you can feel free to work in groups. However, each member of the group will need to set up their own treasure site, and each person will need to deposit their own treasure in the repository in Tortuga. How you go about doing this is up to you.

Timing

You should have your own treasure site up and running by April 27; at this time I will start running an agent that will go to the various sites and collect treasure. Once all of your sites have been checked they should remain running for the rest of the problem period.

On April 29 I will bring down the Tortuga site and start a fresh one. All deposits into accounts prior to that will be gone. At that point, I will start looking for real deposits that will get graded.

On Monday, May 5, I will start looking at the Tortuga repository to see what agents have found there. You should be done with everything (site, ship, etc.) by then.

Good luck, and have fun.

Hints

You are probably going to want to use the Java instanceof operator to find all of the places to search for treasure. It can be your friend. So can the Naming.list method.

Having a home base can make your life a lot easier. This is a place where you can create your ship or ships, decide on where you are going to send them, and be a place that they can return. If you want to get fancy, it can even be a place to which ships communicate while they are out on their journeys. The interface for this place doesn't have to be shared; your ship can know about the particular interface that characterizes from whence it came, so you can roll your own without worrying about anyone else having the same interface for their home base.

Remember that there are going to be times when your ship disappears. You don't want to lose all the treasure collected up until that time, and you probably want to remember where it was that ships disappeared so that you can be sure not to send a ship there again. Figuring out how (and where) to obtain and store this information is part of the overall problem.


Jim Waldo
Last modified: Tues Apr 8 2008