// From: https://github.com/aphyr/riemann-java-client/pull/24
package com.github.kyleburton.logback;

import com.google.protobuf.MessageLite;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import com.aphyr.riemann.client.SynchronousTransport;

import static org.jboss.netty.buffer.ChannelBuffers.wrappedBuffer;

public class SimpleUdpTransport implements SynchronousTransport {

  public static final int DEFAULT_PORT = 5555;

  private volatile DatagramSocket socket;
  private volatile boolean connected = false;

  private final InetSocketAddress address;

  public SimpleUdpTransport(final InetSocketAddress address) {
    this.address = address;
  }

  public SimpleUdpTransport(final String host, final int port) throws IOException {
    this(new InetSocketAddress(host, port));
  }

  public SimpleUdpTransport(final String host) throws IOException {
    this(host, DEFAULT_PORT);
  }

  public SimpleUdpTransport(final int port) throws IOException {
    this(InetAddress.getLocalHost().getHostAddress(), port);
  }

  @Override
  public com.aphyr.riemann.Proto.Msg sendMaybeRecvMessage(final com.aphyr.riemann.Proto.Msg msg) throws IOException {
    final byte[] body = msg.toByteArray();
    final DatagramPacket packet = new DatagramPacket(body, body.length, address);
    socket.send(packet);
    return null;
  }

  @Override
  public com.aphyr.riemann.Proto.Msg sendRecvMessage(final com.aphyr.riemann.Proto.Msg msg) throws IOException {
    throw new UnsupportedOperationException("UDP transport doesn't support receiving messages");
  }

  @Override
  public boolean isConnected() {
    return false;  //To change body of implemented methods use File | Settings | File Templates.
  }

  @Override
  public synchronized void connect() throws IOException {
    socket = new DatagramSocket();
    connected = true;
  }

  @Override
  public synchronized void disconnect() throws IOException {
    try {
      socket.close();
    } finally {
      socket = null;
      connected = false;
    }
  }

  @Override
  public void reconnect() throws IOException {
    disconnect();
    connect();
  }

  @Override
  public void flush() throws IOException {
    // Noop
  }
}

@@ -110,35 +110,49 @@
 com.
-google.protobuf.MessageLite
+aphyr.riemann.client.SynchronousTransport
 ;%0A%0Ai
@@ -309,130 +309,8 @@
 ess;
-%0Aimport com.aphyr.riemann.client.SynchronousTransport;%0A%0Aimport static org.jboss.netty.buffer.ChannelBuffers.wrappedBuffer;
 %0A%0Apu
@@ -422,16 +422,16 @@
  5555;%0A%0A
+
   privat
@@ -467,54 +467,8 @@
 ket;
-%0A  private volatile boolean connected = false;
 %0A%0A  
@@ -1568,88 +1568,9 @@
 lse;
-  //To change body of implemented methods use File %7C Settings %7C File Templates.
 %0A
+
   %7D%0A
@@ -1679,30 +1679,8 @@
 ();%0A
-    connected = true;%0A
   %7D%0A
@@ -1826,33 +1826,8 @@
 ll;%0A
-      connected = false;%0A
     
@@ -1934,32 +1934,32 @@
  %7D%0A%0A  @Override%0A
+
   public void fl
@@ -1988,23 +1988,8 @@
 on %7B
-%0A    // Noop%0A  
 %7D%0A%7D%0A

Tidy up several warnings in SimpleUdpTransport