Exemplo n.º 1
0
 @Override
 public void updateSession(Session session) {
   s_log.info("MockSnmpAgent: starting updateSession()");
   try {
     super.updateSession(session);
   } finally {
     s_log.info("MockSnmpAgent: finished updateSession()");
   }
 }
Exemplo n.º 2
0
 @Override
 public void initConfigMIB() {
   s_log.info("MockSnmpAgent: starting initConfigMIB()");
   try {
     super.initConfigMIB();
   } finally {
     s_log.info("MockSnmpAgent: finished initConfigMIB()");
   }
 }
Exemplo n.º 3
0
 @Override
 public void setupDefaultProxyForwarder() {
   s_log.info("MockSnmpAgent: starting setupDefaultProxyForwarder()");
   try {
     super.setupDefaultProxyForwarder();
   } finally {
     s_log.info("MockSnmpAgent: finished setupDefaultProxyForwarder()");
   }
 }
Exemplo n.º 4
0
 @Override
 public void initSnmpSession() {
   s_log.info("MockSnmpAgent: starting initTransportMappings()");
   try {
     super.initSnmpSession();
   } finally {
     s_log.info("MockSnmpAgent: finished initTransportMappings()");
   }
 }
Exemplo n.º 5
0
  /**
   * Starts the <code>MockSnmpAgent</code> running. Meant to be called from the <code>start</code>
   * method of class <code>Thread</code>, but could also be used to bring up a standalone mock
   * agent.
   *
   * @see org.snmp4j.agent.BaseAgent#run()
   * @author Jeff Gehlbach
   */
  @Override
  public void run() {
    s_log.info("MockSnmpAgent: Initializing SNMP Agent");
    try {
      init();
      s_log.info("MockSnmpAgent: Finished 'init' loading config");
      loadConfig(ImportModes.UPDATE_CREATE);
      s_log.info("MockSnmpAgent: finished 'loadConfig' adding shutdown hook");
      addShutdownHook();
      s_log.info("MockSnmpAgent: finished 'addShutdownHook' finishing init");
      finishInit();
      s_log.info("MockSnmpAgent: finished 'finishInit' running agent");
      super.run();
      s_log.info("MockSnmpAgent: finished running Agent - setting running to true");
      m_running.set(true);
    } catch (final BindException e) {
      s_log.error(
          String.format(
              "MockSnmpAgent: Unable to bind to %s.  You probably specified an invalid address or a port < 1024 and are not running as root. Exception: %s",
              m_address.get(), e),
          e);
    } catch (final Throwable t) {
      s_log.error("MockSnmpAgent: An error occurred while initializing: " + t, t);
      t.printStackTrace();
    }

    boolean interrupted = false;
    s_log.info(
        "MockSnmpAgent: Initialization Complete processing message until agent is shutdown.");
    while (m_running.get()) {
      try {
        Thread.sleep(10); // fast, Fast, FAST, *FAST*!!!
      } catch (final InterruptedException e) {
        interrupted = true;
        break;
      }
    }

    s_log.info("MockSnmpAgent: Shutdown called stopping agent.");
    for (final TransportMapping transportMapping : transportMappings) {
      try {
        if (transportMapping != null) {
          transportMapping.close();
        }
      } catch (final IOException t) {
        s_log.error(
            "MockSnmpAgent: an error occurred while closing the transport mapping "
                + transportMapping
                + ": "
                + t,
            t);
      }
    }

    m_stopped.set(true);

    s_log.info("MockSnmpAgent: Agent is no longer running.");
    if (interrupted) {
      Thread.currentThread().interrupt();
    }
  }