jtulach@292
|
1 |
package org.apidesign.aserverinfo.factories;
|
jtulach@292
|
2 |
|
jtulach@292
|
3 |
import org.apidesign.aserverinfo.spi.ShutdownHandler;
|
jtulach@292
|
4 |
import java.net.URL;
|
jtulach@292
|
5 |
import org.apidesign.aserverinfo.spi.NameProvider;
|
jtulach@292
|
6 |
import org.apidesign.aserverinfo.spi.ResetHandler;
|
jtulach@292
|
7 |
import org.apidesign.aserverinfo.spi.URLProvider;
|
jtulach@292
|
8 |
|
jtulach@292
|
9 |
/** A class to connect to server, identify it and manipulate with
|
jtulach@292
|
10 |
* it state. The <a href="http://apidesign.org">Practical API Design</a>
|
jtulach@292
|
11 |
* book used to call it AServerInfo.
|
jtulach@292
|
12 |
* <p>
|
jtulach@292
|
13 |
*/
|
jtulach@292
|
14 |
public final class ServerConnector {
|
jtulach@292
|
15 |
public String getName() {
|
jtulach@292
|
16 |
return name == null ? "noname" : name.getName();
|
jtulach@292
|
17 |
}
|
jtulach@292
|
18 |
|
jtulach@292
|
19 |
public URL getURL() {
|
jtulach@292
|
20 |
return url == null ? null : url.getURL();
|
jtulach@292
|
21 |
}
|
jtulach@292
|
22 |
|
jtulach@292
|
23 |
public void reset() {
|
jtulach@292
|
24 |
if (reset != null) {
|
jtulach@292
|
25 |
reset.reset();
|
jtulach@292
|
26 |
}
|
jtulach@292
|
27 |
}
|
jtulach@292
|
28 |
|
jtulach@292
|
29 |
/** Additional method for API clients not available from first version.
|
jtulach@292
|
30 |
* @since 2.0
|
jtulach@292
|
31 |
*/
|
jtulach@292
|
32 |
public void shutdown() {
|
jtulach@292
|
33 |
if (shutdown != null) {
|
jtulach@292
|
34 |
shutdown.shutdown();
|
jtulach@292
|
35 |
}
|
jtulach@292
|
36 |
}
|
jtulach@292
|
37 |
|
jtulach@292
|
38 |
//
|
jtulach@292
|
39 |
// factories
|
jtulach@292
|
40 |
//
|
jtulach@292
|
41 |
|
jtulach@292
|
42 |
// BEGIN: aserverinfo.regularcreate
|
jtulach@292
|
43 |
public static ServerConnector create(
|
jtulach@292
|
44 |
NameProvider nameProvider,
|
jtulach@292
|
45 |
URLProvider urlProvider,
|
jtulach@292
|
46 |
ResetHandler reset
|
jtulach@292
|
47 |
)
|
jtulach@292
|
48 |
// END: aserverinfo.regularcreate
|
jtulach@292
|
49 |
{
|
jtulach@292
|
50 |
return new ServerConnector(nameProvider, urlProvider, reset, null);
|
jtulach@292
|
51 |
}
|
jtulach@292
|
52 |
|
jtulach@293
|
53 |
// BEGIN: aserverinfo.regularcreate.withshutdown
|
jtulach@292
|
54 |
/** @since 2.0 */
|
jtulach@292
|
55 |
public static ServerConnector create(
|
jtulach@292
|
56 |
NameProvider nameProvider,
|
jtulach@292
|
57 |
URLProvider urlProvider,
|
jtulach@292
|
58 |
ResetHandler reset,
|
jtulach@292
|
59 |
ShutdownHandler shutdown
|
jtulach@292
|
60 |
)
|
jtulach@292
|
61 |
// END: aserverinfo.regularcreate.withshutdown
|
jtulach@292
|
62 |
{
|
jtulach@292
|
63 |
return new ServerConnector(nameProvider, urlProvider, reset, shutdown);
|
jtulach@292
|
64 |
}
|
jtulach@292
|
65 |
|
jtulach@292
|
66 |
//
|
jtulach@292
|
67 |
// private part
|
jtulach@292
|
68 |
//
|
jtulach@292
|
69 |
|
jtulach@292
|
70 |
private final NameProvider name;
|
jtulach@292
|
71 |
private final URLProvider url;
|
jtulach@292
|
72 |
private final ResetHandler reset;
|
jtulach@292
|
73 |
private final ShutdownHandler shutdown;
|
jtulach@292
|
74 |
|
jtulach@292
|
75 |
private ServerConnector(
|
jtulach@292
|
76 |
NameProvider name, URLProvider url,
|
jtulach@292
|
77 |
ResetHandler reset, ShutdownHandler shutdown
|
jtulach@292
|
78 |
) {
|
jtulach@292
|
79 |
this.name = name;
|
jtulach@292
|
80 |
this.url = url;
|
jtulach@292
|
81 |
this.reset = reset;
|
jtulach@292
|
82 |
this.shutdown = shutdown;
|
jtulach@292
|
83 |
}
|
jtulach@292
|
84 |
|
jtulach@292
|
85 |
}
|