1 /*
2 * Created on Sep 22, 2003
3 * Copyright (c) 2003. All rights reserved.
4 */
5 package portaview.server;
6
7 import java.net.InetAddress;
8
9 import org.apache.xmlrpc.WebServer;
10
11 import portaview.model.AlbumCollection;
12 import portaview.model.PortaViewCollection;
13
14 /***
15 * A server that runs on the remote box that listens to the
16 * display call from the source.
17 *
18 * @author <a href="mailto:wwlee1@uiuc.edu">William Lee</a>
19 * @version $Id: PortaViewServer.java,v 1.9 2003/12/10 06:18:57 wlee Exp $
20 */
21 public class PortaViewServer
22 {
23
24 private WebServer xmlRpcServer = null;
25 private String name = null;
26 private PortaViewUpdateRunner updateRunner = null;
27 private SlideRunner slideRunner = null;
28 public static String XRPC_PROTO = "http";
29
30 /***
31 * List of portaviews. The slave server only contains one, but the master one
32 * should contains multiple of these.
33 */
34 private PortaViewCollection registeredPortaViews =
35 new PortaViewCollection();
36 private AlbumCollection albums = new AlbumCollection();
37
38 /***
39 * Repository, the central place that stores all the album.
40 */
41 private Repository repository = null;
42 private String masterName = null;
43 private InetAddress masterIP = null;
44 private InetAddress hostIP = null;
45
46 /***
47 * Starts the XML-RPC server, the update runnder, and slide runner.
48 * @throws Exception if starting fails.
49 */
50 public synchronized void start() throws Exception
51 {
52 xmlRpcServer.start();
53 updateRunner.start();
54 slideRunner.start();
55 }
56
57 /***
58 * Shuts down all servers.
59 */
60 public synchronized void shutdown()
61 {
62 slideRunner.shutdown();
63 updateRunner.shutdown();
64 xmlRpcServer.shutdown();
65 }
66
67 /***
68 * Constructs the an instance of the viewerserver
69 */
70 public PortaViewServer(
71 String name,
72 InetAddress hostIP,
73 InetAddress masterIP,
74 Repository rep,
75 int port)
76 {
77 xmlRpcServer = new WebServer(port, hostIP);
78 updateRunner = new PortaViewUpdateRunner();
79 slideRunner = new SlideRunner();
80 this.repository = rep;
81 this.hostIP = hostIP;
82 this.name = name;
83 this.masterName = name;
84 this.masterIP = masterIP;
85 init();
86 }
87
88 /***
89 * Initialize this server.
90 */
91 private synchronized void init()
92 {
93 PortaViewCommands cmd = new PortaViewCommands(this);
94 xmlRpcServer.addHandler("main", cmd);
95 }
96
97 /***
98 * @return the name of this server/PortaView.
99 */
100 public synchronized String getName()
101 {
102 return name;
103 }
104
105 /***
106 * Sets the name of this PortaView.
107 * @param name name of PortaView.
108 */
109 public synchronized void setName(String name)
110 {
111 this.name = name;
112 }
113
114 /***
115 * @return the master's name.
116 */
117 public synchronized String getMasterName()
118 {
119 return masterName;
120 }
121
122 /***
123 * Sets the master's name.
124 * @param masterName master's name.
125 */
126 public synchronized void setMasterName(String masterName)
127 {
128 this.masterName = masterName;
129 }
130
131 /***
132 * @return the master's IP address.
133 */
134 public synchronized InetAddress getMasterIP()
135 {
136 return masterIP;
137 }
138
139 /***
140 * Sets the master's IP address.
141 * @param masterIP
142 */
143 public synchronized void setMasterIP(InetAddress masterIP)
144 {
145 this.masterIP = masterIP;
146 }
147
148 /***
149 * @return the IP address for this server.
150 */
151 public synchronized InetAddress getInetAddress()
152 {
153 return hostIP;
154 }
155
156 /***
157 * Sets the IP address for this server.
158 * @param inetAddress IP address.
159 */
160 public synchronized void setInetAddress(InetAddress inetAddress)
161 {
162 this.hostIP = inetAddress;
163 }
164
165 /***
166 * @return the repository of photos (on disk).
167 */
168 public synchronized Repository getRepository()
169 {
170 return repository;
171 }
172
173 /***
174 * Sets the repository of photos (on disk).
175 * @param repository repository for photos.
176 */
177 public synchronized void setRepository(Repository repository)
178 {
179 this.repository = repository;
180 }
181
182 /***
183 * @return the collection of registered PortaViews.
184 */
185 public PortaViewCollection getRegisteredPortaViews()
186 {
187 return registeredPortaViews;
188 }
189
190 /***
191 * Replace the collection of registered PortaViews with a new collection.
192 * @param collection the collection of PortaViews to set to.
193 */
194 public void setRegisteredPortaViews(PortaViewCollection collection)
195 {
196 // since we want to save the observer, we clear the list and add the collection.
197 registeredPortaViews.clear();
198 registeredPortaViews.addAll(collection);
199 }
200
201 /***
202 * @return the collection of albums.
203 */
204 public AlbumCollection getAlbums()
205 {
206 return albums;
207 }
208
209 /***
210 * Sets the collection of albums.
211 * @param collection collection of albums.
212 */
213 public void setAlbums(AlbumCollection collection)
214 {
215 // since we want to save the observer, we clear the list and add the collection.
216 albums.clear();
217 albums.addAll(collection);
218 }
219
220 }
This page was automatically generated by Maven