Example #1
0
 private void setProperty(String key, String value) {
   if (value != null) {
     properties.setProperty(key, value);
   } else {
     properties.remove(key);
   }
 }
  @Test
  public void testClose() throws Exception {
    // use NullSender
    Properties props = System.getProperties();
    props.setProperty(Config.FLUENT_SENDER_CLASS, NullSender.class.getName());

    // create logger objects
    FluentLogger.getLogger("tag1");
    FluentLogger.getLogger("tag2");
    FluentLogger.getLogger("tag3");

    Map<String, FluentLogger> loggers;
    {
      loggers = FluentLogger.getLoggers();
      assertEquals(3, loggers.size());
    }

    // close and delete
    FluentLogger.closeAll();
    {
      loggers = FluentLogger.getLoggers();
      assertEquals(0, loggers.size());
    }

    props.remove(Config.FLUENT_SENDER_CLASS);
  }
Example #3
0
  private Properties validateOutputProperties(Controller controller, Properties outputProperties)
      throws XPathException {
    // Validate the serialization properties requested

    Properties baseProperties = controller.getOutputProperties();
    if (outputProperties != null) {
      Enumeration iter = outputProperties.propertyNames();
      while (iter.hasMoreElements()) {
        String key = (String) iter.nextElement();
        String value = outputProperties.getProperty(key);
        try {
          SaxonOutputKeys.checkOutputProperty(
              key, value, controller.getConfiguration().getNameChecker());
          baseProperties.setProperty(key, value);
        } catch (XPathException dynamicError) {
          try {
            outputProperties.remove(key);
            controller.getErrorListener().warning(dynamicError);
          } catch (TransformerException err2) {
            throw XPathException.makeXPathException(err2);
          }
        }
      }
    }
    if (baseProperties.getProperty("method") == null) {
      // XQuery forces the default method to XML, unlike XSLT where it depends on the contents of
      // the result tree
      baseProperties.setProperty("method", "xml");
    }
    return baseProperties;
  }
Example #4
0
 public static void main(String[] args) throws IOException {
   Properties props = new Properties();
   try (InputStream in = Files.newInputStream(Paths.get(args[0]))) {
     props.load(in);
   }
   String url = props.remove("url").toString();
   String result = doPost(url, props);
   System.out.println(result);
 }
 public boolean removeWorldlyProperty(String key) throws IOException {
   if (worldlyProperties.containsKey(key)) {
     if (worldlyProperties.remove(key) != null) {
       saveConfigFileProperties();
       return true;
     } else {
       return false;
     }
   } else {
     return false;
   }
 }
