Formatting
This commit is contained in:
parent
6080c4fd4d
commit
a4e7447e48
@ -26,14 +26,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) {
|
||||||
|
@ -7,14 +7,15 @@
|
|||||||
*/
|
*/
|
||||||
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.nio.channels.ServerSocketChannel;
|
||||||
import com.barchart.udt.anno.ThreadSafe;
|
|
||||||
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,28 +40,21 @@ 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
|
||||||
public SocketChannelUDT accept() throws IOException {
|
public SocketChannelUDT accept() throws IOException {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
begin();
|
begin();
|
||||||
|
|
||||||
final SocketUDT clientUDT = socketUDT.accept();
|
final SocketUDT clientUDT = socketUDT.accept();
|
||||||
@ -89,8 +83,7 @@ public class ServerSocketChannelUDT extends ServerSocketChannel implements Chann
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void implConfigureBlocking(final boolean block)
|
protected void implConfigureBlocking(final boolean block) throws IOException {
|
||||||
throws IOException {
|
|
||||||
socketUDT.setBlocking(block);
|
socketUDT.setBlocking(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,13 +7,6 @@
|
|||||||
*/
|
*/
|
||||||
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;
|
||||||
@ -24,6 +17,14 @@ 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 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
|
||||||
* stream or message oriented, depending on {@link TypeUDT}
|
* stream or message oriented, depending on {@link TypeUDT}
|
||||||
@ -54,8 +55,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 +76,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) {
|
||||||
@ -106,7 +97,6 @@ public class SocketChannelUDT extends SocketChannel implements ChannelUDT {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean connect(final SocketAddress remote) throws IOException {
|
public boolean connect(final SocketAddress remote) throws IOException {
|
||||||
|
|
||||||
if (!isOpen()) {
|
if (!isOpen()) {
|
||||||
throw new ClosedChannelException();
|
throw new ClosedChannelException();
|
||||||
}
|
}
|
||||||
@ -205,7 +195,6 @@ public class SocketChannelUDT extends SocketChannel implements ChannelUDT {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean finishConnect() throws IOException {
|
public boolean finishConnect() throws IOException {
|
||||||
|
|
||||||
if (!isOpen()) {
|
if (!isOpen()) {
|
||||||
throw new ClosedChannelException();
|
throw new ClosedChannelException();
|
||||||
}
|
}
|
||||||
@ -237,7 +226,6 @@ public class SocketChannelUDT extends SocketChannel implements ChannelUDT {
|
|||||||
throw new IOException();
|
throw new IOException();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -277,7 +265,6 @@ public class SocketChannelUDT extends SocketChannel implements ChannelUDT {
|
|||||||
return (SelectorProviderUDT) super.provider();
|
return (SelectorProviderUDT) super.provider();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See {@link SocketChannel#read(ByteBuffer)} contract;
|
* See {@link SocketChannel#read(ByteBuffer)} contract;
|
||||||
@ -353,7 +340,6 @@ public class SocketChannelUDT extends SocketChannel implements ChannelUDT {
|
|||||||
log.error("should not happen: socket={}", socket);
|
log.error("should not happen: socket={}", socket);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -473,15 +459,12 @@ public class SocketChannelUDT extends SocketChannel implements ChannelUDT {
|
|||||||
log.error("should not happen; socket={}", socket);
|
log.error("should not happen; socket={}", socket);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@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,7 +488,6 @@ 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
|
@Override
|
||||||
@ -514,8 +496,7 @@ public class SocketChannelUDT extends SocketChannel implements ChannelUDT {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** java 7 */
|
/** java 7 */
|
||||||
public SocketChannelUDT bind(final SocketAddress localAddress)
|
public SocketChannelUDT bind(final SocketAddress localAddress) throws IOException {
|
||||||
throws IOException {
|
|
||||||
|
|
||||||
socketUDT.bind((InetSocketAddress) localAddress);
|
socketUDT.bind((InetSocketAddress) localAddress);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user