Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/strangeberry/rendezvous/tools/Main.java


1   // Copyright (C) 2002  Strangeberry Inc.
2   // @(#)Main.java, 1.11, 11/29/2002
3   //
4   // This library is free software; you can redistribute it and/or
5   // modify it under the terms of the GNU Lesser General Public
6   // License as published by the Free Software Foundation; either
7   // version 2.1 of the License, or (at your option) any later version.
8   // 
9   // This library is distributed in the hope that it will be useful,
10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  // Lesser General Public License for more details.
13  // 
14  // You should have received a copy of the GNU Lesser General Public
15  // License along with this library; if not, write to the Free Software
16  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  
18  package com.strangeberry.rendezvous.tools;
19  
20  import java.io.*;
21  import java.net.*;
22  import com.strangeberry.rendezvous.*;
23  
24  /**
25   * Main sample program for Rendezvous.
26   *
27   * @author  Arthur van Hoff
28   * @version   1.11, 11/29/2002
29   */
30  public class Main
31  {
32      static class SampleListener implements ServiceListener
33      {
34    public void addService(Rendezvous rendezvous, String type, String name)
35    {
36        System.out.println("ADD: " + rendezvous.getServiceInfo(type, name, 3*1000));
37    }
38    public void removeService(Rendezvous rendezvous, String type, String name)
39    {
40        System.out.println("REMOVE: " + name);
41    }
42      }
43  
44      public static void main(String argv[]) throws IOException
45      {
46    int argc = argv.length;
47    boolean debug = false;
48  
49    if ((argc > 0) && "-d".equals(argv[0])) {
50        System.arraycopy(argv, 1, argv, 0, --argc);
51        System.getProperties().put("rendezvous.debug", "1");
52        debug = true;
53    }
54    
55    Rendezvous rendezvous = new Rendezvous();
56  
57    if ((argc == 0) || ((argc >= 1) && "-browse".equals(argv[0]))) {
58        if (argc > 1) {
59      String types[] = new String[argc - 1];
60      System.arraycopy(argv, 1, types, 0, argc - 1);
61      new Browser(rendezvous, types);
62        } else {
63      new Browser(rendezvous);
64        }
65    } else if ((argc == 3) && "-bs".equals(argv[0])) {
66        rendezvous.addServiceListener(argv[1] + "." + argv[2], new SampleListener());
67    } else if ((argc == 6) && "-rs".equals(argv[0])) {
68        String type = argv[2] + "." + argv[3];
69        String name = argv[1] + "." + type;
70        rendezvous.registerService(new ServiceInfo(type, name, InetAddress.getLocalHost(), Integer.parseInt(argv[4]), 0, 0, argv[5]));
71    } else if (!debug) {
72        System.out.println();
73        System.out.println("jrendezvous:");
74        System.out.println("     -d            - output debugging info");
75        System.out.println("     -browse [<type>...]               - GUI browser (default)");
76        System.out.println("     -bs <type> <domain>        - browse service");
77        System.out.println("     -rs <name> <type> <domain> <port> <txt>    - register service");
78        System.out.println();
79        System.exit(1);
80    }
81      }
82  }