예제 #1
0
  private BroadcastGroup createBroadcastGroup(BroadcastGroupConfiguration config) throws Exception {
    BroadcastGroup group = broadcastGroups.get(config.getName());

    if (group == null) {
      group =
          new BroadcastGroupImpl(
              nodeManager,
              config.getName(),
              config.getBroadcastPeriod(),
              scheduledExecutor,
              config.getEndpointFactoryConfiguration().createBroadcastEndpointFactory());

      for (String connectorInfo : config.getConnectorInfos()) {
        TransportConfiguration connector =
            configuration.getConnectorConfigurations().get(connectorInfo);

        if (connector == null) {
          logWarnNoConnector(config.getName(), connectorInfo);

          return null;
        }

        group.addConnector(connector);
      }
    }

    if (group.size() == 0) {
      logWarnNoConnector(config.getConnectorInfos().toString(), group.getName());
      return null;
    }

    broadcastGroups.put(config.getName(), group);

    return group;
  }
예제 #2
0
  /**
   * Activates several cluster services. Used by backups on failover.
   *
   * @throws Exception
   */
  public synchronized void activate() throws Exception {
    if (state != State.STARTED && state != State.DEPLOYED) return;

    if (backup) {
      backup = false;

      deployConfiguredBridges();

      for (BroadcastGroup broadcastGroup : broadcastGroups.values()) {
        try {
          broadcastGroup.start();
        } catch (Exception e) {
          HornetQServerLogger.LOGGER.unableToStartBroadcastGroup(e, broadcastGroup.getName());
        }
      }

      for (ClusterConnection clusterConnection : clusterConnections.values()) {
        try {
          clusterConnection.activate();
        } catch (Exception e) {
          HornetQServerLogger.LOGGER.unableToStartClusterConnection(e, clusterConnection.getName());
        }
      }

      for (Bridge bridge : bridges.values()) {
        try {
          bridge.start();
        } catch (Exception e) {
          HornetQServerLogger.LOGGER.unableToStartBridge(e, bridge.getName());
        }
      }
    }
  }
예제 #3
0
  @RequestMapping(
      value = "/api/broadcast",
      method = RequestMethod.POST,
      produces = "application/json")
  public List<BroadcastGroup> broadcastMessage(
      @RequestParam("name") String name,
      @RequestParam("set") Integer setId,
      @RequestParam("message") String message) {
    BroadcastGroup group = broadcastRepository.findOne(name);
    if (group != null) {
      Optional<BroadcastSet> setOptional =
          group.getBroadcastSets().stream().filter(set -> set.getId() == setId).findFirst();
      if (setOptional.isPresent()) {
        BroadcastSet set = setOptional.get();
        set.getMessages().add(new BroadcastMessage(message, new Date()));
        broadcastRepository.save(group);
        executorService.execute(
            () -> {
              set.getUsers()
                  .forEach(
                      userId -> {
                        SlackUser user = session.findUserById(userId);
                        session.sendMessageToUser(user, message, null);
                      });
            });
      } else {
        log.error("Can't find set with id {}", setId);
      }

    } else {
      log.error("Can't find group with name {}", name);
    }
    return broadcastRepository.findAll();
  }
예제 #4
0
  public void stop() throws Exception {
    synchronized (this) {
      if (state == State.STOPPED || state == State.STOPPING) {
        return;
      }
      state = State.STOPPING;

      for (BroadcastGroup group : broadcastGroups.values()) {
        group.stop();
        managementService.unregisterBroadcastGroup(group.getName());
      }

      broadcastGroups.clear();

      for (ClusterConnection clusterConnection : clusterConnections.values()) {
        clusterConnection.stop();
        managementService.unregisterCluster(clusterConnection.getName().toString());
      }

      for (Bridge bridge : bridges.values()) {
        bridge.stop();
        managementService.unregisterBridge(bridge.getName().toString());
      }

      bridges.clear();
    }

    for (ServerLocatorInternal clusterLocator : clusterLocators) {
      try {
        clusterLocator.close();
      } catch (Exception e) {
        HornetQServerLogger.LOGGER.errorClosingServerLocator(e, clusterLocator);
      }
    }
    clusterLocators.clear();
    state = State.STOPPED;

    clearClusterConnections();
  }
예제 #5
0
  public synchronized void start() throws Exception {
    if (state == State.STARTED) {
      return;
    }

    for (BroadcastGroup group : broadcastGroups.values()) {
      if (!backup) {
        group.start();
      }
    }

    for (ClusterConnection conn : clusterConnections.values()) {
      conn.start();
      if (backup && configuration.isSharedStore()) {
        conn.informTopology();
        conn.announceBackup();
      }
    }

    deployConfiguredBridges();
    state = State.STARTED;
  }