Esempio n. 1
0
  /** onInit */
  public synchronized void onInit() {
    Assert.state(m_trapdIpMgr != null, "trapdIpMgr must be set");
    Assert.state(m_eventReader != null, "eventReader must be set");
    Assert.state(m_backlogQ != null, "backlogQ must be set");
    Assert.state(m_snmpTrapAddress != null, "snmpTrapAddress must be set");
    Assert.state(m_snmpTrapPort != null, "snmpTrapPort must be set");
    Assert.state(m_processor != null, "processor must be set");

    try {
      m_trapdIpMgr.dataSourceSync();
    } catch (final SQLException e) {
      LogUtils.errorf(this, e, "init: Failed to load known IP address list");
      throw new UndeclaredThrowableException(e);
    }

    try {
      InetAddress address = getInetAddress();
      LogUtils.infof(
          this,
          "Listening on %s:%d",
          address == null ? "[all interfaces]" : InetAddressUtils.str(address),
          getSnmpTrapPort());
      SnmpUtils.registerForTraps(this, this, address, getSnmpTrapPort(), getSnmpV3Users());
      m_registeredForTraps = true;

      LogUtils.debugf(this, "init: Creating the trap session");
    } catch (final IOException e) {
      if (e instanceof java.net.BindException) {
        managerLog()
            .error(
                "init: Failed to listen on SNMP trap port, perhaps something else is already listening?",
                e);
        LogUtils.errorf(
            this,
            e,
            "init: Failed to listen on SNMP trap port, perhaps something else is already listening?");
      } else {
        LogUtils.errorf(this, e, "init: Failed to initialize SNMP trap socket");
      }
      throw new UndeclaredThrowableException(e);
    }

    try {
      m_eventReader.open();
    } catch (final Throwable e) {
      LogUtils.errorf(this, e, "init: Failed to open event reader");
      throw new UndeclaredThrowableException(e);
    }
  }