SocketCollector implements Closeable, Runnable { @SuppressWarnings("unchecked") @Activate public void activate(ComponentContext context) throws IOException { this.properties = context.getProperties(); int port = Integer.parseInt(getProperty(this.properties, PORT_NAME, "4560")); int workers = Integer.parseInt(getProperty(this.properties, WORKERS_NAME, "10")); LOGGER.info("Starting Log4j Socket collector on port {}", port); this.serverSocket = new ServerSocket(port); this.executor = Executors.newFixedThreadPool(workers + 1); this.executor.execute(this); this.open = true; }  @SuppressWarnings("unchecked") @Activate void activate(ComponentContext context); @Override void run(); @Deactivate @Override void close(); static final String PORT_NAME; static final String WORKERS_NAME; @Reference
    public EventAdmin dispatcher; }
@Test public void testSocket() throws Exception { activate(); sendEventOnSocket(newLoggingEvent("Sample message")); waitUntilEventCountHandled(1); assertEquals("Event(s) should have been correctly handled", 1, eventAdmin.getPostEvents().size()); }
@Test public void testUnknownEvent() throws Exception { activate(); sendEventOnSocket(new UnknownClass()); waitUntilEventCountHandled(1); assertEquals("Event(s) should have been correctly handled", 0, eventAdmin.getPostEvents().size()); }
@Test public void testSocketMultipleClients() throws Exception { activate(); Runnable runnable = new Runnable() { @Override public void run() { try { sendEventOnSocket(newLoggingEvent("Sample message")); } catch (Throwable e) { e.printStackTrace(); } } }; Thread thread; thread = new Thread(runnable); thread.start(); thread = new Thread(runnable); thread.start(); waitUntilEventCountHandled(2); assertEquals("Event(s) should have been correctly handled", 2, eventAdmin.getPostEvents().size()); }