2 |
|
package uk.ac.ukc.iscream.clientinterface; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
< |
import uk.ac.ukc.iscream.util.*; |
5 |
> |
import uk.ac.ukc.iscream.componentmanager.*; |
6 |
|
import uk.ac.ukc.iscream.core.*; |
7 |
+ |
import uk.ac.ukc.iscream.util.*; |
8 |
|
|
9 |
|
/** |
10 |
< |
* A ClientInterface startup class |
10 |
> |
* This class starts the real time clients |
11 |
> |
* client interface. |
12 |
> |
* This is an iscream component that sends data |
13 |
> |
* direct to clients running on desktops to provide |
14 |
> |
* real time information. |
15 |
|
* |
16 |
|
* @author $Author$ |
17 |
|
* @version $Id$ |
18 |
|
*/ |
19 |
< |
class ClientInterfaceMain { |
19 |
> |
public class ClientInterfaceMain implements Component { |
20 |
|
|
21 |
|
//---FINAL ATTRIBUTES--- |
22 |
|
|
27 |
|
|
28 |
|
//---STATIC METHODS--- |
29 |
|
|
30 |
< |
public static void main(String[] args) { |
26 |
< |
// *************************************** |
27 |
< |
// VERY TEMPORARY - will find a better way |
28 |
< |
System.setProperty("org.omg.CORBA.ORBClass","jacorb.orb.ORB"); |
29 |
< |
System.setProperty("org.omg.CORBA.ORBSingletonClass","jacorb.orb.ORBSingleton"); |
30 |
< |
// *************************************** |
30 |
> |
//---CONSTRUCTORS--- |
31 |
|
|
32 |
< |
ReferenceManager refman = ReferenceManager.init(null, null); |
32 |
> |
//---PUBLIC METHODS--- |
33 |
|
|
34 |
< |
// can't have a real toString() :) |
35 |
< |
String toString = "ClientInterface{" + refman.getName() + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
36 |
< |
|
37 |
< |
refman.getLogger().write(toString, Logger.SYSINIT, "coming up"); |
34 |
> |
/** |
35 |
> |
* This method starts the ClientInterface |
36 |
> |
*/ |
37 |
> |
public void start() throws ComponentStartException { |
38 |
> |
|
39 |
> |
_logger.write(toString(), Logger.SYSINIT, "coming up"); |
40 |
|
|
41 |
|
// configuration variables we require |
42 |
|
String ourName = null; |
43 |
|
int listenPort = 0; |
44 |
|
|
45 |
< |
Configuration config = refman.getCM().getConfiguration("ClientInterface"); |
45 |
> |
Configuration config = _refman.getCM().getConfiguration("ClientInterface"); |
46 |
|
if (config == null) { |
47 |
< |
throw new RuntimeException ("CRITICAL:Unable to obtain configuration" + |
48 |
< |
" Advise you check the i-scream log for more information."); |
49 |
< |
} else { |
47 |
> |
throw new ComponentStartException("Unable to obtain configuration for component"); |
48 |
> |
} |
49 |
> |
else { |
50 |
|
try { |
51 |
+ |
// get the configuration properties we need |
52 |
|
ourName = config.getProperty("RootFilter.realtimeInterfaceName"); |
53 |
|
listenPort = Integer.parseInt(config.getProperty("ClientInterface.listenPort")); |
54 |
|
} catch (org.omg.CORBA.MARSHAL e) { |
55 |
< |
refman.getLogger().write(toString, Logger.FATAL, "required config property not present"); |
53 |
< |
throw new RuntimeException ("CRITICAL:Unable to obtain required configuration property" + |
54 |
< |
" Advise you check the i-scream log for more information."); |
55 |
< |
|
55 |
> |
throw new ComponentStartException("Unable to obtain requried configuration property for component"); |
56 |
|
} |
57 |
|
} |
58 |
+ |
|
59 |
|
// now we have the name of the interface we set it |
60 |
< |
refman.setName(ourName); |
61 |
< |
toString = "ClientInterface{" + refman.getName() + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
62 |
< |
refman.getLogger().write(toString, Logger.SYSINIT, "configured"); |
63 |
< |
|
60 |
> |
NAME = ourName; |
61 |
> |
|
62 |
> |
_logger.write(toString(), Logger.SYSINIT, "configured"); |
63 |
> |
|
64 |
> |
// Setup a PacketSorter |
65 |
> |
PacketSorter ps = new PacketSorter(); |
66 |
> |
ps.start(); |
67 |
> |
|
68 |
|
// ClientInterfaceServant start (for inbound data) |
69 |
< |
refman.getLogger().write(toString, Logger.DEBUG, "starting servant for inbound data"); |
70 |
< |
ClientInterfaceServant ciServant = new ClientInterfaceServant(); |
71 |
< |
refman.bindToOrb(ciServant, "iscream.ClientInterface." + refman.getName()); |
69 |
> |
_logger.write(toString(), Logger.DEBUG, "starting servant for inbound data"); |
70 |
> |
ClientInterfaceServant ciServant = new ClientInterfaceServant(ps); |
71 |
> |
_refman.bindToOrb(ciServant, "iscream.ClientInterface." + ClientInterfaceMain.NAME); |
72 |
|
|
73 |
< |
ClientListener clientListener = new ClientListener(listenPort, ciServant); |
74 |
< |
clientListener.start(); |
73 |
> |
// Startup the TCPListener |
74 |
> |
TCPClientListener tcpClientListener = new TCPClientListener(listenPort, ps); |
75 |
> |
tcpClientListener.start(); |
76 |
|
|
77 |
< |
// start the POA off |
78 |
< |
// now we are running, we just need to serve |
79 |
< |
// so we ask the orb to block for us until it has finished |
80 |
< |
refman.activatePOA(); |
81 |
< |
refman.getLogger().write(toString, Logger.SYSINIT, "started"); |
82 |
< |
refman.getORB().run(); |
77 |
> |
// Startup the CORBA Listener |
78 |
> |
_logger.write(toString(), Logger.DEBUG, "starting servant for inbound clients"); |
79 |
> |
CorbaClientListenerServant corbaServant = new CorbaClientListenerServant(ps); |
80 |
> |
// !!! verify this name is correct at some point !!! |
81 |
> |
_refman.bindToOrb(corbaServant, "iscream.ClientInterface.CorbaListener"); |
82 |
> |
|
83 |
> |
_logger.write(toString(), Logger.SYSINIT, "started"); |
84 |
|
} |
85 |
|
|
86 |
< |
//---CONSTRUCTORS--- |
86 |
> |
/** |
87 |
> |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
88 |
> |
* method to provide clean logging (every class should have this). |
89 |
> |
* |
90 |
> |
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
91 |
> |
* to format the toString() |
92 |
> |
* |
93 |
> |
* @return the name of this class and its CVS revision |
94 |
> |
*/ |
95 |
> |
public String toString() { |
96 |
> |
return FormatName.getName( |
97 |
> |
NAME, |
98 |
> |
getClass().getName(), |
99 |
> |
REVISION); |
100 |
> |
} |
101 |
|
|
81 |
– |
//---PUBLIC METHODS--- |
82 |
– |
|
102 |
|
//---PRIVATE METHODS--- |
103 |
|
|
104 |
|
//---ACCESSOR/MUTATOR METHODS--- |
105 |
|
|
106 |
|
//---ATTRIBUTES--- |
107 |
|
|
108 |
+ |
/** |
109 |
+ |
* This holds a reference to the |
110 |
+ |
* system logger that is being used. |
111 |
+ |
*/ |
112 |
+ |
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
113 |
+ |
|
114 |
+ |
/** |
115 |
+ |
* A reference to the reference manager in use |
116 |
+ |
*/ |
117 |
+ |
private ReferenceManager _refman = ReferenceManager.getInstance(); |
118 |
+ |
|
119 |
|
//---STATIC ATTRIBUTES--- |
120 |
|
|
121 |
< |
} |
121 |
> |
/** |
122 |
> |
* The friendly name for this component, used by |
123 |
> |
* all related classes. |
124 |
> |
* This is set from the configuration. |
125 |
> |
*/ |
126 |
> |
public static String NAME; |
127 |
> |
|
128 |
> |
} |