public synchronized void sendNow(final Event event) {
    // Expand the event parms
    final EventExpander expander = new EventExpander();
    expander.setEventConfDao(new EmptyEventConfDao());
    expander.expandEvent(event);
    m_pendingEvents++;
    LogUtils.debugf(this, "StartEvent processing (%d remaining)", m_pendingEvents);
    LogUtils.debugf(this, "Received: ", new EventWrapper(event));
    m_anticipator.eventReceived(event);

    final Runnable r =
        new Runnable() {
          public void run() {
            try {
              m_eventWriter.writeEvent(event);
              broadcastNow(event);
              m_anticipator.eventProcessed(event);
            } finally {
              synchronized (MockEventIpcManager.this) {
                m_pendingEvents--;
                LogUtils.debugf(this, "Finished processing event (%d remaining)", m_pendingEvents);
                MockEventIpcManager.this.notifyAll();
              }
            }
          }
        };

    if (isSynchronous()) {
      r.run();
    } else {
      getScheduler().schedule(r, m_eventDelay, TimeUnit.MILLISECONDS);
    }
  }
示例#2
0
  protected void setUp() throws Exception {
    super.setUp();
    MockUtil.println("------------ Begin Test " + this + " --------------------------");
    MockLogAppender.setupLogging();

    if (m_runSupers) {

      createMockNetwork();

      populateDatabase();

      DataSourceFactory.setInstance(m_db);

      SnmpPeerFactory.setInstance(
          new SnmpPeerFactory(new ByteArrayResource(getSnmpConfig().getBytes())));

      if (isStartEventd()) {
        m_eventdIpcMgr = new EventIpcManagerDefaultImpl();

        JdbcEventdServiceManager eventdServiceManager = new JdbcEventdServiceManager();
        eventdServiceManager.setDataSource(m_db);
        eventdServiceManager.afterPropertiesSet();

        /*
         * Make sure we specify a full resource path since "this" is
         * the unit test class, which is most likely in another package.
         */
        File configFile =
            ConfigurationTestUtils.getFileForResource(
                this, "/org/opennms/netmgt/mock/eventconf.xml");
        DefaultEventConfDao eventConfDao = new DefaultEventConfDao();
        eventConfDao.setConfigResource(new FileSystemResource(configFile));
        eventConfDao.afterPropertiesSet();
        EventconfFactory.setInstance(eventConfDao);

        EventExpander eventExpander = new EventExpander();
        eventExpander.setEventConfDao(eventConfDao);
        eventExpander.afterPropertiesSet();

        JdbcEventWriter jdbcEventWriter = new JdbcEventWriter();
        jdbcEventWriter.setEventdServiceManager(eventdServiceManager);
        jdbcEventWriter.setDataSource(m_db);
        jdbcEventWriter.setGetNextIdString(
            "select nextVal('eventsNxtId')"); // for HSQL: "SELECT max(eventId)+1 from events"
        jdbcEventWriter.afterPropertiesSet();

        EventIpcBroadcastProcessor eventIpcBroadcastProcessor = new EventIpcBroadcastProcessor();
        eventIpcBroadcastProcessor.setEventIpcBroadcaster(m_eventdIpcMgr);
        eventIpcBroadcastProcessor.afterPropertiesSet();

        List<EventProcessor> eventProcessors = new ArrayList<EventProcessor>(3);
        eventProcessors.add(eventExpander);
        eventProcessors.add(jdbcEventWriter);
        eventProcessors.add(eventIpcBroadcastProcessor);

        DefaultEventHandlerImpl eventHandler = new DefaultEventHandlerImpl();
        eventHandler.setEventProcessors(eventProcessors);
        eventHandler.afterPropertiesSet();

        m_eventdIpcMgr.setHandlerPoolSize(5);
        m_eventdIpcMgr.setEventHandler(eventHandler);
        m_eventdIpcMgr.afterPropertiesSet();

        m_eventProxy = m_eventdIpcMgr;

        EventIpcManagerFactory.setIpcManager(m_eventdIpcMgr);

        EventIpcManagerEventHandlerProxy proxy = new EventIpcManagerEventHandlerProxy();
        proxy.setEventIpcManager(m_eventdIpcMgr);
        proxy.afterPropertiesSet();
        List<EventHandler> eventHandlers = new ArrayList<EventHandler>(1);
        eventHandlers.add(proxy);

        TcpEventReceiver tcpEventReceiver = new TcpEventReceiver();
        tcpEventReceiver.setPort(5837);
        tcpEventReceiver.setEventHandlers(eventHandlers);

        UdpEventReceiver udpEventReceiver = new UdpEventReceiver();
        udpEventReceiver.setPort(5837);
        tcpEventReceiver.setEventHandlers(eventHandlers);

        List<EventReceiver> eventReceivers = new ArrayList<EventReceiver>(2);
        eventReceivers.add(tcpEventReceiver);
        eventReceivers.add(udpEventReceiver);

        m_eventd = new Eventd();
        m_eventd.setEventdServiceManager(eventdServiceManager);
        m_eventd.setEventReceivers(eventReceivers);
        m_eventd.setReceiver(new BroadcastEventProcessor(m_eventdIpcMgr, eventConfDao));

        m_eventd.init();
        m_eventd.start();
      }
    }

    m_transMgr = new DataSourceTransactionManager(DataSourceFactory.getInstance());
  }