PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/core/src/java/org/hypergraphdb/peer/StartPeer.java

http://hypergraphdb.googlecode.com/
Java | 60 lines | 49 code | 4 blank | 7 comment | 16 complexity | 6aa7d982d4f46d7bb9c2bce676479ed3 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause
  1. /*
  2. * This file is part of the HyperGraphDB source distribution. This is copyrighted
  3. * software. For permitted uses, licensing options and redistribution, please see
  4. * the LicensingInformation file at the root level of the distribution.
  5. *
  6. * Copyright (c) 2005-2010 Kobrix Software, Inc. All rights reserved.
  7. */
  8. package org.hypergraphdb.peer;
  9. import java.io.File;
  10. import java.util.Map;
  11. public class StartPeer
  12. {
  13. private static void die(String msg)
  14. {
  15. System.out.println(msg);
  16. System.out.println("Syntax: StartPeer <configfile> [db=<graph location>] [name=<peer name>] [port=<peer port>.");
  17. System.out.println("where configfile is a JSON formatted configuration file " +
  18. "and the optional 'db', 'name' and 'port' parameters overwrite the " +
  19. "'localDB', 'peerName' and 'tcp port' confuration parameters.");
  20. System.exit(-1);
  21. }
  22. public static void main(String[] args)
  23. {
  24. if (args.length < 1)
  25. die("No arguments.");
  26. String filename = args[0];
  27. String db = null;
  28. String name = null;
  29. String port = null;
  30. for (int i = 1; i < args.length; i++)
  31. {
  32. String [] A = args[i].split("=");
  33. if (A.length != 2)
  34. die("Invalid argument " + args[i]);
  35. if ("db".equals(A[0]))
  36. db = A[1];
  37. else if ("name".equals(A[0]))
  38. name = A[1];
  39. else if ("port".equals(A[0]))
  40. port = A[1];
  41. else
  42. die("Invalid parameter name " + A[0]);
  43. }
  44. Map<String, Object> configuration = HyperGraphPeer.loadConfiguration(new File(filename));
  45. if (db != null)
  46. configuration.put("localDB", db);
  47. if (name != null)
  48. configuration.put("peerName", name);
  49. if (port != null)
  50. Structs.getStruct(configuration, "jxta", "tcp").put("port", Integer.parseInt(port));
  51. HyperGraphPeer server = new HyperGraphPeer(configuration);
  52. server.start();
  53. while (true)
  54. try { Thread.sleep(5000); } catch (InterruptedException ex) { break; }
  55. }
  56. }