Example #6
0
  // Expand grid search related argument sets
  @Override
  protected NanoHTTPD.Response serveGrid(NanoHTTPD server, Properties parms, RequestType type) {
    String[][] values = new String[_arguments.size()][];
    boolean gridSearch = false;
    for (int i = 0; i < _arguments.size(); i++) {
      Argument arg = _arguments.get(i);
      if (arg._gridable) {
        String value = _parms.getProperty(arg._name);
        if (value != null) {
          // Skips grid if argument is an array, except if imbricated expression
          // Little hackish, waiting for real language
          boolean imbricated = value.contains("(");
          if (!arg._field.getType().isArray() || imbricated) {
            values[i] = split(value);
            if (values[i] != null && values[i].length > 1) gridSearch = true;
          } else if (arg._field.getType().isArray()
              && !imbricated) { // Copy values which are arrays
            values[i] = new String[] {value};
          }
        }
      }
    }
    if (!gridSearch) return superServeGrid(server, parms, type);

    // Ignore destination key so that each job gets its own
    _parms.remove("destination_key");
    for (int i = 0; i < _arguments.size(); i++)
      if (_arguments.get(i)._name.equals("destination_key")) values[i] = null;

    // Iterate over all argument combinations
    int[] counters = new int[values.length];
    ArrayList<Job> jobs = new ArrayList<Job>();
    for (; ; ) {
      Job job = (Job) create(_parms);
      Properties combination = new Properties();
      for (int i = 0; i < values.length; i++) {
        if (values[i] != null) {
          String value = values[i][counters[i]];
          value = value.trim();
          combination.setProperty(_arguments.get(i)._name, value);
          _arguments.get(i).reset();
          _arguments.get(i).check(job, value);
        }
      }
      job._parms = combination;
      jobs.add(job);
      if (!increment(counters, values)) break;
    }
    GridSearch grid = new GridSearch();
    grid.jobs = jobs.toArray(new Job[jobs.size()]);
    return grid.superServeGrid(server, parms, type);
  }
  public PluginInterface getLocalPluginInterface(Class plugin_class, String id)
      throws PluginException {
    try {
      Plugin p = (Plugin) plugin_class.newInstance();

      // Discard plugin.id from the properties, we want the
      // plugin ID we create to take priority - not a value
      // from the original plugin ID properties file.
      Properties local_props = new Properties(props);
      local_props.remove("plugin.id");

      if (id.endsWith("_v")) {

        throw (new Exception("Verified plugins must be loaded from a jar"));
      }

      PluginInterfaceImpl pi =
          new PluginInterfaceImpl(
              p,
              initialiser,
              initialiser_key,
              class_loader,
              null,
              key + "." + id,
              local_props,
              pluginDir,
              getPluginID() + "." + id,
              plugin_version);

      initialiser.fireCreated(pi);

      p.initialize(pi);

      children.add(pi);

      return (pi);

    } catch (Throwable e) {

      if (e instanceof PluginException) {

        throw ((PluginException) e);
      }

      throw (new PluginException("Local initialisation fails", e));
    }
  }
 /**
  * Update a property value. Assign a value to a property. If the property value has really changed
  * notify our observers of the change.
  *
  * @param name The name of the property to assign.
  * @param value The new value for this property, or <strong>null</strong> if the property setting
  *     is to be cancelled.
  * @return A boolean <strong>true</strong> if change was accepted by our observers,
  *     <strong>false</strong> otherwise.
  */
 public synchronized boolean putValue(String name, String value) {
   if (debug) System.out.println("ObservableProperties: put " + name + "=[" + value + "]");
   // If null value, remove the prop definition:
   if (value == null) {
     super.remove(name);
     return true;
   }
   // Otherwise, proceed:
   String old = (String) get(name);
   if ((old == null) || (!old.equals(value))) {
     super.put(name, value);
     for (int i = 0; i < observers.length; i++) {
       if (observers[i] == null) continue;
       if (debug) System.out.println("ObservableProperties: notifies " + observers[i]);
       if (!observers[i].propertyChanged(name)) {
         if (old != null) super.put(name, old);
         return false;
       }
     }
   }
   return true;
 }
