/*------------------------------------------------------------ */
  @Override
  public void doStart() throws Exception {
    super.doStart();
    __log.debug("KVStoreSessionManager::doStart method");
    String kvstorename = this._session_id_manager.getKvstorename();
    if (kvstorename == null) throw new IllegalStateException("kvstore name is null");
    String kvstorehosts = this._session_id_manager.getKvstorehosts();
    if (kvstorehosts == null) throw new IllegalStateException("kvstore hosts list is null");
    this._kvstorehandler = this._session_id_manager.getKVStore();
    String[] hhosts = this._session_id_manager.getKvstorehosts().split(",");
    KVStoreConfig kconfig = new KVStoreConfig(this._session_id_manager.getKvstorename(), hhosts);
    KVStore kvstore = KVStoreFactory.getStore(kconfig);
    if (kvstore == null)
      throw new IllegalStateException(
          "cannot connect to kvstore, hosts=" + kvstorehosts + ";storename=" + kvstorename);
    else __log.debug("succesfully connected to the kvstore instance");
    this._kvstorehandler = kvstore;

    if (this._kvstorehandler == null)
      throw new IllegalStateException("kvstore handler passed from session id manager is null");
    String[] hosts = getContextHandler().getVirtualHosts();

    if (hosts == null || hosts.length == 0) hosts = new String[] {"::"}; // IPv6 equiv of 0.0.0.0

    String contextPath = getContext().getContextPath();
    if (contextPath == null || "".equals(contextPath)) {
      contextPath = "*";
    }

    _contextId = createContextId(hosts, contextPath);
    this.kvstore_object_ops = new ArrayList<Operation>();
  }
Beispiel #2
0
  public Java_oraclenosql(String[] argv) {

    int nArgs = argv.length;
    int argc = 0;

    while (argc < nArgs) {
      final String arg = argv[argc++];

      if (arg.equals("-s")) {
        if (argc < nArgs) {
          storeName = argv[argc++];
        } else {
          errorMessage = "storeName requires an argument";
          // True means the program will abort after printing.
          _printErrorMessage("True");
        }
      } else if (arg.equals("-h")) {
        if (argc < nArgs) {
          hostName = argv[argc++];
        } else {
          errorMessage = "hostName requires an argument";
          _printErrorMessage("True");
        }
      } else if (arg.equals("-p")) {
        if (argc < nArgs) {
          port = argv[argc++];
        } else {
          errorMessage = "port requires an argument";
          _printErrorMessage("True");
        }
      } else if (arg.equals("-t")) {
        isTest = true;
      } else if (arg.equals("-i")) {
        isInteractive = true;
      } else {
        errorMessage = "Argument " + arg + " unknown.";
        _printErrorMessage("False");
      }
    }

    store = KVStoreFactory.getStore(new KVStoreConfig(storeName, hostName + ":" + port));

    if (nArgs == 0) {
      System.out.println("No arguments were given; using defaults");
    }

    if (isTest) {
      // Run the tests.
      test();
    }

    // Infinite loop for reading Strings from the console.
    // Abandon with quit()
    String operation = "";
    Scanner scanner = new Scanner(System.in);
    while (isInteractive) {
      System.out.print(cliPrefix);
      operation = scanner.nextLine();

      if (operation.equals("")) {
        continue;
      }

      // operation must be in the form: function(arguments)
      if ((operation.indexOf('(') > 0) && (operation.indexOf('(') < operation.indexOf(')'))) {

        // Get function name.
        String functionName = operation.substring(0, operation.indexOf('(')).trim();
        // Function name must be known.
        // Determine if an element is in a java array:
        // In stackoverflow.com/questions/1128723/
        // bit.ly: http://bit.ly/yOOPLg
        if (Arrays.asList(
                "get", "delete", "put", "multiDelete", "countAll", "getAllKeys", "storeIterator")
            .contains(functionName)) {

          // Get arguments of functionName.
          String functionArgument =
              operation.substring(operation.indexOf('(') + 1, operation.indexOf(')'));
          if (functionArgument.indexOf(',') < 0) {
            keysString = functionArgument;
          } else {
            keysString = functionArgument.substring(0, functionArgument.indexOf(','));
            valueString = functionArgument.substring(functionArgument.indexOf(',') + 1);
          }
          if (Arrays.asList("get", "delete", "put").contains(functionName)) {
            _storeFunctions(functionName, true);
          } else if (functionName.equals("countAll")) {
            countAll(true);
          } else if (functionName.equals("getAllKeys")) {
            getAllKeys(true);
          } else if (functionName.equals("storeIterator")) {
            storeIterator(functionArgument, true);
          }
          if (errorMessage != "") _printErrorMessage("False");
        } else if (functionName.equals("quit")) {
          scanner.close();
          System.exit(0);
        } else {
          errorMessage = "Operation " + functionName + " could not be identified.";
          _printErrorMessage("False");
        }
      } else {
        errorMessage =
            "Operation: " + operation + " must be in the form: function(arg1, arg2, ...).";
        _printErrorMessage("False");
      }
    }
  }
  /** Parses command line args and opens the KVStore. */
  private LoadRmvTable(final String[] argv) {

    String storeName = "";
    String hostName = "";
    String hostPort = "";

    final int nArgs = argv.length;
    int argc = 0;

    if (nArgs == 0) {
      usage(null);
    }

    while (argc < nArgs) {
      final String thisArg = argv[argc++];

      if ("-store".equals(thisArg)) {
        if (argc < nArgs) {
          storeName = argv[argc++];
        } else {
          usage("-store requires an argument");
        }
      } else if ("-host".equals(thisArg)) {
        if (argc < nArgs) {
          hostName = argv[argc++];
        } else {
          usage("-host requires an argument");
        }
      } else if ("-port".equals(thisArg)) {
        if (argc < nArgs) {
          hostPort = argv[argc++];
        } else {
          usage("-port requires an argument");
        }
      } else if ("-nops".equals(thisArg)) {
        if (argc < nArgs) {
          nOps = Long.parseLong(argv[argc++]);
        } else {
          usage("-nops requires an argument");
        }
      } else if ("-security".equals(thisArg)) {
        if (argc < nArgs) {
          System.setProperty(KVSecurityConstants.SECURITY_FILE_PROPERTY, argv[argc++]);
        } else {
          usage("-security requires an argument");
        }
      } else if ("-delete".equals(thisArg)) {
        deleteExisting = true;
      } else {
        usage("Unknown argument: " + thisArg);
      }
    }

    store = KVStoreFactory.getStore(new KVStoreConfig(storeName, hostName + ":" + hostPort));

    tableAPI = store.getTableAPI();
    createTable();
    table = tableAPI.getTable(TABLE_NAME);
    if (table == null) {
      final String msg = "Store does not contain table [name=" + TABLE_NAME + "]";
      throw new RuntimeException(msg);
    }
  }