ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/client/ClientMain.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/client/ClientMain.java (file contents):
Revision 1.4 by tdb, Mon Feb 5 20:45:32 2001 UTC vs.
Revision 1.5 by tdb, Wed Feb 21 22:48:20 2001 UTC

# Line 1 | Line 1
1 + //---PACKAGE DECLARATION---
2   package uk.ac.ukc.iscream.client;
3  
4 < import uk.ac.ukc.iscream.client.*;
4 > //---IMPORTS---
5   import uk.ac.ukc.iscream.clientinterface.*;
6   import uk.ac.ukc.iscream.componentmanager.*;
7 < import org.omg.CosNaming.*;
8 < import org.omg.CORBA.*;
8 < import org.omg.PortableServer.*;
7 > import uk.ac.ukc.iscream.core.*;
8 > import uk.ac.ukc.iscream.util.*;
9  
10 < public class ClientMain {
11 <    public static void main(String args[]) {
12 <        System.setProperty("org.omg.CORBA.ORBClass","jacorb.orb.ORB");
13 <        System.setProperty("org.omg.CORBA.ORBSingletonClass","jacorb.orb.ORBSingleton");
14 <        try {
15 <            ReferenceManager _refman = ReferenceManager.getInstance();
16 <            _refman.activatePOA();
10 > /**
11 > * A startup component for the Local Clients.
12 > *
13 > * @author  $Author$
14 > * @version $Id$
15 > */
16 > public class ClientMain implements Component {
17  
18 <            ClientServant corbaServant = new ClientServant();
19 <            org.omg.CORBA.Object o = _refman.getRootPOA().servant_to_reference(corbaServant);
20 <            Client client = ClientHelper.narrow(o);
18 > //---FINAL ATTRIBUTES---
19  
20 <            o = _refman.getCORBARef("iscream.ClientInterface.CorbaListener");
21 <            CorbaClientListener lRef = CorbaClientListenerHelper.narrow(o);
20 >    /**
21 >     * The current CVS revision of this class
22 >     */
23 >    public static final String REVISION = "$Revision$";
24 >    
25 >    /**
26 >     * The friendly name for this component, used by
27 >     * all related classes.
28 >     */
29 >    public static final String NAME = "LocalClient";
30 >    
31 > //---STATIC METHODS---
32  
33 <            boolean result;
26 <            System.out.println(" -- connecting -- ");
27 <            CorbaControlHandler handler = lRef.connect(client);
28 <            System.out.println(" -- starting data -- ");
29 <            result = handler.startData();
30 <            //System.out.println(" -- sleep for 30s -- ");
31 <            //Thread.sleep(30000);
32 <            //System.out.println(" -- stopping data -- ");
33 <            //result = handler.stopData();
34 <            //Thread.sleep(2000);
35 <            //System.out.println(" -- completed -- ");
36 <            _refman.getORB().run();
33 > //---CONSTRUCTORS---
34  
35 + //---PUBLIC METHODS---
36 +
37 +    /**
38 +     * This starts the Local Client component
39 +     */
40 +    public void start() throws ComponentStartException {
41 +
42 +        _logger.write(toString(), Logger.SYSINIT, "coming up");
43 +            
44 +        // configuration variables we require
45 +        int queueMonitorInterval = 0;
46 +        
47 +        Configuration config = _refman.getCM().getConfiguration("LocalClient");
48 +        if (config == null) {
49 +            throw new ComponentStartException("Unable to obtain configuration for component");
50          }
51 <        catch (Exception e) {
52 <            System.out.println("ERROR : " + e);
53 <            e.printStackTrace(System.out);
51 >        else {
52 >            try {
53 >                // get the configuration properties we need
54 >                queueMonitorInterval = Integer.parseInt(config.getProperty("Queue.MonitorInterval"));
55 >            } catch (org.omg.CORBA.MARSHAL e) {
56 >                throw new ComponentStartException("Unable to obtain requried configuration property for component");
57 >            }
58          }
59 +              
60 +        _logger.write(toString(), Logger.SYSINIT, "configured");
61 +        
62 +        // setup the servant
63 +        _logger.write(toString(), Logger.SYSINIT, "starting servant");          
64 +        
65 +        Client client;
66 +        
67 +        try {
68 +            ClientServant ref = new ClientServant();
69 +            org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(ref);
70 +            client = ClientHelper.narrow(objRef);
71 +            
72 +            // this name maybe shouldn't be static
73 +            objRef = _refman.getCORBARef("iscream.ClientInterface.CorbaListener");
74 +            CorbaClientListener listener = CorbaClientListenerHelper.narrow(objRef);
75 +            
76 +            _logger.write(toString(), Logger.SYSINIT, "connecting");
77 +            CorbaControlHandler handler = listener.connect(client);
78 +            handler.startData();
79 +        }
80 +        catch(Exception e) {
81 +            // not sure what to do here
82 +            // so we just log the error
83 +            _logger.write(toString(), Logger.ERROR, "ERROR - " + e.getMessage());
84 +        }
85 +        
86 +        _logger.write(toString(), Logger.SYSINIT, "started");
87 +        
88      }
89 +
90 +    /**
91 +     * Overrides the {@link java.lang.Object#toString() Object.toString()}
92 +     * method to provide clean logging (every class should have this).
93 +     *
94 +     * This uses the uk.ac.ukc.iscream.util.FormatName class
95 +     * to format the toString()
96 +     *
97 +     * @return the name of this class and its CVS revision
98 +     */
99 +    public String toString() {
100 +        return FormatName.getName(
101 +            NAME,
102 +            getClass().getName(),
103 +            REVISION);
104 +    }
105 +
106 + //---PRIVATE METHODS---
107 +
108 + //---ACCESSOR/MUTATOR METHODS---
109 +
110 + //---ATTRIBUTES---
111 +
112 +    /**
113 +     * This holds a reference to the
114 +     * system logger that is being used.
115 +     */
116 +    private Logger _logger = ReferenceManager.getInstance().getLogger();
117 +
118 +    /**
119 +     * A reference to the reference manager in use
120 +     */
121 +    private ReferenceManager _refman = ReferenceManager.getInstance();
122 +
123 + //---STATIC ATTRIBUTES---
124  
125   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines