KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > notification > TestServer


1 package org.jacorb.test.notification;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1999-2003 Gerald Brose
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  */

23
24 import java.io.PrintWriter JavaDoc;
25 import java.net.Socket JavaDoc;
26
27 import org.omg.CORBA.ORB JavaDoc;
28 import org.omg.PortableServer.POA JavaDoc;
29 import org.omg.PortableServer.POAHelper JavaDoc;
30 import org.omg.PortableServer.Servant JavaDoc;
31
32 /**
33  * @author Alphonse Bendt
34  */

35
36 public class TestServer
37 {
38     public static void main(String JavaDoc[] args) throws Exception JavaDoc
39     {
40         String JavaDoc _servantClassName = args[0];
41         int _portToSendIorTo = Integer.parseInt(args[1]);
42
43         try
44         {
45             // init ORB
46
ORB JavaDoc orb = ORB.init(args, null);
47
48             // init POA
49
POA JavaDoc poa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
50             poa.the_POAManager().activate();
51
52             Class JavaDoc _servantClass = Class.forName(_servantClassName);
53
54             Servant JavaDoc _servant = (Servant JavaDoc) _servantClass.newInstance();
55
56             // create the object reference
57
org.omg.CORBA.Object JavaDoc o = poa.servant_to_reference(_servant);
58
59             Socket JavaDoc _socket = new Socket JavaDoc("localhost", _portToSendIorTo);
60
61             PrintWriter JavaDoc _out = new PrintWriter JavaDoc(_socket.getOutputStream(), true);
62
63             _out.println(orb.object_to_string(o));
64             _out.flush();
65             _out.close();
66             _socket.close();
67
68             // wait for requests
69
orb.run();
70         } catch (Throwable JavaDoc e)
71         {
72             // ignored
73
}
74     }
75 }
76
Popular Tags