Beispiel #1
0
  @Test
  public void testPutAllEnv() {
    final SystemProperties props = new SystemProperties();
    assertNull(props.getEnv("MY_ENV"));

    final Map<String, String> env = ImmutableMap.of("MY_ENV", "myvalue");
    props.putAllEnv(env);

    assertEquals("myvalue", props.getEnv("MY_ENV"));
    assertEquals("myvalue", props.get("env.MY_ENV"));
  }
Beispiel #2
0
  @Test
  public void testDefault() {
    final SystemProperties props = SystemProperties.getDefault();

    final String propKey = System.getProperties().keySet().iterator().next().toString();
    final String propValue = System.getProperties().getProperty(propKey);
    assertEquals(propValue, props.get(propKey));

    final String envKey = System.getenv().keySet().iterator().next();
    final String envValue = System.getenv(envKey);
    assertEquals(envValue, props.getEnv(envKey));
  }
Beispiel #3
0
  @Test
  public void testEnv() {
    final SystemProperties props = new SystemProperties();
    assertNull(props.getEnv("MY_ENV"));

    assertNull(props.putEnv("MY_ENV", "myvalue"));
    assertEquals("myvalue", props.getEnv("MY_ENV"));

    assertEquals("myvalue", props.putEnv("MY_ENV", "othervalue"));
    assertEquals("othervalue", props.getEnv("MY_ENV"));
    assertEquals("othervalue", props.get("env.MY_ENV"));
  }
  @Override
  public void run() {

    terminate = false;
    logger.info("Starting echos.");
    EchoResourceMap echoMap = EchoResourceMap.getEchoMap();

    // Get the connection details for the MQ box.
    String path = amqpURI.getRawPath();
    String queue = path.substring(path.indexOf('/', 1) + 1);
    String virtualHost = uriDecode(amqpURI.getPath().substring(1, path.indexOf('/', 1)));

    // Prepare a simple message to send to the echo system. This message
    // will come back in each resource's MQ queue.
    StreamEcho streamEcho = new StreamEcho();
    streamEcho.setHost(virtualHost);
    streamEcho.setQueue(queue);
    String guid = UUID.randomUUID().toString();
    DateFormat df = new SimpleDateFormat("yyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    df.setTimeZone(TimeZone.getTimeZone("UTC"));
    streamEcho.setMessage(guid + ";" + df.format(new Date()));
    String stringStreamEcho = JsonHelper.ToJson(streamEcho);
    Thread.currentThread().setName(THREAD_NAME);

    int sleepInterval = Integer.parseInt(SystemProperties.get("ss.echo_sender_interval")) * 1000;

    while (true) {
      try {

        // Send the message to the Sporting Solution's end-point.
        HttpServices.getHttpService()
            .processRequest(
                "http://api.sportingsolutions.com/rels/stream/batchecho",
                restItem,
                stringStreamEcho);

        logger.info("Batch echo sent: " + stringStreamEcho);

        // After the message is sent increase the number of echos sent
        // for all resources.
        // The number of missed echos is configured in:
        // conf/sdk.properties using "ss.echo_max_missed_echos"
        Set<String> defaulters =
            echoMap.incrAll(Integer.parseInt(SystemProperties.get("ss.echo_max_missed_echos")));

        Iterator<String> keyIter = defaulters.iterator();

        /*
         * EchoMap returns a list of resources which appear to have
         * unresponsive queues (the number of echo retries has been
         * exceeded.
         *
         * At this point we disconnect the queue consumer from the MQ
         * service. This triggers an action in RabbitMQ which alerts the
         * resource/fixture of the failure. The resource is then
         * responsible for communicating the problem to the client code.
         */
        while (keyIter.hasNext()) {
          String resourceId = keyIter.next();
          logger.warn(
              "Attempting to disconnect resource: "
                  + resourceId
                  + " due maximum number of echo retries reached");
          MQListener.disconnect(resourceId);
        }

        // The interval between echos is configured in:
        // conf/sdk.properties using "ss.echo_sender_interval"
        Thread.sleep(sleepInterval);

        if (terminate == true) {
          return;
        }

      } catch (Exception ex) {
        logger.error("An error occured: " + ex);
      }
    }
  }
 @Override
 public String getValue(SpringApplicationEvent event) {
   return SystemProperties.get(this.properties);
 }
Beispiel #6
0
  public static File createTempFile(String prefix, String extension) {
    PortalFilePermission.checkWrite(SystemProperties.get(SystemProperties.TMP_DIR));

    return getFile().createTempFile(prefix, extension);
  }
Beispiel #7
0
  public static File createTempFile(InputStream is) throws IOException {
    PortalFilePermission.checkWrite(SystemProperties.get(SystemProperties.TMP_DIR));

    return getFile().createTempFile(is);
  }
Beispiel #8
0
  public static File createTempFile() {
    PortalFilePermission.checkWrite(SystemProperties.get(SystemProperties.TMP_DIR));

    return getFile().createTempFile();
  }