1 |
//---PACKAGE DECLARATION--- |
2 |
package uk.ac.ukc.iscream.clientinterface; |
3 |
|
4 |
//---IMPORTS--- |
5 |
import uk.ac.ukc.iscream.core.*; |
6 |
import uk.ac.ukc.iscream.util.*; |
7 |
import uk.ac.ukc.iscream.componentmanager.*; |
8 |
import uk.ac.ukc.iscream.client.*; |
9 |
|
10 |
/** |
11 |
* This class, a servant, listens for incoming connections from CORBA based |
12 |
* clients. Once it receives a connection it creates and assigns a CorbaHandler |
13 |
* object to it. The CorbaHandler will then handle all requests on behalf of the |
14 |
* client, and will send the client data. |
15 |
* |
16 |
* @author $Author: tdb1 $ |
17 |
* @version $Id: CorbaClientListenerServant.java,v 1.2 2001/02/03 04:44:09 tdb1 Exp $ |
18 |
*/ |
19 |
class CorbaClientListenerServant extends CorbaClientListenerPOA { |
20 |
|
21 |
//---FINAL ATTRIBUTES--- |
22 |
|
23 |
/** |
24 |
* The current CVS revision of this class |
25 |
*/ |
26 |
public final String REVISION = "$Revision: 1.2 $"; |
27 |
|
28 |
//---STATIC METHODS--- |
29 |
|
30 |
//---CONSTRUCTORS--- |
31 |
|
32 |
/** |
33 |
* Creates a new CorbaClientListenerServant. |
34 |
* |
35 |
* @param packetSorter a reference to the PacketSorter object being used |
36 |
*/ |
37 |
public CorbaClientListenerServant(PacketSorter packetSorter) { |
38 |
_packetSorter = packetSorter; |
39 |
_logger.write(toString(), Logger.SYSINIT, "created"); |
40 |
} |
41 |
|
42 |
//---PUBLIC METHODS--- |
43 |
|
44 |
/** |
45 |
* Allows a CORBA client to connect to the server. |
46 |
* |
47 |
* @param name the name of the connecting client. |
48 |
* @param client a reference to the "servant" part of the connecting client. |
49 |
* @return a CorbaHandler reference. |
50 |
*/ |
51 |
public CorbaHandler connect(String name, Client client) { |
52 |
CorbaHandlerServant chServant = new CorbaHandlerServant(_packetSorter, name, client); |
53 |
CorbaHandlerPOATie chPOATie = new CorbaHandlerPOATie(chServant); |
54 |
org.omg.CORBA.Object objRef; |
55 |
try { |
56 |
objRef = _refman.getRootPOA().servant_to_reference(chPOATie); |
57 |
} catch (Exception e) { |
58 |
objRef = null; |
59 |
_logger.write(toString(), Logger.ERROR, "Error creating CorbaHandler: "+e); |
60 |
} |
61 |
CorbaHandler corbaHandler = CorbaHandlerHelper.narrow(objRef); |
62 |
((Thread) corbaHandler).start(); |
63 |
return corbaHandler; |
64 |
} |
65 |
|
66 |
/** |
67 |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
68 |
* method to provide clean logging (every class should have this). |
69 |
* |
70 |
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
71 |
* to format the toString() |
72 |
* |
73 |
* @return the name of this class and its CVS revision |
74 |
*/ |
75 |
public String toString() { |
76 |
return FormatName.getName( |
77 |
_name, |
78 |
getClass().getName(), |
79 |
REVISION); |
80 |
} |
81 |
|
82 |
//---PRIVATE METHODS--- |
83 |
|
84 |
//---ACCESSOR/MUTATOR METHODS--- |
85 |
|
86 |
//---ATTRIBUTES--- |
87 |
|
88 |
/** |
89 |
* This is the friendly identifier of the |
90 |
* component this class is running in. |
91 |
* eg, a Filter may be called "filter1", |
92 |
* If this class does not have an owning |
93 |
* component, a name from the configuration |
94 |
* can be placed here. This name could also |
95 |
* be changed to null for utility classes. |
96 |
*/ |
97 |
private String _name = ClientInterfaceMain.NAME; |
98 |
|
99 |
/** |
100 |
* This holds a reference to the |
101 |
* system logger that is being used. |
102 |
*/ |
103 |
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
104 |
|
105 |
/** |
106 |
* A reference to the reference manager in use |
107 |
*/ |
108 |
private ReferenceManager _refman = ReferenceManager.getInstance(); |
109 |
|
110 |
/** |
111 |
* A reference to the PacketSorter. |
112 |
*/ |
113 |
private PacketSorter _packetSorter; |
114 |
|
115 |
//---STATIC ATTRIBUTES--- |
116 |
|
117 |
} |