Example #9
0
  /**
   * Setup the Protocol instance acording to the configuration string The following properties are
   * being read by the UDP protocol param mcast_addr - the multicast address to use default is
   * 224.0.0.200 param mcast_port - (int) the port that the multicast is sent on default is 7500
   * param ip_mcast - (boolean) flag whether to use IP multicast - default is true param ip_ttl -
   * Set the default time-to-live for multicast packets sent out on this socket. default is 32
   *
   * @return true if no other properties are left. false if the properties still have data in them,
   *     ie , properties are left over and not handled by the protocol stack
   */
  public boolean setProperties(Properties props) {
    String str, tmp;

    tmp = System.getProperty("UDP.bind_addr");
    if (tmp != null) {
      str = tmp;
    } else {
      str = props.getProperty("bind_addr");
    }
    if (str != null) {
      try {
        bind_addr = InetAddress.getByName(str);
      } catch (UnknownHostException unknown) {
        Trace.fatal("UDP.setProperties()", "(bind_addr): host " + str + " not known");
        return false;
      }
      props.remove("bind_addr");
    }

    str = props.getProperty("bind_port");
    if (str != null) {
      bind_port = new Integer(str).intValue();
      props.remove("bind_port");
    }

    str = props.getProperty("start_port");
    if (str != null) {
      bind_port = new Integer(str).intValue();
      props.remove("start_port");
    }

    str = props.getProperty("port_range");
    if (str != null) {
      port_range = new Integer(str).intValue();
      props.remove("port_range");
    }

    str = props.getProperty("mcast_addr");
    if (str != null) {
      mcast_addr_name = new String(str);
      props.remove("mcast_addr");
    }

    str = props.getProperty("mcast_port");
    if (str != null) {
      mcast_port = new Integer(str).intValue();
      props.remove("mcast_port");
    }

    str = props.getProperty("ip_mcast");
    if (str != null) {
      ip_mcast = new Boolean(str).booleanValue();
      props.remove("ip_mcast");
    }

    str = props.getProperty("ip_ttl");
    if (str != null) {
      ip_ttl = new Integer(str).intValue();
      props.remove("ip_ttl");
    }

    str = props.getProperty("mcast_send_buf_size");
    if (str != null) {
      mcast_send_buf_size = Integer.parseInt(str);
      props.remove("mcast_send_buf_size");
    }

    str = props.getProperty("mcast_recv_buf_size");
    if (str != null) {
      mcast_recv_buf_size = Integer.parseInt(str);
      props.remove("mcast_recv_buf_size");
    }

    str = props.getProperty("ucast_send_buf_size");
    if (str != null) {
      ucast_send_buf_size = Integer.parseInt(str);
      props.remove("ucast_send_buf_size");
    }

    str = props.getProperty("ucast_recv_buf_size");
    if (str != null) {
      ucast_recv_buf_size = Integer.parseInt(str);
      props.remove("ucast_recv_buf_size");
    }

    str = props.getProperty("loopback");
    if (str != null) {
      loopback = new Boolean(str).booleanValue();
      props.remove("loopback");
    }

    // this is deprecated, just left for compatibility (use use_incoming_packet_handler)
    str = props.getProperty("use_packet_handler");
    if (str != null) {
      use_incoming_packet_handler = new Boolean(str).booleanValue();
      props.remove("use_packet_handler");
      Trace.warn(
          "UDP.setProperties()",
          "'use_packet_handler' is deprecated; use 'use_incoming_packet_handler' instead");
    }

    str = props.getProperty("use_incoming_packet_handler");
    if (str != null) {
      use_incoming_packet_handler = new Boolean(str).booleanValue();
      props.remove("use_incoming_packet_handler");
    }

    str = props.getProperty("use_outgoing_packet_handler");
    if (str != null) {
      use_outgoing_packet_handler = new Boolean(str).booleanValue();
      props.remove("use_outgoing_packet_handler");
    }

    str = props.getProperty("max_bundle_size");
    if (str != null) {
      int bundle_size = Integer.parseInt(str);
      if (bundle_size > max_bundle_size) {
        Trace.error(
            "UDP.setProperties()",
            "max_bundle_size ("
                + bundle_size
                + ") is greater than largest UDP fragmentation size ("
                + max_bundle_size
                + ")");
        return false;
      }
      if (bundle_size <= 0) {
        Trace.error("UDP.setProperties()", "max_bundle_size (" + bundle_size + ") is <= 0");
        return false;
      }
      max_bundle_size = bundle_size;
      props.remove("max_bundle_size");
    }

    str = props.getProperty("max_bundle_timeout");
    if (str != null) {
      max_bundle_timeout = Long.parseLong(str);
      if (max_bundle_timeout <= 0) {
        Trace.error(
            "UDP.setProperties()", "max_bundle_timeout of " + max_bundle_timeout + " is invalid");
        return false;
      }
      props.remove("max_bundle_timeout");
    }

    str = props.getProperty("enable_bundling");
    if (str != null) {
      enable_bundling = new Boolean(str).booleanValue();
      props.remove("enable_bundling");
    }

    if (props.size() > 0) {
      System.err.println("UDP.setProperties(): the following properties are not recognized:");
      props.list(System.out);
      return false;
    }

    if (enable_bundling) {
      if (use_outgoing_packet_handler == false) {
        Trace.warn(
            "UDP.setProperties()",
            "enable_bundling is true; setting use_outgoing_packet_handler=true");
      }
      use_outgoing_packet_handler = true;
    }

    return true;
  }
Example #10
0
 /**
  * PUBLIC: Some drivers don't like the "user" and "password" properties. They can be removed with
  * this method.
  */
 public void removeProperty(String propertyName) {
   properties.remove(propertyName);
 }
Example #11
0
 private void clearStats(Info info) {
   raidTarget.remove(info.getChannel());
   raidLocation.remove(info.getChannel());
   raidPath.remove(info.getChannel());
   info.sendMessage("Raid status cleared.");
 }