Updated UDT to be compilable on Java7.

This commit is contained in:
nathan 2017-07-30 19:50:28 +02:00
parent 2154eeb5a8
commit d39f3ea289
3 changed files with 154 additions and 56 deletions

View File

@ -7,14 +7,15 @@
*/ */
package com.barchart.udt.nio; package com.barchart.udt.nio;
import com.barchart.udt.SocketUDT;
import com.barchart.udt.TypeUDT;
import java.io.IOException; import java.io.IOException;
import java.net.ProtocolFamily;
import java.nio.channels.DatagramChannel; import java.nio.channels.DatagramChannel;
import java.nio.channels.Pipe; import java.nio.channels.Pipe;
import java.nio.channels.spi.SelectorProvider; import java.nio.channels.spi.SelectorProvider;
import com.barchart.udt.SocketUDT;
import com.barchart.udt.TypeUDT;
/** /**
* selection provider for UDT * selection provider for UDT
* <p> * <p>
@ -26,14 +27,12 @@ public class SelectorProviderUDT extends SelectorProvider {
/** /**
* system-wide provider instance, for {@link TypeUDT#DATAGRAM} UDT sockets * system-wide provider instance, for {@link TypeUDT#DATAGRAM} UDT sockets
*/ */
public static final SelectorProviderUDT DATAGRAM = // public static final SelectorProviderUDT DATAGRAM = new SelectorProviderUDT(TypeUDT.DATAGRAM);
new SelectorProviderUDT(TypeUDT.DATAGRAM);
/** /**
* system-wide provider instance, for {@link TypeUDT#STREAM} UDT sockets * system-wide provider instance, for {@link TypeUDT#STREAM} UDT sockets
*/ */
public static final SelectorProviderUDT STREAM = // public static final SelectorProviderUDT STREAM = new SelectorProviderUDT(TypeUDT.STREAM);
new SelectorProviderUDT(TypeUDT.STREAM);
public static SelectorProviderUDT from(final TypeUDT type) { public static SelectorProviderUDT from(final TypeUDT type) {
switch (type) { switch (type) {
@ -79,6 +78,15 @@ public class SelectorProviderUDT extends SelectorProvider {
throw new UnsupportedOperationException("feature not available"); throw new UnsupportedOperationException("feature not available");
} }
/**
* java 7
*/
@Override
public
DatagramChannel openDatagramChannel(final ProtocolFamily family) throws IOException {
throw new UnsupportedOperationException("feature not available");
}
/** /**
* Not supported. * Not supported.
*/ */

View File

@ -7,14 +7,18 @@
*/ */
package com.barchart.udt.nio; package com.barchart.udt.nio;
import com.barchart.udt.SocketUDT; import java.io.IOException;
import com.barchart.udt.TypeUDT; import java.net.SocketAddress;
import com.barchart.udt.anno.ThreadSafe; import java.net.SocketOption;
import java.nio.channels.ServerSocketChannel;
import java.util.Set;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import com.barchart.udt.SocketUDT;
import java.nio.channels.ServerSocketChannel; import com.barchart.udt.TypeUDT;
import com.barchart.udt.anno.ThreadSafe;
/** /**
* {@link ServerSocketChannel}-like wrapper for {@link SocketUDT} can be either * {@link ServerSocketChannel}-like wrapper for {@link SocketUDT} can be either
@ -39,22 +43,16 @@ import java.nio.channels.ServerSocketChannel;
*/ */
public class ServerSocketChannelUDT extends ServerSocketChannel implements ChannelUDT { public class ServerSocketChannelUDT extends ServerSocketChannel implements ChannelUDT {
protected static final Logger log = LoggerFactory protected static final Logger log = LoggerFactory.getLogger(ServerSocketChannelUDT.class);
.getLogger(ServerSocketChannelUDT.class);
@ThreadSafe("this") @ThreadSafe("this")
protected NioServerSocketUDT socketAdapter; protected NioServerSocketUDT socketAdapter;
protected final SocketUDT socketUDT; protected final SocketUDT socketUDT;
protected ServerSocketChannelUDT( // protected ServerSocketChannelUDT(final SelectorProviderUDT provider, final SocketUDT socketUDT) {
final SelectorProviderUDT provider, //
final SocketUDT socketUDT //
) {
super(provider); super(provider);
this.socketUDT = socketUDT; this.socketUDT = socketUDT;
} }
@Override @Override
@ -83,14 +81,22 @@ public class ServerSocketChannelUDT extends ServerSocketChannel implements Chann
} }
} }
@Override /**
* java 7
*/
@Override
public
SocketAddress getLocalAddress() throws IOException {
throw new UnsupportedOperationException("feature not available");
}
@Override
protected void implCloseSelectableChannel() throws IOException { protected void implCloseSelectableChannel() throws IOException {
socketUDT.close(); socketUDT.close();
} }
@Override @Override
protected void implConfigureBlocking(final boolean block) protected void implConfigureBlocking(final boolean block) throws IOException {
throws IOException {
socketUDT.setBlocking(block); socketUDT.setBlocking(block);
} }
@ -109,6 +115,42 @@ public class ServerSocketChannelUDT extends ServerSocketChannel implements Chann
return (SelectorProviderUDT) super.provider(); return (SelectorProviderUDT) super.provider();
} }
/**
* java 7
*/
@Override
public
ServerSocketChannel bind(final SocketAddress local, final int backlog) throws IOException {
throw new UnsupportedOperationException("feature not available");
}
/**
* java 7
*/
@Override
public
<T> ServerSocketChannel setOption(final SocketOption<T> name, final T value) throws IOException {
throw new UnsupportedOperationException("feature not available");
}
/**
* java 7
*/
@Override
public
<T> T getOption(final SocketOption<T> name) throws IOException {
throw new UnsupportedOperationException("feature not available");
}
/**
* java 7
*/
@Override
public
Set<SocketOption<?>> supportedOptions() {
throw new UnsupportedOperationException("feature not available");
}
@Override @Override
public synchronized NioServerSocketUDT socket() { public synchronized NioServerSocketUDT socket() {
if (socketAdapter == null) { if (socketAdapter == null) {

View File

@ -7,22 +7,25 @@
*/ */
package com.barchart.udt.nio; package com.barchart.udt.nio;
import com.barchart.udt.ExceptionUDT;
import com.barchart.udt.SocketUDT;
import com.barchart.udt.TypeUDT;
import com.barchart.udt.anno.ThreadSafe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.net.SocketOption;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException; import java.nio.channels.ClosedChannelException;
import java.nio.channels.ConnectionPendingException; import java.nio.channels.ConnectionPendingException;
import java.nio.channels.IllegalBlockingModeException; import java.nio.channels.IllegalBlockingModeException;
import java.nio.channels.SocketChannel; import java.nio.channels.SocketChannel;
import java.nio.channels.UnresolvedAddressException; import java.nio.channels.UnresolvedAddressException;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.barchart.udt.ExceptionUDT;
import com.barchart.udt.SocketUDT;
import com.barchart.udt.TypeUDT;
import com.barchart.udt.anno.ThreadSafe;
/** /**
* {@link SocketChannel}-like wrapper for {@link SocketUDT}, can be either * {@link SocketChannel}-like wrapper for {@link SocketUDT}, can be either
@ -54,8 +57,7 @@ import java.nio.channels.UnresolvedAddressException;
*/ */
public class SocketChannelUDT extends SocketChannel implements ChannelUDT { public class SocketChannelUDT extends SocketChannel implements ChannelUDT {
protected static final Logger log = LoggerFactory protected static final Logger log = LoggerFactory.getLogger(SocketChannelUDT.class);
.getLogger(SocketChannelUDT.class);
protected final Object connectLock = new Object(); protected final Object connectLock = new Object();
@ -76,22 +78,13 @@ public class SocketChannelUDT extends SocketChannel implements ChannelUDT {
private InetSocketAddress remoteSocket; private InetSocketAddress remoteSocket;
protected SocketChannelUDT( // protected SocketChannelUDT(final SelectorProviderUDT provider, final SocketUDT socketUDT) throws ExceptionUDT {
final SelectorProviderUDT provider, //
final SocketUDT socketUDT //
) throws ExceptionUDT {
super(provider); super(provider);
this.socketUDT = socketUDT; this.socketUDT = socketUDT;
this.socketUDT.setBlocking(true); this.socketUDT.setBlocking(true);
} }
protected SocketChannelUDT( // protected SocketChannelUDT(final SelectorProviderUDT provider, final SocketUDT socketUDT, final boolean isConnected) throws ExceptionUDT {
final SelectorProviderUDT provider, //
final SocketUDT socketUDT, //
final boolean isConnected //
) throws ExceptionUDT {
this(provider, socketUDT); this(provider, socketUDT);
if (isConnected) { if (isConnected) {
@ -101,7 +94,6 @@ public class SocketChannelUDT extends SocketChannel implements ChannelUDT {
isConnectFinished = false; isConnectFinished = false;
isConnectionPending = true; isConnectionPending = true;
} }
} }
@Override @Override
@ -240,6 +232,15 @@ public class SocketChannelUDT extends SocketChannel implements ChannelUDT {
} }
/**
* java 7
*/
@Override
public
SocketAddress getRemoteAddress() throws IOException {
throw new UnsupportedOperationException("feature not available");
}
@Override @Override
protected void implCloseSelectableChannel() throws IOException { protected void implCloseSelectableChannel() throws IOException {
socketUDT.close(); socketUDT.close();
@ -357,8 +358,7 @@ public class SocketChannelUDT extends SocketChannel implements ChannelUDT {
} }
@Override @Override
public long read(final ByteBuffer[] dsts, final int offset, final int length) public long read(final ByteBuffer[] dsts, final int offset, final int length) throws IOException {
throws IOException {
throw new RuntimeException("feature not available"); throw new RuntimeException("feature not available");
} }
@ -477,11 +477,9 @@ public class SocketChannelUDT extends SocketChannel implements ChannelUDT {
} }
@Override @Override
public long write(final ByteBuffer[] bufferArray, final int offset, public long write(final ByteBuffer[] bufferArray, final int offset, final int length) throws IOException {
final int length) throws IOException {
try { try {
long total = 0; long total = 0;
for (int index = offset; index < offset + length; index++) { for (int index = offset; index < offset + length; index++) {
@ -505,21 +503,71 @@ public class SocketChannelUDT extends SocketChannel implements ChannelUDT {
} catch (final Throwable e) { } catch (final Throwable e) {
throw new IOException("failed to write buffer array", e); throw new IOException("failed to write buffer array", e);
} }
} }
@Override /**
* java 7
*/
@Override
public
SocketAddress getLocalAddress() throws IOException {
throw new UnsupportedOperationException("feature not available");
}
@Override
public TypeUDT typeUDT() { public TypeUDT typeUDT() {
return providerUDT().type(); return providerUDT().type();
} }
/** java 7 */ /** java 7 */
public SocketChannelUDT bind(final SocketAddress localAddress) @Override
throws IOException { public SocketChannelUDT bind(final SocketAddress localAddress) throws IOException {
socketUDT.bind((InetSocketAddress) localAddress); socketUDT.bind((InetSocketAddress) localAddress);
return this; return this;
} }
/**
* java 7
*/
@Override
public
<T> SocketChannel setOption(final SocketOption<T> option, final T value) throws IOException {
throw new UnsupportedOperationException("feature not available");
}
/**
* java 7
*/
@Override
public
<T> T getOption(final SocketOption<T> name) throws IOException {
throw new UnsupportedOperationException("feature not available");
}
/**
* java 7
*/
@Override
public
Set<SocketOption<?>> supportedOptions() {
throw new UnsupportedOperationException("feature not available");
}
/**
* java 7
*/
@Override
public
SocketChannel shutdownInput() throws IOException {
throw new UnsupportedOperationException("feature not available");
}
/**
* java 7
*/
@Override
public
SocketChannel shutdownOutput() throws IOException {
throw new UnsupportedOperationException("feature not available");
}
} }