package org.realityforge.tarrabah;

import java.net.InetSocketAddress;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.annotation.Nullable;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.enterprise.context.ApplicationScoped;
import org.jboss.netty.bootstrap.ConnectionlessBootstrap;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.channel.Channels;
import org.jboss.netty.channel.FixedReceiveBufferSizePredictorFactory;
import org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory;

@ApplicationScoped
public class SyslogUDPServer
  extends AbstractSyslogServer
{
  private final int _port = 8080;

  @Nullable
  private ConnectionlessBootstrap _bootstrap;

  @PostConstruct
  public void postConstruct()
  {
    System.out.println( "SyslogUDPServer.postConstruct" );
    final ExecutorService executorService = Executors.newCachedThreadPool();
    _bootstrap = new ConnectionlessBootstrap( new NioDatagramChannelFactory( executorService ) );

    _bootstrap.setOption( "receiveBufferSize", 1048576 );
    _bootstrap.setOption( "receiveBufferSizePredictorFactory", new FixedReceiveBufferSizePredictorFactory( 1024 * 8 ) );

    // Set up the pipeline factory.
    _bootstrap.setPipelineFactory( new ChannelPipelineFactory()
    {
      public ChannelPipeline getPipeline()
        throws Exception
      {
        return Channels.pipeline( new Handler() );
      }
    } );

    // Bind and start to accept incoming connections.
    _bootstrap.bind( new InetSocketAddress( _port ) );
  }

  @PreDestroy
  public void preDestroy()
  {
    System.out.println( "SyslogUDPServer.preDestroy" );
    if ( null != _bootstrap )
    {
      _bootstrap.shutdown();
      _bootstrap = null;
    }
  }
}

@@ -148,16 +148,81 @@
 cutors;%0A
+import java.util.logging.Level;%0Aimport java.util.logging.Logger;%0A
 import j
@@ -797,16 +797,53 @@
 erver%0A%7B%0A
+  @Inject%0A  private Logger _logger;%0A%0A
   privat
@@ -983,67 +983,8 @@
   %7B%0A
-    System.out.println( %22SyslogUDPServer.postConstruct%22 );%0A
     
@@ -1582,24 +1582,141 @@
 %7D%0A    %7D );%0A%0A
+    if ( _logger.isLoggable( Level.INFO ) )%0A    %7B%0A      _logger.info( %22Binding UDP Server to port %22 + _port );%0A    %7D%0A
     // Bind 
@@ -1870,95 +1870,171 @@
     
-System.out.println( %22SyslogUDPServer.preDestroy%22 );%0A    if ( null != _bootstrap
+if ( null != _bootstrap )%0A    %7B%0A      if ( _logger.isLoggable( Level.INFO ) )%0A      %7B%0A        _logger.info( %22Shutting down UDP server on port %22 + _port
  )
+;
 %0A    
-%7B
+  %7D%0A
 %0A   

Replace System out with Logger