示例#1
0
  public void publishMessage(final NetPublish np, final String messageSource) {
    StringBuilder sb_source = new StringBuilder();
    sb_source.append("topic@");
    sb_source.append(GcsInfo.getAgentName());
    sb_source.append("://");
    sb_source.append(np.getDestination());
    sb_source.append("?app=");
    sb_source.append(messageSource);

    np.getMessage().addHeader(Headers.FROM, sb_source.toString());

    Gcs.publish(np);
  }
示例#2
0
  @GET()
  @Path("/self")
  @Produces(MediaType.APPLICATION_JSON)
  @ApiOperation(
      value = "Agent status information.",
      notes = "Returns the agent version, name and system failures.",
      response = AgentStatus.class)
  @ApiResponses(value = {@ApiResponse(code = 200, message = "The agent status information.")})
  public AgentStatus getStatus() {
    String version = System.getProperty("project-version");
    AgentStatus status = new AgentStatus();
    status.setName(GcsInfo.getAgentName());
    // FIXME: Change the next line
    status.setVersion(version != null ? version : "");
    status.setSystemMessageFailures(MiscStats.getSystemMessagesFailures());

    return status;
  }
  @Override
  public void start(Gcs gcs) {

    int wsPort = GcsInfo.getBrokerWsPort();

    if (wsPort > 0) {

      RestServer restServer = new RestServer();

      try {
        restServer.start(wsPort);
      } catch (Exception e) {
        e.printStackTrace();
      }

    } else {
      log.warn("Not starting Broker WebService");
    }
  }
示例#4
0
  public boolean enqueueMessage(final NetPublish np, String messageSource) {
    StringBuilder sb_source = new StringBuilder();
    sb_source.append("queue@");
    sb_source.append(GcsInfo.getAgentName());
    sb_source.append("://");
    sb_source.append(np.getDestination());
    sb_source.append("?app=");
    sb_source.append(messageSource);

    np.getMessage().addHeader(Headers.FROM, sb_source.toString());

    // Deferred delivery
    String defDeliveryStr = np.getMessage().getHeaders().get(Headers.DEFERRED_DELIVERY);

    if (!StringUtils.isBlank(defDeliveryStr)) {
      try {
        long value = Long.parseLong(defDeliveryStr);
        if (value < 0) {
          throw new NumberFormatException();
        }
        // Set delivery delivery time
        np.getMessage()
            .getHeaders()
            .put(Headers.DEFERRED_DELIVERY, "" + (System.currentTimeMillis() + value));
      } catch (NumberFormatException nfe) {
        log.warn(
            String.format(
                "Invalid value for '%s' header: '%s'. Ignoring and removing header. Destination queue: '%s'",
                Headers.DEFERRED_DELIVERY, defDeliveryStr, np.getDestination()));
        np.getMessage().getHeaders().remove(Headers.DEFERRED_DELIVERY);
      }
    }

    NetMessage nmsg = Gcs.buildNotification(np, np.getDestination());

    return Gcs.enqueue(nmsg, np.getDestination());
  }