Package net.grinder.messages.agent

Examples of net.grinder.messages.agent.StartGrinderMessage


   */
  @Override
  public void startAgent(Set<AgentIdentity> agents, GrinderProperties properties) {
    final GrinderProperties propertiesToSend = properties != null ? properties : new GrinderProperties();
    for (AgentIdentity each : agents) {
      m_consoleCommunication.sendToAddressedAgents(new AgentAddress(each), new StartGrinderMessage(
          propertiesToSend, each.getNumber()));
    }
  }
View Full Code Here


   *
   * @param grinderProperties {@link GrinderProperties} which contains grinder agent base configuration.
   * @throws GrinderException If an error occurs.
   */
  public void run(GrinderProperties grinderProperties) throws GrinderException {
    StartGrinderMessage startMessage = null;
    ConsoleCommunication consoleCommunication = null;
    m_fanOutStreamSender = new FanOutStreamSender(GrinderConstants.AGENT_FANOUT_STREAM_THREAD_COUNT);
    m_timer = new Timer(false);
    try {
      while (true) {
        m_logger.info(GrinderBuild.getName());
        ScriptLocation script = null;
        GrinderProperties properties;

        do {
          properties = createAndMergeProperties(grinderProperties,
              startMessage != null ? startMessage.getProperties() : null);
          properties.setProperty(GrinderProperties.CONSOLE_HOST, m_agentConfig.getControllerIP());
          m_agentIdentity.setName(m_agentConfig.getAgentHostID());
          final Connector connector = m_connectorFactory.create(properties);
          // We only reconnect if the connection details have changed.
          if (consoleCommunication != null && !consoleCommunication.getConnector().equals(connector)) {
            shutdownConsoleCommunication(consoleCommunication);
            consoleCommunication = null;
            // Accept any startMessage from previous console - see
            // bug 2092881.
          }

          if (consoleCommunication == null && connector != null) {
            try {
              consoleCommunication = new ConsoleCommunication(connector, grinderProperties.getProperty(
                  "grinder.user", "_default"));
              consoleCommunication.start();
              m_logger.info("Connect to console at {}", connector.getEndpointAsString());
            } catch (CommunicationException e) {
              if (m_proceedWithoutConsole) {
                m_logger.warn("{}, proceeding without the console; set "
                    + "grinder.useConsole=false to disable this warning.", e.getMessage());
              } else {
                m_logger.error(e.getMessage());
                return;
              }
            }
          }

          if (consoleCommunication != null && startMessage == null) {
            m_logger.info("Waiting for console signal");
            m_consoleListener.waitForMessage();

            if (m_consoleListener.received(ConsoleListener.START)) {
              startMessage = m_consoleListener.getLastStartGrinderMessage();
              continue; // Loop to handle new properties.
            } else {
              break; // Another message, check at end of outer while loop.
            }
          }

          if (startMessage != null) {

            final GrinderProperties messageProperties = startMessage.getProperties();
            final Directory fileStoreDirectory = m_fileStore.getDirectory();

            // Convert relative path to absolute path.
            messageProperties.setAssociatedFile(fileStoreDirectory.getFile(messageProperties
                .getAssociatedFile()));

            final File consoleScript = messageProperties.resolveRelativeFile(messageProperties.getFile(
                GrinderProperties.SCRIPT, GrinderProperties.DEFAULT_SCRIPT));

            // We only fall back to the agent properties if the start message
            // doesn't specify a script and there is no default script.
            if (messageProperties.containsKey(GrinderProperties.SCRIPT) || consoleScript.canRead()) {
              // The script directory may not be the file's direct parent.
              script = new ScriptLocation(fileStoreDirectory, consoleScript);
            }
            m_agentIdentity.setNumber(startMessage.getAgentNumber());
          } else {
            m_agentIdentity.setNumber(-1);
          }

          if (script == null) {
View Full Code Here

  public void run() throws GrinderException {
    synchronized (m_eventSyncCondition) {
      m_eventSyncCondition.notifyAll();
    }

    StartGrinderMessage startMessage = null;
    ConsoleCommunication consoleCommunication = null;
    m_fanOutStreamSender = new FanOutStreamSender(GrinderConstants.AGENT_CONTROLLER_FANOUT_STREAM_THREAD_COUNT);
    m_timer = new Timer(false);
    AgentDaemon agent = new AgentDaemon(checkNotNull(agentConfig,
        "agent.conf should be provided before agent daemon start."));
    try {
      while (true) {
        do {
          if (consoleCommunication == null) {
            final Connector connector = m_connectorFactory.create(agentConfig.getControllerIP(), agentConfig.getControllerPort());
            try {
              consoleCommunication = new ConsoleCommunication(connector);
              consoleCommunication.start();
              LOGGER.info("Connected to agent controller server at {}", connector.getEndpointAsString());
            } catch (CommunicationException e) {
              LOGGER.error("Error while connecting to agent controller server at {}",
                  connector.getEndpointAsString());
              return;
            }
          }

          if (consoleCommunication != null && startMessage == null) {
            if (m_state == AgentControllerState.UPDATING) {
              m_agentControllerServerListener.waitForMessage();
              break;
            } else {
              LOGGER.info("Waiting for agent controller server signal");
              m_state = AgentControllerState.READY;
              m_agentControllerServerListener.waitForMessage();
              if (m_agentControllerServerListener.received(AgentControllerServerListener.START)) {
                startMessage = m_agentControllerServerListener.getLastStartGrinderMessage();
                LOGGER.info("Agent start message is received from controller {}", startMessage);
                continue;
              } else {
                break; // Another message, check at end of outer
                // while loop.
              }
            }
          }

          if (startMessage != null) {
            m_agentIdentity.setNumber(startMessage.getAgentNumber());
          }
        } while (checkNotNull(startMessage).getProperties() == null);

        // Here the agent run code goes..
        if (startMessage != null) {
          final String testId = startMessage.getProperties().getProperty("grinder.test.id", "unknown");
          LOGGER.info("Starting agent... for {}", testId);
          m_state = AgentControllerState.BUSY;
          m_connectionPort = startMessage.getProperties().getInt(GrinderProperties.CONSOLE_PORT, 0);
          agent.run(startMessage.getProperties());

          final ConsoleCommunication conCom = consoleCommunication;
          agent.resetListeners();
          agent.addListener(new AgentShutDownListener() {
            @Override
View Full Code Here

    final AgentAddress address = new AgentAddress(agentIdentity);
    final String localConnectingAddress = component.getLocalConnectingAddress(address);
    final GrinderProperties prop = (GrinderProperties) grinderProperties.clone();
    prop.setProperty(GrinderProperties.CONSOLE_HOST, localConnectingAddress);
    component.sendToAddressedAgents(address,
        new StartGrinderMessage(prop, agentIdentity.getNumber()));
  }
View Full Code Here

TOP

Related Classes of net.grinder.messages.agent.StartGrinderMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.