Skip to content

Instantly share code, notes, and snippets.

@Sammers21
Created October 5, 2018 08:53
Show Gist options
  • Save Sammers21/a6635213276e9ea064a5a4f20dd53c11 to your computer and use it in GitHub Desktop.
Save Sammers21/a6635213276e9ea064a5a4f20dd53c11 to your computer and use it in GitHub Desktop.
SynchronizedSocket example
class SynchronizedSocket extends Socket {
private final Socket wrappedSocket;
public SynchronizedSocket(Socket wrappedSocket) {
this.wrappedSocket = wrappedSocket;
}
@Override
public synchronized void connect(SocketAddress endpoint) throws IOException {
wrappedSocket.connect(endpoint);
}
@Override
public synchronized void connect(SocketAddress endpoint, int timeout) throws IOException {
wrappedSocket.connect(endpoint, timeout);
}
@Override
public synchronized void bind(SocketAddress bindpoint) throws IOException {
wrappedSocket.bind(bindpoint);
}
@Override
public synchronized InetAddress getInetAddress() {
return wrappedSocket.getInetAddress();
}
@Override
public synchronized InetAddress getLocalAddress() {
return wrappedSocket.getLocalAddress();
}
@Override
public synchronized int getPort() {
return wrappedSocket.getPort();
}
@Override
public synchronized int getLocalPort() {
return wrappedSocket.getLocalPort();
}
@Override
public synchronized SocketAddress getRemoteSocketAddress() {
return wrappedSocket.getRemoteSocketAddress();
}
@Override
public synchronized SocketAddress getLocalSocketAddress() {
return wrappedSocket.getLocalSocketAddress();
}
@Override
public synchronized SocketChannel getChannel() {
return wrappedSocket.getChannel();
}
@Override
public synchronized InputStream getInputStream() throws IOException {
return wrappedSocket.getInputStream();
}
@Override
public synchronized OutputStream getOutputStream() throws IOException {
return wrappedSocket.getOutputStream();
}
@Override
public synchronized void setTcpNoDelay(boolean on) throws SocketException {
wrappedSocket.setTcpNoDelay(on);
}
@Override
public synchronized boolean getTcpNoDelay() throws SocketException {
return wrappedSocket.getTcpNoDelay();
}
@Override
public synchronized void setSoLinger(boolean on, int linger) throws SocketException {
wrappedSocket.setSoLinger(on, linger);
}
@Override
public synchronized int getSoLinger() throws SocketException {
return wrappedSocket.getSoLinger();
}
@Override
public synchronized void sendUrgentData(int data) throws IOException {
wrappedSocket.sendUrgentData(data);
}
@Override
public synchronized void setOOBInline(boolean on) throws SocketException {
wrappedSocket.setOOBInline(on);
}
@Override
public synchronized boolean getOOBInline() throws SocketException {
return wrappedSocket.getOOBInline();
}
@Override
public synchronized synchronized void setSoTimeout(int timeout) throws SocketException {
wrappedSocket.setSoTimeout(timeout);
}
@Override
public synchronized synchronized int getSoTimeout() throws SocketException {
return wrappedSocket.getSoTimeout();
}
@Override
public synchronized synchronized void setSendBufferSize(int size) throws SocketException {
wrappedSocket.setSendBufferSize(size);
}
@Override
public synchronized synchronized int getSendBufferSize() throws SocketException {
return wrappedSocket.getSendBufferSize();
}
@Override
public synchronized synchronized void setReceiveBufferSize(int size) throws SocketException {
wrappedSocket.setReceiveBufferSize(size);
}
@Override
public synchronized synchronized int getReceiveBufferSize() throws SocketException {
return wrappedSocket.getReceiveBufferSize();
}
@Override
public synchronized void setKeepAlive(boolean on) throws SocketException {
wrappedSocket.setKeepAlive(on);
}
@Override
public synchronized boolean getKeepAlive() throws SocketException {
return wrappedSocket.getKeepAlive();
}
@Override
public synchronized void setTrafficClass(int tc) throws SocketException {
wrappedSocket.setTrafficClass(tc);
}
@Override
public synchronized int getTrafficClass() throws SocketException {
return wrappedSocket.getTrafficClass();
}
@Override
public synchronized void setReuseAddress(boolean on) throws SocketException {
wrappedSocket.setReuseAddress(on);
}
@Override
public synchronized boolean getReuseAddress() throws SocketException {
return wrappedSocket.getReuseAddress();
}
@Override
public synchronized synchronized void close() throws IOException {
wrappedSocket.close();
}
@Override
public synchronized void shutdownInput() throws IOException {
wrappedSocket.shutdownInput();
}
@Override
public synchronized void shutdownOutput() throws IOException {
wrappedSocket.shutdownOutput();
}
@Override
public synchronized String toString() {
return wrappedSocket.toString();
}
@Override
public synchronized boolean isConnected() {
return wrappedSocket.isConnected();
}
@Override
public synchronized boolean isBound() {
return wrappedSocket.isBound();
}
@Override
public synchronized boolean isClosed() {
return wrappedSocket.isClosed();
}
@Override
public synchronized boolean isInputShutdown() {
return wrappedSocket.isInputShutdown();
}
@Override
public synchronized boolean isOutputShutdown() {
return wrappedSocket.isOutputShutdown();
}
@Override
public synchronized void setPerformancePreferences(int connectionTime, int latency, int bandwidth) {
wrappedSocket.setPerformancePreferences(connectionTime, latency, bandwidth);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment