Java Reference
In-Depth Information
37. InetAddress.getLocalHost().getHostName(),
38. CALLBACK_CLIENT_SERVICE_NAME);
39. }
40. projectAvailable = false;
41. }
42. catch (RemoteException exc){}
43. catch (NotBoundException exc){}
44. catch (MalformedURLException exc){}
45. catch (UnknownHostException exc){}
46. }
47.
48. public Project getProject(){ return requestedProject; }
49. public boolean isProjectAvailable(){ return projectAvailable; }
50. }
The basic sequence of action is as follows. When a client requires a project, the CallbackClientImpl object
calls the method getProject on the CallbackServerImpl object. The CallbackServerImpl creates a
CallbackServerWorkThread object to retrieve the project. When the CallbackServerWorkThread completes its
task, it calls the client method receiveProject , sending the Project instance to the requester, the
CallbackClientImpl object.
In this example, the interface ProjectItem and the classes Project and Task are used to represent the project
resource to be retrieved by the client.
Example A.232 Project.java
1. import java.util.ArrayList;
2. public class Project implements ProjectItem{
3. private String name;
4. private String description;
5. private ArrayList projectItems = new ArrayList();
6.
7. public Project(){ }
8. public Project(String newName, String newDescription){
9. name = newName;
10. description = newDescription;
11. }
12.
13. public String getName(){ return name; }
14. public String getDescription(){ return description; }
15. public ArrayList getProjectItems(){ return projectItems; }
16.
17. public void setName(String newName){ name = newName; }
18. public void setDescription(String newDescription){ description = newDescription; }
19.
20. public void addProjectItem(ProjectItem element){
21. if (!projectItems.contains(element)){
22. projectItems.add(element);
23. }
24. }
25.
26. public void removeProjectItem(ProjectItem element){
27. projectItems.remove(element);
28. }
29.
30. public String toString(){ return name + ", " + description; }
31. }
Example A.233 ProjectItem.java
1. import java.io.Serializable;
2. import java.util.ArrayList;
3. public interface ProjectItem extends Serializable{
4. public ArrayList getProjectItems();
5. }
Example A.234 Task.java
1. import java.util.ArrayList;
2. public class Task implements ProjectItem{
3. private String name;
4. private ArrayList projectItems = new ArrayList();
5. private double timeRequired;
6.
7. public Task(){ }
8. public Task(String newName, double newTimeRequired){
Search WWH ::




Custom Search