Formatting

This commit is contained in:
nathan 2017-07-30 19:46:11 +02:00
parent 3461d511f9
commit 2154eeb5a8
2 changed files with 84 additions and 103 deletions

View File

@ -7,7 +7,10 @@
*/ */
package com.barchart.udt; package com.barchart.udt;
import static com.barchart.udt.OptionUDT.Format.*; import static com.barchart.udt.OptionUDT.Format.BINARY;
import static com.barchart.udt.OptionUDT.Format.BOOLEAN;
import static com.barchart.udt.OptionUDT.Format.DECIMAL;
import static com.barchart.udt.OptionUDT.Format.DEFAULT;
import java.util.List; import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
@ -57,76 +60,76 @@ public class OptionUDT<T> {
} }
/** the Maximum Transfer Unit. */ /** the Maximum Transfer Unit. */
public static final OptionUDT<Integer> UDT_MSS = // public static final OptionUDT<Integer> UDT_MSS = NEW(0, Integer.class, DECIMAL);
NEW(0, Integer.class, DECIMAL);
/** the Maximum Transfer Unit., bytes */ /** the Maximum Transfer Unit., bytes */
public static final OptionUDT<Integer> Maximum_Transfer_Unit = // public static final OptionUDT<Integer> Maximum_Transfer_Unit = NEW(0, Integer.class, DECIMAL);
NEW(0, Integer.class, DECIMAL);
/** if sending is blocking. */ /** if sending is blocking. */
public static final OptionUDT<Boolean> UDT_SNDSYN = // public static final OptionUDT<Boolean> UDT_SNDSYN = NEW(1, Boolean.class, BOOLEAN);
NEW(1, Boolean.class, BOOLEAN);
/** if sending is blocking., true/false */ /** if sending is blocking., true/false */
public static final OptionUDT<Boolean> Is_Send_Synchronous = // public static final OptionUDT<Boolean> Is_Send_Synchronous = NEW(1, Boolean.class, BOOLEAN);
NEW(1, Boolean.class, BOOLEAN);
/** if receiving is blocking. */ /** if receiving is blocking. */
public static final OptionUDT<Boolean> UDT_RCVSYN = // public static final OptionUDT<Boolean> UDT_RCVSYN = NEW(2, Boolean.class, BOOLEAN);
NEW(2, Boolean.class, BOOLEAN);
/** if receiving is blocking, true/false */ /** if receiving is blocking, true/false */
public static final OptionUDT<Boolean> Is_Receive_Synchronous = // public static final OptionUDT<Boolean> Is_Receive_Synchronous = NEW(2, Boolean.class, BOOLEAN);
NEW(2, Boolean.class, BOOLEAN);
/** custom congestion control algorithm */ /** custom congestion control algorithm */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static final OptionUDT<FactoryUDT> UDT_CC = //
NEW(3, FactoryUDT.class, DEFAULT); public static final OptionUDT<FactoryUDT> UDT_CC = NEW(3, FactoryUDT.class, DEFAULT);
/** custom congestion control algorithm, class factory */ /** custom congestion control algorithm, class factory */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static final OptionUDT<FactoryUDT> Custom_Congestion_Control = // public static final OptionUDT<FactoryUDT> Custom_Congestion_Control = NEW(3, FactoryUDT.class, DEFAULT);
NEW(3, FactoryUDT.class, DEFAULT);
/** Flight flag size (window size). */ /** Flight flag size (window size). */
public static final OptionUDT<Integer> UDT_FC = // public static final OptionUDT<Integer> UDT_FC = NEW(4, Integer.class, BINARY);
NEW(4, Integer.class, BINARY);
/** Flight flag size (window size), bytes */ /** Flight flag size (window size), bytes */
public static final OptionUDT<Integer> Flight_Window_Size = // public static final OptionUDT<Integer> Flight_Window_Size = NEW(4, Integer.class, BINARY);
NEW(4, Integer.class, BINARY);
/** maximum buffer in sending queue. */ /** maximum buffer in sending queue. */
public static final OptionUDT<Integer> UDT_SNDBUF = // public static final OptionUDT<Integer> UDT_SNDBUF = NEW(5, Integer.class, DECIMAL);
NEW(5, Integer.class, DECIMAL);
/** maximum buffer in sending queue. */ /** maximum buffer in sending queue. */
public static final OptionUDT<Integer> Protocol_Send_Buffer_Size = // public static final OptionUDT<Integer> Protocol_Send_Buffer_Size = NEW(5, Integer.class, DECIMAL);
NEW(5, Integer.class, DECIMAL);
/** UDT receiving buffer size. */ /** UDT receiving buffer size. */
public static final OptionUDT<Integer> UDT_RCVBUF = // public static final OptionUDT<Integer> UDT_RCVBUF = NEW(6, Integer.class, DECIMAL);
NEW(6, Integer.class, DECIMAL);
/** UDT receiving buffer size limit, bytes */ /** UDT receiving buffer size limit, bytes */
public static final OptionUDT<Integer> Protocol_Receive_Buffer_Size = // public static final OptionUDT<Integer> Protocol_Receive_Buffer_Size = NEW(6, Integer.class, DECIMAL);
NEW(6, Integer.class, DECIMAL);
/** waiting for unsent data when closing. */ /** waiting for unsent data when closing. */
public static final OptionUDT<LingerUDT> UDT_LINGER = // public static final OptionUDT<LingerUDT> UDT_LINGER = NEW(7, LingerUDT.class, DECIMAL);
NEW(7, LingerUDT.class, DECIMAL);
/** waiting for unsent data when closing. true/false and timeout, seconds */ /** waiting for unsent data when closing. true/false and timeout, seconds */
public static final OptionUDT<LingerUDT> Time_To_Linger_On_Close = // public static final OptionUDT<LingerUDT> Time_To_Linger_On_Close = NEW(7, LingerUDT.class, DECIMAL);
NEW(7, LingerUDT.class, DECIMAL);
/** UDP sending buffer size. */ /** UDP sending buffer size. */
public static final OptionUDT<Integer> UDP_SNDBUF = // public static final OptionUDT<Integer> UDP_SNDBUF = NEW(8, Integer.class, DECIMAL);
NEW(8, Integer.class, DECIMAL);
/** UDP sending buffer size limit, bytes */ /** UDP sending buffer size limit, bytes */
public static final OptionUDT<Integer> System_Send_Buffer_Size = // public static final OptionUDT<Integer> System_Send_Buffer_Size = NEW(8, Integer.class, DECIMAL);
NEW(8, Integer.class, DECIMAL);
/** UDP receiving buffer size. */ /** UDP receiving buffer size. */
public static final OptionUDT<Integer> UDP_RCVBUF = // public static final OptionUDT<Integer> UDP_RCVBUF = NEW(9, Integer.class, DECIMAL);
NEW(9, Integer.class, DECIMAL);
/** UDP receiving buffer size limit, bytes */ /** UDP receiving buffer size limit, bytes */
public static final OptionUDT<Integer> System_Receive_Buffer_Size = // public static final OptionUDT<Integer> System_Receive_Buffer_Size = NEW(9, Integer.class, DECIMAL);
NEW(9, Integer.class, DECIMAL);
/* maximum datagram message size */ /* maximum datagram message size */
// UDT_MAXMSG(10, Integer.class, DECIMAL); no support in udt core // UDT_MAXMSG(10, Integer.class, DECIMAL); no support in udt core
@ -135,90 +138,81 @@ public class OptionUDT<T> {
// UDT_MSGTTL(11, Integer.class, DECIMAL); no support in udt core // UDT_MSGTTL(11, Integer.class, DECIMAL); no support in udt core
/** rendezvous connection mode. */ /** rendezvous connection mode. */
public static final OptionUDT<Boolean> UDT_RENDEZVOUS = // public static final OptionUDT<Boolean> UDT_RENDEZVOUS = NEW(12, Boolean.class, BOOLEAN);
NEW(12, Boolean.class, BOOLEAN);
/** rendezvous connection mode, enabled/disabled */ /** rendezvous connection mode, enabled/disabled */
public static final OptionUDT<Boolean> Is_Randezvous_Connect_Enabled = // public static final OptionUDT<Boolean> Is_Randezvous_Connect_Enabled = NEW(12, Boolean.class, BOOLEAN);
NEW(12, Boolean.class, BOOLEAN);
/** send() timeout. */ /** send() timeout. */
public static final OptionUDT<Integer> UDT_SNDTIMEO = // public static final OptionUDT<Integer> UDT_SNDTIMEO = NEW(13, Integer.class, DECIMAL);
NEW(13, Integer.class, DECIMAL);
/** send() timeout. milliseconds */ /** send() timeout. milliseconds */
public static final OptionUDT<Integer> Send_Timeout = // public static final OptionUDT<Integer> Send_Timeout = NEW(13, Integer.class, DECIMAL);
NEW(13, Integer.class, DECIMAL);
/** recv() timeout. */ /** recv() timeout. */
public static final OptionUDT<Integer> UDT_RCVTIMEO = // public static final OptionUDT<Integer> UDT_RCVTIMEO = NEW(14, Integer.class, DECIMAL);
NEW(14, Integer.class, DECIMAL);
/** recv() timeout. milliseconds */ /** recv() timeout. milliseconds */
public static final OptionUDT<Integer> Receive_Timeout = // public static final OptionUDT<Integer> Receive_Timeout = NEW(14, Integer.class, DECIMAL);
NEW(14, Integer.class, DECIMAL);
/** reuse an existing port or create a one. */ /** reuse an existing port or create a one. */
public static final OptionUDT<Boolean> UDT_REUSEADDR = // public static final OptionUDT<Boolean> UDT_REUSEADDR = NEW(15, Boolean.class, BOOLEAN);
NEW(15, Boolean.class, BOOLEAN);
/** reuse an existing port or create a one. true/false */ /** reuse an existing port or create a one. true/false */
public static final OptionUDT<Boolean> Is_Address_Reuse_Enabled = // public static final OptionUDT<Boolean> Is_Address_Reuse_Enabled = NEW(15, Boolean.class, BOOLEAN);
NEW(15, Boolean.class, BOOLEAN);
/** maximum bandwidth (bytes per second) that the connection can use. */ /** maximum bandwidth (bytes per second) that the connection can use. */
public static final OptionUDT<Long> UDT_MAXBW = // public static final OptionUDT<Long> UDT_MAXBW = NEW(16, Long.class, DECIMAL);
NEW(16, Long.class, DECIMAL);
/** maximum bandwidth (bytes per second) that the connection can use. */ /** maximum bandwidth (bytes per second) that the connection can use. */
public static final OptionUDT<Long> Maximum_Bandwidth = // public static final OptionUDT<Long> Maximum_Bandwidth = NEW(16, Long.class, DECIMAL);
NEW(16, Long.class, DECIMAL);
/** current socket state, see UDTSTATUS, read only */ /** current socket state, see UDTSTATUS, read only */
public static final OptionUDT<Integer> UDT_STATE = // public static final OptionUDT<Integer> UDT_STATE = NEW(17, Integer.class, DECIMAL);
NEW(17, Integer.class, DECIMAL);
/** current socket status code, see {@link StatusUDT#getCode()}, read only */ /** current socket status code, see {@link StatusUDT#getCode()}, read only */
public static final OptionUDT<Integer> Status_Code = // public static final OptionUDT<Integer> Status_Code = NEW(17, Integer.class, DECIMAL);
NEW(17, Integer.class, DECIMAL);
/** current available events associated with the socket */ /** current available events associated with the socket */
public static final OptionUDT<Integer> UDT_EVENT = // public static final OptionUDT<Integer> UDT_EVENT = NEW(18, Integer.class, DECIMAL);
NEW(18, Integer.class, DECIMAL);
/** current available epoll events, see {@link EpollUDT.Opt#code} */ /** current available epoll events, see {@link EpollUDT.Opt#code} */
public static final OptionUDT<Integer> Epoll_Event_Mask = // public static final OptionUDT<Integer> Epoll_Event_Mask = NEW(18, Integer.class, DECIMAL);
NEW(18, Integer.class, DECIMAL);
/** size of data in the sending buffer */ /** size of data in the sending buffer */
public static final OptionUDT<Integer> UDT_SNDDATA = // public static final OptionUDT<Integer> UDT_SNDDATA = NEW(19, Integer.class, DECIMAL);
NEW(19, Integer.class, DECIMAL);
/** current consumed sending buffer utilization, read only, bytes */ /** current consumed sending buffer utilization, read only, bytes */
public static final OptionUDT<Integer> Send_Buffer_Consumed = // public static final OptionUDT<Integer> Send_Buffer_Consumed = NEW(19, Integer.class, DECIMAL);
NEW(19, Integer.class, DECIMAL);
/** size of data available for recv */ /** size of data available for recv */
public static final OptionUDT<Integer> UDT_RCVDATA = // public static final OptionUDT<Integer> UDT_RCVDATA = NEW(20, Integer.class, DECIMAL);
NEW(20, Integer.class, DECIMAL);
/** current available receiving buffer capacity, read only, bytes */ /** current available receiving buffer capacity, read only, bytes */
public static final OptionUDT<Integer> Receive_Buffer_Available = // public static final OptionUDT<Integer> Receive_Buffer_Available = NEW(20, Integer.class, DECIMAL);
NEW(20, Integer.class, DECIMAL);
//
protected OptionUDT(final int code, final Class<T> klaz, final Format format) { protected OptionUDT(final int code, final Class<T> klaz, final Format format) {
this.code = code; this.code = code;
this.type = klaz; this.type = klaz;
this.format = format; this.format = format;
values.add(this); values.add(this);
} }
protected static <T> OptionUDT<T> NEW(final int code, final Class<T> klaz, protected static <T> OptionUDT<T> NEW(final int code, final Class<T> klaz, final Format format) {
final Format format) {
return new OptionUDT<T>(code, klaz, format); return new OptionUDT<T>(code, klaz, format);
} }
public static void appendSnapshot( // public static void appendSnapshot(final SocketUDT socketUDT, final StringBuilder text) {
final SocketUDT socketUDT, //
final StringBuilder text //
) {
text.append("\n\t"); text.append("\n\t");
text.append(String.format("[id: 0x%08x]", socketUDT.id())); text.append(String.format("[id: 0x%08x]", socketUDT.id()));
@ -248,9 +242,7 @@ public class OptionUDT<T> {
} catch (final Exception e) { } catch (final Exception e) {
log.error("unexpected; " + optionName, e); log.error("unexpected; " + optionName, e);
} }
} }
} }
protected static final Logger log; protected static final Logger log;
@ -284,7 +276,6 @@ public class OptionUDT<T> {
* render options in human format * render options in human format
*/ */
public enum Format { public enum Format {
DECIMAL() { DECIMAL() {
@Override @Override
public String convert(final Object value) { public String convert(final Object value) {
@ -328,7 +319,5 @@ public class OptionUDT<T> {
; ;
public abstract String convert(Object value); public abstract String convert(Object value);
} }
} }

View File

@ -1619,17 +1619,13 @@ class SocketUDT {
* @see #setOption0(int, Class, Object) * @see #setOption0(int, Class, Object)
*/ */
public public
<T> void setOption( // <T> void setOption(final OptionUDT<T> option, final T value) throws ExceptionUDT {
final OptionUDT<T> option, //
final T value //
) throws ExceptionUDT {
if (option == null || value == null) { if (option == null || value == null) {
throw new IllegalArgumentException("option == null || value == null"); throw new IllegalArgumentException("option == null || value == null");
} }
setOption0(option.code(), option.type(), value); setOption0(option.code(), option.type(), value);
} }
/** /**
@ -1637,11 +1633,7 @@ class SocketUDT {
* href="http://udt.sourceforge.net/udt4/doc/opt.htm">UDT::setsockopt()</a> * href="http://udt.sourceforge.net/udt4/doc/opt.htm">UDT::setsockopt()</a>
*/ */
protected native protected native
void setOption0( // void setOption0(final int code, final Class<?> klaz, final Object value) throws ExceptionUDT;
final int code, //
final Class<?> klaz, //
final Object value //
) throws ExceptionUDT;
/** /**
* Set maximum receive buffer size. Affects both protocol-level (UDT) and * Set maximum receive buffer size. Affects both protocol-level (UDT) and