KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > benchmark > util > PortAgent


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Christophe Demarey.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.benchmark.util;
28
29 // Package dependencies.
30
import java.io.IOException JavaDoc;
31 import java.net.ServerSocket JavaDoc;
32 import java.net.Socket JavaDoc;
33
34 /**
35  * This Agent is a utility class to synchronize hosts with port (sockets).
36  *
37  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
38  *
39  * @version 0.1
40  */

41 public class PortAgent
42 {
43     public static void
44     main(String JavaDoc[] args)
45     {
46         int port = 0;
47         
48         if (args.length < 2)
49         {
50             System.err.println("usage: PortAgent activate|wait_for_activation <port> [host]");
51             System.exit(0);
52         }
53         port = Integer.parseInt(args[1]);
54         
55         if (args[0].compareTo("activate") == 0)
56         {
57             // Activate a port on a remote host
58
try
59             {
60                 Socket JavaDoc socket = new Socket JavaDoc(args[2], port);
61                 socket.sendUrgentData(0);
62             } catch (IOException JavaDoc e) {
63                 e.printStackTrace();
64             }
65         }
66         else if (args[0].compareTo("wait_for_activation") == 0)
67         {
68             // Wait a port activation
69
try
70             {
71                 ServerSocket JavaDoc s = new ServerSocket JavaDoc(port);
72                 Socket JavaDoc socket = s.accept(); // blocking
73
s.close();
74             } catch (IOException JavaDoc e) {
75                 e.printStackTrace();
76             }
77         }
78     }
79
80 }
81
Popular Tags